@@ -29,12 +29,24 @@ class Registration extends \Magento\Framework\View\Element\Template
2929 */
3030 protected $ accountManagement ;
3131
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+
3242 /**
3343 * @param Template\Context $context
3444 * @param \Magento\Checkout\Model\Session $checkoutSession
3545 * @param \Magento\Customer\Model\Session $customerSession
3646 * @param \Magento\Customer\Model\Registration $registration
3747 * @param \Magento\Customer\Api\AccountManagementInterface $accountManagement
48+ * @param \Magento\Sales\Api\OrderRepositoryInterface $orderRepository
49+ * @param \Magento\Sales\Model\Order\Address\Validator $addressValidator
3850 * @param array $data
3951 */
4052 public function __construct (
@@ -43,12 +55,16 @@ public function __construct(
4355 \Magento \Customer \Model \Session $ customerSession ,
4456 \Magento \Customer \Model \Registration $ registration ,
4557 \Magento \Customer \Api \AccountManagementInterface $ accountManagement ,
58+ \Magento \Sales \Api \OrderRepositoryInterface $ orderRepository ,
59+ \Magento \Sales \Model \Order \Address \Validator $ addressValidator ,
4660 array $ data = []
4761 ) {
4862 $ this ->checkoutSession = $ checkoutSession ;
4963 $ this ->customerSession = $ customerSession ;
5064 $ this ->registration = $ registration ;
5165 $ this ->accountManagement = $ accountManagement ;
66+ $ this ->orderRepository = $ orderRepository ;
67+ $ this ->addressValidator = $ addressValidator ;
5268 parent ::__construct ($ context , $ data );
5369 }
5470
@@ -81,9 +97,28 @@ public function toHtml()
8197 $ this ->customerSession ->isLoggedIn ()
8298 || !$ this ->registration ->isAllowed ()
8399 || !$ this ->accountManagement ->isEmailAvailable ($ this ->getEmailAddress ())
100+ || !$ this ->validateAddresses ()
84101 ) {
85102 return '' ;
86103 }
87104 return parent ::toHtml ();
88105 }
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+ }
89124}
0 commit comments