Skip to content

Commit bf1eb88

Browse files
pradeep.rauthanpradeep.rauthan
authored andcommitted
MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings
1 parent 6b851fb commit bf1eb88

File tree

2 files changed

+15
-63
lines changed

2 files changed

+15
-63
lines changed

app/code/Magento/Sales/ViewModel/Customer/Address/AddressAttributeFilter.php

Lines changed: 10 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -10,100 +10,48 @@
1010

1111
use Magento\Customer\Model\ResourceModel\Address\Collection;
1212
use Magento\Directory\Model\AllowedCountries;
13+
use Magento\Framework\Exception\LocalizedException;
1314
use Magento\Framework\View\Element\Block\ArgumentInterface;
1415
use Magento\Store\Model\ScopeInterface;
1516

1617
/**
1718
* Customer's addresses filter as per allowed country filter for corresponding store
1819
*/
19-
class AddressAttributeFilter extends \Magento\Eav\Model\Entity\Collection\VersionControl\AbstractCollection implements ArgumentInterface
20+
class AddressAttributeFilter implements ArgumentInterface
2021
{
2122
/**
2223
* @var AllowedCountries
2324
*/
2425
private $allowedCountryReader;
2526

2627
/**
27-
* @var Collection
28-
*/
29-
private $collection;
30-
31-
/**
32-
* @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
33-
* @param \Psr\Log\LoggerInterface $logger
34-
* @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
35-
* @param \Magento\Framework\Event\ManagerInterface $eventManager
36-
* @param \Magento\Eav\Model\Config $eavConfig
37-
* @param \Magento\Framework\App\ResourceConnection $resource
38-
* @param \Magento\Eav\Model\EntityFactory $eavEntityFactory
39-
* @param \Magento\Eav\Model\ResourceModel\Helper $resourceHelper
40-
* @param \Magento\Framework\Validator\UniversalFactory $universalFactory
41-
* @param \Magento\Framework\Model\ResourceModel\Db\VersionControl\Snapshot $entitySnapshot
4228
* @param AllowedCountries $allowedCountryReader
43-
* @param Collection $collection
44-
* @param \Magento\Framework\DB\Adapter\AdapterInterface|null $connection
45-
*
46-
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
4729
*/
4830
public function __construct(
49-
\Magento\Framework\Data\Collection\EntityFactory $entityFactory,
50-
\Psr\Log\LoggerInterface $logger,
51-
\Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy,
52-
\Magento\Framework\Event\ManagerInterface $eventManager,
53-
\Magento\Eav\Model\Config $eavConfig,
54-
\Magento\Framework\App\ResourceConnection $resource,
55-
\Magento\Eav\Model\EntityFactory $eavEntityFactory,
56-
\Magento\Eav\Model\ResourceModel\Helper $resourceHelper,
57-
\Magento\Framework\Validator\UniversalFactory $universalFactory,
58-
\Magento\Framework\Model\ResourceModel\Db\VersionControl\Snapshot $entitySnapshot,
59-
AllowedCountries $allowedCountryReader,
60-
Collection $collection,
61-
\Magento\Framework\DB\Adapter\AdapterInterface $connection = null
31+
AllowedCountries $allowedCountryReader
6232
) {
6333
$this->allowedCountryReader = $allowedCountryReader;
64-
$this->collection = $collection;
65-
66-
parent::__construct(
67-
$entityFactory,
68-
$logger,
69-
$fetchStrategy,
70-
$eventManager,
71-
$eavConfig,
72-
$resource,
73-
$eavEntityFactory,
74-
$resourceHelper,
75-
$universalFactory,
76-
$entitySnapshot,
77-
$connection
78-
);
7934
}
8035

81-
/**
82-
* Resource initialization
83-
*
84-
* @return void
85-
*/
86-
protected function _construct()
87-
{
88-
$this->_init(\Magento\Customer\Model\Address::class, \Magento\Customer\Model\ResourceModel\Address::class);
89-
}
9036

9137
/**
9238
* Set allowed country filter for customer's addresses
9339
*
94-
* @return $this|Object
95-
* @throws \Magento\Framework\Exception\LocalizedException
40+
* @param Collection $collection
41+
* @param $storeId
42+
* @return Object
43+
* @throws LocalizedException
9644
*/
97-
public function setScopeFilter($storeId)
45+
public function setScopeFilter(Collection $collection, $storeId)
9846
{
9947
if ($storeId) {
10048
$allowedCountries = $this->allowedCountryReader->getAllowedCountries(
10149
ScopeInterface::SCOPE_STORE,
10250
$storeId
10351
);
104-
$this->collection->addAttributeToFilter('country_id', ['in' => $allowedCountries]);
52+
$collection->addAttributeToFilter('country_id', ['in' => $allowedCountries]);
10553
}
10654

107-
return $this->collection;
55+
return $collection;
10856
}
10957
}

app/code/Magento/Sales/view/adminhtml/templates/order/create/form/address.phtml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@
1010
*/
1111

1212
/**
13+
* @var \Magento\Customer\Model\ResourceModel\Address\Collection $addressCollection
1314
* @var $viewModel \Magento\Sales\ViewModel\Customer\Address\AddressAttributeFilter
1415
*/
16+
17+
$addressCollection = $block->getData('customerAddressCollection');
1518
$viewModel = $block->getViewModel();
1619

1720
$addressArray = [];
1821
if ($block->getCustomerId()):
19-
$addressArray = $viewModel->setScopeFilter($block->getStoreId())->setCustomerFilter([$block->getCustomerId()])->toArray();
22+
$addressArray = $viewModel->setScopeFilter($addressCollection, $block->getStoreId())
23+
->setCustomerFilter([$block->getCustomerId()])->toArray();
2024
endif;
2125

2226
/**

0 commit comments

Comments
 (0)