|
10 | 10 | use Magento\Catalog\Model\Product;
|
11 | 11 | use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
12 | 12 | use Magento\Catalog\Model\Product\Type;
|
13 |
| -use Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory; |
14 | 13 | use Magento\CatalogSearch\Model\ResourceModel\EngineInterface;
|
15 | 14 | use Magento\CatalogSearch\Model\ResourceModel\EngineProvider;
|
16 |
| -use Magento\Eav\Model\Config; |
17 |
| -use Magento\Eav\Model\Entity\Attribute; |
| 15 | +use Magento\Eav\Api\AttributeRepositoryInterface; |
18 | 16 | use Magento\Framework\App\ResourceConnection;
|
19 | 17 | use Magento\Framework\DB\Adapter\AdapterInterface;
|
20 | 18 | use Magento\Framework\DB\Select;
|
21 | 19 | use Magento\Framework\EntityManager\EntityMetadata;
|
22 | 20 | use Magento\Framework\EntityManager\MetadataPool;
|
23 |
| -use Magento\Framework\Event\ManagerInterface; |
24 |
| -use Magento\Framework\Exception\LocalizedException; |
25 | 21 | use Magento\Framework\Exception\NoSuchEntityException;
|
26 | 22 | use Magento\Store\Model\Store;
|
27 | 23 | use Magento\Store\Model\StoreManagerInterface;
|
@@ -53,50 +49,35 @@ class GetSearchableProductsSelect
|
53 | 49 | * @var EntityMetadata
|
54 | 50 | */
|
55 | 51 | private $metadata;
|
| 52 | + |
56 | 53 | /**
|
57 |
| - * @var Config |
58 |
| - */ |
59 |
| - private $eavConfig; |
60 |
| - /** |
61 |
| - * @var CollectionFactory |
62 |
| - */ |
63 |
| - private $productAttributeCollectionFactory; |
64 |
| - /** |
65 |
| - * @var ManagerInterface |
| 54 | + * @var AttributeRepositoryInterface |
66 | 55 | */
|
67 |
| - private $eventManager; |
68 |
| - private $searchableAttributes; |
69 |
| - private $searchableAttributesByBackendType; |
| 56 | + private $attributeRepository; |
70 | 57 |
|
71 | 58 | /**
|
72 | 59 | * @param ResourceConnection $resource
|
73 | 60 | * @param Type $catalogProductType
|
74 |
| - * @param Config $eavConfig |
75 |
| - * @param CollectionFactory $prodAttributeCollectionFactory |
76 | 61 | * @param EngineProvider $engineProvider
|
77 |
| - * @param ManagerInterface $eventManager |
78 | 62 | * @param StoreManagerInterface $storeManager
|
79 | 63 | * @param MetadataPool $metadataPool
|
| 64 | + * @param AttributeRepositoryInterface $attributeRepository |
80 | 65 | * @throws \Exception
|
81 | 66 | */
|
82 | 67 | public function __construct(
|
83 | 68 | ResourceConnection $resource,
|
84 | 69 | Type $catalogProductType,
|
85 |
| - Config $eavConfig, |
86 |
| - CollectionFactory $prodAttributeCollectionFactory, |
87 | 70 | EngineProvider $engineProvider,
|
88 |
| - ManagerInterface $eventManager, |
89 | 71 | StoreManagerInterface $storeManager,
|
90 |
| - MetadataPool $metadataPool |
| 72 | + MetadataPool $metadataPool, |
| 73 | + AttributeRepositoryInterface $attributeRepository |
91 | 74 | ) {
|
92 | 75 | $this->resource = $resource;
|
93 | 76 | $this->connection = $resource->getConnection();
|
94 |
| - $this->eavConfig = $eavConfig; |
95 |
| - $this->productAttributeCollectionFactory = $prodAttributeCollectionFactory; |
96 |
| - $this->eventManager = $eventManager; |
97 | 77 | $this->storeManager = $storeManager;
|
98 | 78 | $this->engine = $engineProvider->get();
|
99 | 79 | $this->metadata = $metadataPool->getMetadata(ProductInterface::class);
|
| 80 | + $this->attributeRepository = $attributeRepository; |
100 | 81 | }
|
101 | 82 |
|
102 | 83 | /**
|
@@ -151,11 +132,12 @@ public function execute(
|
151 | 132 | * @param string $attributeCode
|
152 | 133 | * @param int $storeId
|
153 | 134 | * @param array $whereValue
|
| 135 | + * @throws NoSuchEntityException |
154 | 136 | */
|
155 |
| - private function joinAttribute(Select $select, $attributeCode, $storeId, array $whereValue) |
| 137 | + private function joinAttribute(Select $select, string $attributeCode, int $storeId, array $whereValue) |
156 | 138 | {
|
157 | 139 | $linkField = $this->metadata->getLinkField();
|
158 |
| - $attribute = $this->getSearchableAttribute($attributeCode); |
| 140 | + $attribute = $this->attributeRepository->get(Product::ENTITY, $attributeCode); |
159 | 141 | $attributeTable = $this->resource->getTableName('catalog_product_entity_' . $attribute->getBackendType());
|
160 | 142 | $defaultAlias = $attributeCode . '_default';
|
161 | 143 | $storeAlias = $attributeCode . '_store';
|
@@ -191,95 +173,4 @@ private function joinAttribute(Select $select, $attributeCode, $storeId, array $
|
191 | 173 | $whereValue
|
192 | 174 | );
|
193 | 175 | }
|
194 |
| - |
195 |
| - /** |
196 |
| - * Retrieve searchable attributes |
197 |
| - * |
198 |
| - * @param string $backendType |
199 |
| - * @return Attribute[] |
200 |
| - * @throws LocalizedException |
201 |
| - * @since 100.0.3 |
202 |
| - */ |
203 |
| - private function getSearchableAttributes($backendType = null) |
204 |
| - { |
205 |
| - /** TODO: Remove this block in the next minor release and add a new public method instead */ |
206 |
| - if ($this->eavConfig->getEntityType(Product::ENTITY)->getNeedRefreshSearchAttributesList()) { |
207 |
| - $this->clearSearchableAttributesList(); |
208 |
| - } |
209 |
| - if (null === $this->searchableAttributes) { |
210 |
| - $this->searchableAttributes = []; |
211 |
| - |
212 |
| - $productAttributes = $this->productAttributeCollectionFactory->create(); |
213 |
| - $productAttributes->addToIndexFilter(true); |
214 |
| - |
215 |
| - /** @var Attribute[] $attributes */ |
216 |
| - $attributes = $productAttributes->getItems(); |
217 |
| - |
218 |
| - /** @deprecated */ |
219 |
| - $this->eventManager->dispatch( |
220 |
| - 'catelogsearch_searchable_attributes_load_after', |
221 |
| - ['engine' => $this->engine, 'attributes' => $attributes] |
222 |
| - ); |
223 |
| - |
224 |
| - $this->eventManager->dispatch( |
225 |
| - 'catalogsearch_searchable_attributes_load_after', |
226 |
| - ['engine' => $this->engine, 'attributes' => $attributes] |
227 |
| - ); |
228 |
| - |
229 |
| - $entity = $this->eavConfig->getEntityType(Product::ENTITY)->getEntity(); |
230 |
| - |
231 |
| - foreach ($attributes as $attribute) { |
232 |
| - $attribute->setEntity($entity); |
233 |
| - $this->searchableAttributes[$attribute->getAttributeId()] = $attribute; |
234 |
| - $this->searchableAttributes[$attribute->getAttributeCode()] = $attribute; |
235 |
| - } |
236 |
| - } |
237 |
| - |
238 |
| - if ($backendType !== null) { |
239 |
| - if (isset($this->searchableAttributesByBackendType[$backendType])) { |
240 |
| - return $this->searchableAttributesByBackendType[$backendType]; |
241 |
| - } |
242 |
| - $this->searchableAttributesByBackendType[$backendType] = []; |
243 |
| - foreach ($this->searchableAttributes as $attribute) { |
244 |
| - if ($attribute->getBackendType() == $backendType) { |
245 |
| - $this->searchableAttributesByBackendType[$backendType][$attribute->getAttributeId()] = $attribute; |
246 |
| - } |
247 |
| - } |
248 |
| - |
249 |
| - return $this->searchableAttributesByBackendType[$backendType]; |
250 |
| - } |
251 |
| - |
252 |
| - return $this->searchableAttributes; |
253 |
| - } |
254 |
| - |
255 |
| - /** |
256 |
| - * Remove searchable attributes list. |
257 |
| - * |
258 |
| - * @return void |
259 |
| - * @throws LocalizedException |
260 |
| - */ |
261 |
| - private function clearSearchableAttributesList(): void |
262 |
| - { |
263 |
| - $this->searchableAttributes = null; |
264 |
| - $this->searchableAttributesByBackendType = []; |
265 |
| - $this->eavConfig->getEntityType(Product::ENTITY)->unsNeedRefreshSearchAttributesList(); |
266 |
| - } |
267 |
| - |
268 |
| - /** |
269 |
| - * Retrieve searchable attribute by Id or code |
270 |
| - * |
271 |
| - * @param int|string $attribute |
272 |
| - * @return Attribute |
273 |
| - * @throws LocalizedException |
274 |
| - * @since 100.0.3 |
275 |
| - */ |
276 |
| - private function getSearchableAttribute($attribute) |
277 |
| - { |
278 |
| - $attributes = $this->getSearchableAttributes(); |
279 |
| - if (isset($attributes[$attribute])) { |
280 |
| - return $attributes[$attribute]; |
281 |
| - } |
282 |
| - |
283 |
| - return $this->eavConfig->getAttribute(Product::ENTITY, $attribute); |
284 |
| - } |
285 | 176 | }
|
0 commit comments