Skip to content

Commit 30594d7

Browse files
authored
MCLOUD-7742: Updated patch to fix the layered navigation issue (#24)
1 parent 3361e84 commit 30594d7

File tree

1 file changed

+81
-9
lines changed

1 file changed

+81
-9
lines changed

patches/MCLOUD-6923__layered_navigation_filter_is_present_only_when_product_is_present_on_the_listing_page_with_enabled_shared_catalog__2.3.5.patch

Lines changed: 81 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,64 @@
11
diff -Nuar a/vendor/magento/module-shared-catalog/Model/SearchAdapter/Aggregation/Builder/DataProvider.php b/vendor/magento/module-shared-catalog/Model/SearchAdapter/Aggregation/Builder/DataProvider.php
2+
index 86f4fd48e9..a6061fca6f 100644
23
--- a/vendor/magento/module-shared-catalog/Model/SearchAdapter/Aggregation/Builder/DataProvider.php
34
+++ b/vendor/magento/module-shared-catalog/Model/SearchAdapter/Aggregation/Builder/DataProvider.php
4-
@@ -103,18 +103,16 @@ public function __construct(
5+
@@ -7,6 +7,8 @@ declare(strict_types=1);
6+
7+
namespace Magento\SharedCatalog\Model\SearchAdapter\Aggregation\Builder;
8+
9+
+use Magento\Catalog\Model\Layer;
10+
+use Magento\Catalog\Model\Layer\Resolver;
11+
use Magento\Catalog\Model\Product;
12+
use Magento\Catalog\Model\ResourceModel\Product as ProductResource;
13+
use Magento\CatalogInventory\Model\Configuration;
14+
@@ -14,6 +16,7 @@ use Magento\CatalogInventory\Model\Stock;
15+
use Magento\Customer\Model\Session;
16+
use Magento\Eav\Model\Config as EavConfig;
17+
use Magento\Framework\App\Config\ScopeConfigInterface;
18+
+use Magento\Framework\App\ObjectManager;
19+
use Magento\Framework\App\ResourceConnection;
20+
use Magento\Framework\App\ScopeResolverInterface;
21+
use Magento\Framework\DB\Adapter\AdapterInterface;
22+
@@ -70,6 +73,11 @@ class DataProvider
23+
*/
24+
private $productItem;
25+
26+
+ /**
27+
+ * @var Layer
28+
+ */
29+
+ private $searchLayer;
30+
+
31+
/**
32+
* @param ResourceConnection $resource
33+
* @param Session $session
34+
@@ -78,6 +86,7 @@ class DataProvider
35+
* @param EavConfig $eavConfig
36+
* @param ProductResource $product
37+
* @param ProductItemResource $productItem
38+
+ * @param Resolver|null $layerResolver
39+
*/
40+
public function __construct(
41+
ResourceConnection $resource,
42+
@@ -86,7 +95,8 @@ class DataProvider
43+
ScopeConfigInterface $scopeConfig,
44+
EavConfig $eavConfig,
45+
ProductResource $product,
46+
- ProductItemResource $productItem
47+
+ ProductItemResource $productItem,
48+
+ ?Resolver $layerResolver = null
49+
) {
50+
$this->resource = $resource;
51+
$this->connection = $resource->getConnection();
52+
@@ -96,6 +106,8 @@ class DataProvider
53+
$this->eavConfig = $eavConfig;
54+
$this->product = $product;
55+
$this->productItem = $productItem;
56+
+ $layerResolver = $layerResolver ?? ObjectManager::getInstance()->get(Resolver::class);
57+
+ $this->searchLayer = $layerResolver->get();
58+
}
59+
60+
/**
61+
@@ -103,18 +115,16 @@ class DataProvider
562
*
663
* @param BucketInterface $bucket
764
* @param array $dimensions
@@ -20,9 +77,9 @@ diff -Nuar a/vendor/magento/module-shared-catalog/Model/SearchAdapter/Aggregatio
2077
- $select = $this->getSelect($bucket, $dimensions, $documentIds);
2178
+ $select = $this->getSelect($bucket, $dimensions);
2279
$query = $this->connection->query($select);
23-
80+
2481
while ($row = $query->fetch()) {
25-
@@ -134,11 +132,10 @@ public function getAggregation(
82+
@@ -134,15 +144,15 @@ class DataProvider
2683
*
2784
* @param BucketInterface $bucket
2885
* @param array $dimensions
@@ -35,24 +92,39 @@ diff -Nuar a/vendor/magento/module-shared-catalog/Model/SearchAdapter/Aggregatio
3592
{
3693
$attribute = $this->eavConfig->getAttribute(Product::ENTITY, $bucket->getField());
3794
$currentScope = $this->scopeResolver->getScope($dimensions['scope']->getValue());
38-
@@ -161,7 +158,6 @@ private function getSelect(BucketInterface $bucket, array $dimensions, array $do
95+
$customerGroupId = $this->session->getCustomerGroupId();
96+
+ $categoryId = $this->searchLayer->getCurrentCategory()->getId();
97+
98+
$eavIndexTable = $this->resource->getTableName(
99+
'catalog_product_index_eav' . ($attribute->getBackendType() === 'decimal' ? '_decimal' : '')
100+
@@ -160,11 +170,14 @@ class DataProvider
101+
['shared_catalog_item' => $this->productItem->getMainTable()],
39102
'source_entity.sku = shared_catalog_item.sku',
40103
[]
104+
+ )->joinInner(
105+
+ ['catalog_category_product' => $this->resource->getTableName('catalog_category_product')],
106+
+ 'eav.entity_id = catalog_category_product.product_id',
107+
+ []
41108
)
42109
- ->where('eav.entity_id IN (?)', $documentIds)
43110
->where('eav.attribute_id = ?', $attribute->getId())
44111
->where('eav.store_id = ? ', $currentScope->getId())
45-
->where('source_entity.type_id <> ?', 'configurable')
46-
diff -Nuar a/vendor/magento/module-shared-catalog/Plugin/Elasticsearch/SearchAdapter/Aggregation/Builder/UpdateTermBucketBuilderPlugin.php b/vendor/magento/module-shared-catalog/Plugin/Elasticsearch/SearchAdapter/Aggregation/Builder/UpdateTermBucketBuilderPlugin.php
112+
- ->where('source_entity.type_id <> ?', 'configurable')
113+
+ ->where('catalog_category_product.category_id = ?', $categoryId)
114+
->where('shared_catalog_item.customer_group_id = ?', $customerGroupId);
115+
116+
$this->addStockFilterToSelect($subSelect);
117+
diff --git a/vendor/magento/module-shared-catalog/Plugin/Elasticsearch/SearchAdapter/Aggregation/Builder/UpdateTermBucketBuilderPlugin.php b/vendor/magento/module-shared-catalog/Plugin/Elasticsearch/SearchAdapter/Aggregation/Builder/UpdateTermBucketBuilderPlugin.php
118+
index fdc811dbeb..28b1cd4ee4 100644
47119
--- a/vendor/magento/module-shared-catalog/Plugin/Elasticsearch/SearchAdapter/Aggregation/Builder/UpdateTermBucketBuilderPlugin.php
48120
+++ b/vendor/magento/module-shared-catalog/Plugin/Elasticsearch/SearchAdapter/Aggregation/Builder/UpdateTermBucketBuilderPlugin.php
49-
@@ -65,8 +65,7 @@ public function afterBuild(
121+
@@ -65,8 +65,7 @@ class UpdateTermBucketBuilderPlugin
50122
$shouldAggregate = ($bucket->getField() !== 'category_ids');
51-
123+
52124
if ($sharedCatalogIsEnabled && $shouldAggregate) {
53125
- $documentIds = array_column($queryResult['hits']['hits'], '_id');
54126
- $values = $this->dataProvider->getAggregation($bucket, $dimensions, $documentIds);
55127
+ $values = $this->dataProvider->getAggregation($bucket, $dimensions);
56128
}
57-
129+
58130
return $values;

0 commit comments

Comments
 (0)