|
10 | 10 | use Magento\Customer\Helper\Address as AddressHelper;
|
11 | 11 | use Magento\Customer\Model\Session;
|
12 | 12 | use Magento\Directory\Helper\Data as DirectoryHelper;
|
| 13 | +use Magento\Directory\Model\AllowedCountries; |
| 14 | +use Magento\Framework\App\ObjectManager; |
13 | 15 | use Magento\Framework\Exception\LocalizedException;
|
14 | 16 | use Magento\Framework\Exception\NoSuchEntityException;
|
15 | 17 |
|
@@ -92,23 +94,32 @@ class AttributeMerger
|
92 | 94 | */
|
93 | 95 | private $topCountryCodes;
|
94 | 96 |
|
| 97 | + /** |
| 98 | + * @var AllowedCountries|null |
| 99 | + */ |
| 100 | + private $allowedCountryReader; |
| 101 | + |
95 | 102 | /**
|
96 | 103 | * @param AddressHelper $addressHelper
|
97 | 104 | * @param Session $customerSession
|
98 | 105 | * @param CustomerRepository $customerRepository
|
99 | 106 | * @param DirectoryHelper $directoryHelper
|
| 107 | + * @param AllowedCountries $allowedCountryReader |
100 | 108 | */
|
101 | 109 | public function __construct(
|
102 | 110 | AddressHelper $addressHelper,
|
103 | 111 | Session $customerSession,
|
104 | 112 | CustomerRepository $customerRepository,
|
105 |
| - DirectoryHelper $directoryHelper |
| 113 | + DirectoryHelper $directoryHelper, |
| 114 | + ?AllowedCountries $allowedCountryReader = null |
106 | 115 | ) {
|
107 | 116 | $this->addressHelper = $addressHelper;
|
108 | 117 | $this->customerSession = $customerSession;
|
109 | 118 | $this->customerRepository = $customerRepository;
|
110 | 119 | $this->directoryHelper = $directoryHelper;
|
111 | 120 | $this->topCountryCodes = $directoryHelper->getTopCountryCodes();
|
| 121 | + $this->allowedCountryReader = |
| 122 | + $allowedCountryReader ?: ObjectManager::getInstance()->get(AllowedCountries::class); |
112 | 123 | }
|
113 | 124 |
|
114 | 125 | /**
|
@@ -289,7 +300,7 @@ protected function getMultilineFieldConfig($attributeCode, array $attributeConfi
|
289 | 300 | 'dataScope' => $lineIndex,
|
290 | 301 | 'provider' => $providerName,
|
291 | 302 | 'validation' => $isFirstLine
|
292 |
| - //phpcs:ignore Magento2.Performance.ForeachArrayMerge |
| 303 | + // phpcs:ignore Magento2.Performance.ForeachArrayMerge |
293 | 304 | ? array_merge(
|
294 | 305 | ['required-entry' => (bool)$attributeConfig['required']],
|
295 | 306 | $attributeConfig['validation']
|
@@ -330,7 +341,11 @@ protected function getMultilineFieldConfig($attributeCode, array $attributeConfi
|
330 | 341 | protected function getDefaultValue($attributeCode): ?string
|
331 | 342 | {
|
332 | 343 | if ($attributeCode === 'country_id') {
|
333 |
| - return $this->directoryHelper->getDefaultCountry(); |
| 344 | + $defaultCountryId = $this->directoryHelper->getDefaultCountry(); |
| 345 | + if (!in_array($defaultCountryId, $this->allowedCountryReader->getAllowedCountries())) { |
| 346 | + $defaultCountryId = null; |
| 347 | + } |
| 348 | + return $defaultCountryId; |
334 | 349 | }
|
335 | 350 |
|
336 | 351 | $customer = $this->getCustomer();
|
|
0 commit comments