Skip to content

Commit 0ce6682

Browse files
committed
MC-42791: [Magento Cloud] Products not showing in catagories
1 parent c483469 commit 0ce6682

File tree

2 files changed

+13
-122
lines changed

2 files changed

+13
-122
lines changed

app/code/Magento/CatalogSearch/Model/Indexer/Fulltext/Action/DataProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public function getSearchableProducts(
210210
$lastProductId = 0,
211211
$batch = 100
212212
) {
213-
$select = $this->selectSearchableProducts->execute($storeId, $staticFields, $productIds, $lastProductId, $batch);
213+
$select = $this->selectSearchableProducts->execute((int)$storeId, $staticFields, $productIds, $lastProductId, $batch);
214214
if ($productIds === null) {
215215
$select->where(
216216
'e.entity_id < ?',
@@ -221,7 +221,7 @@ public function getSearchableProducts(
221221
if ($productIds === null && !$products) {
222222
// try to search without limit entity_id by batch size for cover case with a big gap between entity ids
223223
$products = $this->connection->fetchAll(
224-
$this->selectSearchableProducts->execute($storeId, $staticFields, $productIds, $lastProductId, $batch)
224+
$this->selectSearchableProducts->execute((int)$storeId, $staticFields, $productIds, $lastProductId, $batch)
225225
);
226226
}
227227

app/code/Magento/CatalogSearch/Model/Indexer/Fulltext/Action/GetSearchableProductsSelect.php

Lines changed: 11 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,14 @@
1010
use Magento\Catalog\Model\Product;
1111
use Magento\Catalog\Model\Product\Attribute\Source\Status;
1212
use Magento\Catalog\Model\Product\Type;
13-
use Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory;
1413
use Magento\CatalogSearch\Model\ResourceModel\EngineInterface;
1514
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;
1816
use Magento\Framework\App\ResourceConnection;
1917
use Magento\Framework\DB\Adapter\AdapterInterface;
2018
use Magento\Framework\DB\Select;
2119
use Magento\Framework\EntityManager\EntityMetadata;
2220
use Magento\Framework\EntityManager\MetadataPool;
23-
use Magento\Framework\Event\ManagerInterface;
24-
use Magento\Framework\Exception\LocalizedException;
2521
use Magento\Framework\Exception\NoSuchEntityException;
2622
use Magento\Store\Model\Store;
2723
use Magento\Store\Model\StoreManagerInterface;
@@ -53,50 +49,35 @@ class GetSearchableProductsSelect
5349
* @var EntityMetadata
5450
*/
5551
private $metadata;
52+
5653
/**
57-
* @var Config
58-
*/
59-
private $eavConfig;
60-
/**
61-
* @var CollectionFactory
62-
*/
63-
private $productAttributeCollectionFactory;
64-
/**
65-
* @var ManagerInterface
54+
* @var AttributeRepositoryInterface
6655
*/
67-
private $eventManager;
68-
private $searchableAttributes;
69-
private $searchableAttributesByBackendType;
56+
private $attributeRepository;
7057

7158
/**
7259
* @param ResourceConnection $resource
7360
* @param Type $catalogProductType
74-
* @param Config $eavConfig
75-
* @param CollectionFactory $prodAttributeCollectionFactory
7661
* @param EngineProvider $engineProvider
77-
* @param ManagerInterface $eventManager
7862
* @param StoreManagerInterface $storeManager
7963
* @param MetadataPool $metadataPool
64+
* @param AttributeRepositoryInterface $attributeRepository
8065
* @throws \Exception
8166
*/
8267
public function __construct(
8368
ResourceConnection $resource,
8469
Type $catalogProductType,
85-
Config $eavConfig,
86-
CollectionFactory $prodAttributeCollectionFactory,
8770
EngineProvider $engineProvider,
88-
ManagerInterface $eventManager,
8971
StoreManagerInterface $storeManager,
90-
MetadataPool $metadataPool
72+
MetadataPool $metadataPool,
73+
AttributeRepositoryInterface $attributeRepository
9174
) {
9275
$this->resource = $resource;
9376
$this->connection = $resource->getConnection();
94-
$this->eavConfig = $eavConfig;
95-
$this->productAttributeCollectionFactory = $prodAttributeCollectionFactory;
96-
$this->eventManager = $eventManager;
9777
$this->storeManager = $storeManager;
9878
$this->engine = $engineProvider->get();
9979
$this->metadata = $metadataPool->getMetadata(ProductInterface::class);
80+
$this->attributeRepository = $attributeRepository;
10081
}
10182

10283
/**
@@ -151,11 +132,12 @@ public function execute(
151132
* @param string $attributeCode
152133
* @param int $storeId
153134
* @param array $whereValue
135+
* @throws NoSuchEntityException
154136
*/
155-
private function joinAttribute(Select $select, $attributeCode, $storeId, array $whereValue)
137+
private function joinAttribute(Select $select, string $attributeCode, int $storeId, array $whereValue)
156138
{
157139
$linkField = $this->metadata->getLinkField();
158-
$attribute = $this->getSearchableAttribute($attributeCode);
140+
$attribute = $this->attributeRepository->get(Product::ENTITY, $attributeCode);
159141
$attributeTable = $this->resource->getTableName('catalog_product_entity_' . $attribute->getBackendType());
160142
$defaultAlias = $attributeCode . '_default';
161143
$storeAlias = $attributeCode . '_store';
@@ -191,95 +173,4 @@ private function joinAttribute(Select $select, $attributeCode, $storeId, array $
191173
$whereValue
192174
);
193175
}
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-
}
285176
}

0 commit comments

Comments
 (0)