7
7
8
8
use Magento \Customer \Api \Data \CustomerInterface ;
9
9
use Magento \Customer \Api \Data \GroupInterface ;
10
+ use Magento \Directory \Model \AllowedCountries ;
10
11
use Magento \Framework \Api \AttributeValueFactory ;
11
12
use Magento \Framework \Api \ExtensionAttribute \JoinProcessorInterface ;
12
13
use Magento \Framework \Model \AbstractExtensibleModel ;
13
14
use Magento \Quote \Api \Data \PaymentInterface ;
14
15
use Magento \Quote \Model \Quote \Address ;
15
16
use Magento \Quote \Model \Quote \Address \Total as AddressTotal ;
16
17
use Magento \Sales \Model \Status ;
18
+ use Magento \Store \Model \ScopeInterface ;
17
19
use Magento \Framework \App \ObjectManager ;
18
20
19
21
/**
@@ -359,6 +361,11 @@ class Quote extends AbstractExtensibleModel implements \Magento\Quote\Api\Data\C
359
361
*/
360
362
private $ orderIncrementIdChecker ;
361
363
364
+ /**
365
+ * @var AllowedCountries
366
+ */
367
+ private $ allowedCountriesReader ;
368
+
362
369
/**
363
370
* @param \Magento\Framework\Model\Context $context
364
371
* @param \Magento\Framework\Registry $registry
@@ -444,7 +451,8 @@ public function __construct(
444
451
\Magento \Framework \Model \ResourceModel \AbstractResource $ resource = null ,
445
452
\Magento \Framework \Data \Collection \AbstractDb $ resourceCollection = null ,
446
453
array $ data = [],
447
- \Magento \Sales \Model \OrderIncrementIdChecker $ orderIncrementIdChecker = null
454
+ \Magento \Sales \Model \OrderIncrementIdChecker $ orderIncrementIdChecker = null ,
455
+ AllowedCountries $ allowedCountriesReader = null
448
456
) {
449
457
$ this ->quoteValidator = $ quoteValidator ;
450
458
$ this ->_catalogProduct = $ catalogProduct ;
@@ -481,6 +489,8 @@ public function __construct(
481
489
$ this ->shippingAssignmentFactory = $ shippingAssignmentFactory ;
482
490
$ this ->orderIncrementIdChecker = $ orderIncrementIdChecker ?: ObjectManager::getInstance ()
483
491
->get (\Magento \Sales \Model \OrderIncrementIdChecker::class);
492
+ $ this ->allowedCountriesReader = $ allowedCountriesReader
493
+ ?: ObjectManager::getInstance ()->get (AllowedCountries::class);
484
494
parent ::__construct (
485
495
$ context ,
486
496
$ registry ,
@@ -941,7 +951,9 @@ public function assignCustomerWithAddressChange(
941
951
/** @var \Magento\Quote\Model\Quote\Address $billingAddress */
942
952
$ billingAddress = $ this ->_quoteAddressFactory ->create ();
943
953
$ billingAddress ->importCustomerAddressData ($ defaultBillingAddress );
944
- $ this ->setBillingAddress ($ billingAddress );
954
+ if ($ this ->isAddressAllowedForWebsite ($ billingAddress , (int )$ this ->getStoreId ())) {
955
+ $ this ->setBilliphpngAddress ($ billingAddress );
956
+ }
945
957
}
946
958
}
947
959
@@ -959,7 +971,9 @@ public function assignCustomerWithAddressChange(
959
971
$ shippingAddress = $ this ->_quoteAddressFactory ->create ();
960
972
}
961
973
}
962
- $ this ->setShippingAddress ($ shippingAddress );
974
+ if ($ this ->isAddressAllowedForWebsite ($ shippingAddress , (int )$ this ->getStoreId ())) {
975
+ $ this ->setShippingAddress ($ shippingAddress );
976
+ }
963
977
}
964
978
965
979
return $ this ;
@@ -2596,4 +2610,18 @@ public function setExtensionAttributes(\Magento\Quote\Api\Data\CartExtensionInte
2596
2610
{
2597
2611
return $ this ->_setExtensionAttributes ($ extensionAttributes );
2598
2612
}
2613
+
2614
+ /**
2615
+ * Check is address allowed for store
2616
+ *
2617
+ * @param Address $address
2618
+ * @param int $storeId
2619
+ * @return bool
2620
+ */
2621
+ private function isAddressAllowedForWebsite (Address $ address , int $ storeId ): bool
2622
+ {
2623
+ $ allowedCountries = $ this ->allowedCountriesReader ->getAllowedCountries (ScopeInterface::SCOPE_STORE , $ storeId );
2624
+
2625
+ return in_array ($ address ->getCountryId (), $ allowedCountries );
2626
+ }
2599
2627
}
0 commit comments