|
10 | 10 |
|
11 | 11 | use Magento\Customer\Model\ResourceModel\Address\Collection;
|
12 | 12 | use Magento\Directory\Model\AllowedCountries;
|
| 13 | +use Magento\Framework\Exception\LocalizedException; |
13 | 14 | use Magento\Framework\View\Element\Block\ArgumentInterface;
|
14 | 15 | use Magento\Store\Model\ScopeInterface;
|
15 | 16 |
|
16 | 17 | /**
|
17 | 18 | * Customer's addresses filter as per allowed country filter for corresponding store
|
18 | 19 | */
|
19 |
| -class AddressAttributeFilter extends \Magento\Eav\Model\Entity\Collection\VersionControl\AbstractCollection implements ArgumentInterface |
| 20 | +class AddressAttributeFilter implements ArgumentInterface |
20 | 21 | {
|
21 | 22 | /**
|
22 | 23 | * @var AllowedCountries
|
23 | 24 | */
|
24 | 25 | private $allowedCountryReader;
|
25 | 26 |
|
26 | 27 | /**
|
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 |
42 | 28 | * @param AllowedCountries $allowedCountryReader
|
43 |
| - * @param Collection $collection |
44 |
| - * @param \Magento\Framework\DB\Adapter\AdapterInterface|null $connection |
45 |
| - * |
46 |
| - * @SuppressWarnings(PHPMD.ExcessiveParameterList) |
47 | 29 | */
|
48 | 30 | 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 |
62 | 32 | ) {
|
63 | 33 | $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 |
| - ); |
79 | 34 | }
|
80 | 35 |
|
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 |
| - } |
90 | 36 |
|
91 | 37 | /**
|
92 | 38 | * Set allowed country filter for customer's addresses
|
93 | 39 | *
|
94 |
| - * @return $this|Object |
95 |
| - * @throws \Magento\Framework\Exception\LocalizedException |
| 40 | + * @param Collection $collection |
| 41 | + * @param $storeId |
| 42 | + * @return Object |
| 43 | + * @throws LocalizedException |
96 | 44 | */
|
97 |
| - public function setScopeFilter($storeId) |
| 45 | + public function setScopeFilter(Collection $collection, $storeId) |
98 | 46 | {
|
99 | 47 | if ($storeId) {
|
100 | 48 | $allowedCountries = $this->allowedCountryReader->getAllowedCountries(
|
101 | 49 | ScopeInterface::SCOPE_STORE,
|
102 | 50 | $storeId
|
103 | 51 | );
|
104 |
| - $this->collection->addAttributeToFilter('country_id', ['in' => $allowedCountries]); |
| 52 | + $collection->addAttributeToFilter('country_id', ['in' => $allowedCountries]); |
105 | 53 | }
|
106 | 54 |
|
107 |
| - return $this->collection; |
| 55 | + return $collection; |
108 | 56 | }
|
109 | 57 | }
|
0 commit comments