@@ -29,12 +29,24 @@ class Registration extends \Magento\Framework\View\Element\Template
29
29
*/
30
30
protected $ accountManagement ;
31
31
32
+ /**
33
+ * @var \Magento\Sales\Api\OrderRepositoryInterface
34
+ */
35
+ protected $ orderRepository ;
36
+
37
+ /**
38
+ * @var \Magento\Sales\Model\Order\Address\Validator
39
+ */
40
+ protected $ addressValidator ;
41
+
32
42
/**
33
43
* @param Template\Context $context
34
44
* @param \Magento\Checkout\Model\Session $checkoutSession
35
45
* @param \Magento\Customer\Model\Session $customerSession
36
46
* @param \Magento\Customer\Model\Registration $registration
37
47
* @param \Magento\Customer\Api\AccountManagementInterface $accountManagement
48
+ * @param \Magento\Sales\Api\OrderRepositoryInterface $orderRepository
49
+ * @param \Magento\Sales\Model\Order\Address\Validator $addressValidator
38
50
* @param array $data
39
51
*/
40
52
public function __construct (
@@ -43,12 +55,16 @@ public function __construct(
43
55
\Magento \Customer \Model \Session $ customerSession ,
44
56
\Magento \Customer \Model \Registration $ registration ,
45
57
\Magento \Customer \Api \AccountManagementInterface $ accountManagement ,
58
+ \Magento \Sales \Api \OrderRepositoryInterface $ orderRepository ,
59
+ \Magento \Sales \Model \Order \Address \Validator $ addressValidator ,
46
60
array $ data = []
47
61
) {
48
62
$ this ->checkoutSession = $ checkoutSession ;
49
63
$ this ->customerSession = $ customerSession ;
50
64
$ this ->registration = $ registration ;
51
65
$ this ->accountManagement = $ accountManagement ;
66
+ $ this ->orderRepository = $ orderRepository ;
67
+ $ this ->addressValidator = $ addressValidator ;
52
68
parent ::__construct ($ context , $ data );
53
69
}
54
70
@@ -81,9 +97,28 @@ public function toHtml()
81
97
$ this ->customerSession ->isLoggedIn ()
82
98
|| !$ this ->registration ->isAllowed ()
83
99
|| !$ this ->accountManagement ->isEmailAvailable ($ this ->getEmailAddress ())
100
+ || !$ this ->validateAddresses ()
84
101
) {
85
102
return '' ;
86
103
}
87
104
return parent ::toHtml ();
88
105
}
106
+
107
+ /**
108
+ * Validate order addresses
109
+ *
110
+ * @return bool
111
+ */
112
+ protected function validateAddresses ()
113
+ {
114
+ $ order = $ this ->orderRepository ->get ($ this ->checkoutSession ->getLastOrderId ());
115
+ $ addresses = $ order ->getAddresses ();
116
+ foreach ($ addresses as $ address ) {
117
+ $ result = $ this ->addressValidator ->validateForCustomer ($ address );
118
+ if (is_array ($ result ) && !empty ($ result )) {
119
+ return false ;
120
+ }
121
+ }
122
+ return true ;
123
+ }
89
124
}
0 commit comments