From fa9033987baacd24a18b46c5deaf4639bd367134 Mon Sep 17 00:00:00 2001 From: Kostadin Bashev Date: Wed, 25 Aug 2021 14:32:20 +0300 Subject: [PATCH 01/30] Add is_discount configurable and grouped products depends on children discounts. --- .../Indexer/Fulltext/Datasource/PriceData.php | 68 ++++++++++++++----- 1 file changed, 52 insertions(+), 16 deletions(-) diff --git a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php index 0c2452b21..3d27be509 100644 --- a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php +++ b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php @@ -1,21 +1,21 @@ - * @copyright 2020 Smile - * @license Open Software License ("OSL") v. 3.0 + * @author Kostadin Bashev (bashev@webcode.bg) + * @copyright Copyright © 2021 Webcode Ltd. (https://webcode.bg/) + * @license See LICENSE.txt for license details. */ namespace Smile\ElasticsuiteCatalog\Model\Product\Indexer\Fulltext\Datasource; -use Smile\ElasticsuiteCore\Api\Index\DatasourceInterface; +use Magento\Catalog\Model\ProductRepository; +use Magento\Catalog\Pricing\Price\FinalPrice; +use Magento\Catalog\Pricing\Price\RegularPrice; +use Magento\ConfigurableProduct\Model\Product\Type\Configurable; +use Magento\GroupedProduct\Model\Product\Type\Grouped; use Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Indexer\Fulltext\Datasource\PriceData as ResourceModel; +use Smile\ElasticsuiteCore\Api\Index\DatasourceInterface; /** * Datasource used to append prices data to product during indexing. @@ -26,6 +26,11 @@ */ class PriceData implements DatasourceInterface { + /** + * @var \Magento\Catalog\Model\ProductRepository + */ + private $productRepository; + /** * @var \Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Indexer\Fulltext\Datasource\PriceData */ @@ -39,12 +44,17 @@ class PriceData implements DatasourceInterface /** * Constructor. * - * @param ResourceModel $resourceModel Resource model + * @param ProductRepository $productRepository + * @param ResourceModel $resourceModel Resource model * @param PriceData\PriceDataReaderInterface[] $priceReaderPool Price modifiers pool. */ - public function __construct(ResourceModel $resourceModel, $priceReaderPool = []) - { - $this->resourceModel = $resourceModel; + public function __construct( + ProductRepository $productRepository, + ResourceModel $resourceModel, + $priceReaderPool = [] + ) { + $this->productRepository = $productRepository; + $this->resourceModel = $resourceModel; $this->priceReaderPool = $priceReaderPool; } @@ -52,6 +62,7 @@ public function __construct(ResourceModel $resourceModel, $priceReaderPool = []) * Add price data to the index data. * * {@inheritdoc} + * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function addData($storeId, array $indexData) { @@ -65,10 +76,34 @@ public function addData($storeId, array $indexData) $originalPrice = $priceModifier->getOriginalPrice($priceDataRow); $price = $priceModifier->getPrice($priceDataRow); + $isDiscount = $price < $originalPrice; + if (in_array($productTypeId, [Grouped::TYPE_CODE, Configurable::TYPE_CODE])) { + $product = $this->productRepository->getById($productId); + + $isDiscount = false; + if ($productTypeId === Grouped::TYPE_CODE) { + $children = $product->getTypeInstance()->getAssociatedProducts($product); + } + + if ($productTypeId === Configurable::TYPE_CODE) { + $children = $product->getTypeInstance()->getUsedProducts($product); + } + + if (isset($children)) { + foreach ($children as $child) { + if ($child->getPriceInfo()->getPrice(FinalPrice::PRICE_CODE)->getAmount()->getValue() + < $child->getPriceInfo()->getPrice(RegularPrice::PRICE_CODE)->getAmount()->getValue()) { + $isDiscount = true; + break; + } + } + } + } + $indexData[$productId]['price'][] = [ 'price' => (float) $price, 'original_price' => (float) $originalPrice, - 'is_discount' => $price < $originalPrice, + 'is_discount' => $isDiscount, 'customer_group_id' => (int) $priceDataRow['customer_group_id'], 'tax_class_id' => (int) $priceDataRow['tax_class_id'], 'final_price' => (float) $priceDataRow['final_price'], @@ -89,6 +124,7 @@ public function addData($storeId, array $indexData) /** * Retur + * * @param string $typeId Product type id. * * @return PriceData\PriceDataReaderInterface From 9acb976e5db133d826fbe492c0eaad9070bb2be4 Mon Sep 17 00:00:00 2001 From: Kostadin Bashev Date: Wed, 25 Aug 2021 14:34:30 +0300 Subject: [PATCH 02/30] Add is_discount configurable and grouped products depends on children discounts. --- .../Indexer/Fulltext/Datasource/PriceData.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php index 3d27be509..f6a4797f0 100644 --- a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php +++ b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php @@ -1,10 +1,15 @@ + * @copyright 2020 Smile + * @license Open Software License ("OSL") v. 3.0 */ namespace Smile\ElasticsuiteCatalog\Model\Product\Indexer\Fulltext\Datasource; From 299fa57abee36594f7f03f722033cad568c4d424 Mon Sep 17 00:00:00 2001 From: Kostadin Bashev Date: Wed, 25 Aug 2021 14:40:29 +0300 Subject: [PATCH 03/30] code quality fixes. --- .../Model/Product/Indexer/Fulltext/Datasource/PriceData.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php index f6a4797f0..af22aa0c0 100644 --- a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php +++ b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php @@ -49,7 +49,7 @@ class PriceData implements DatasourceInterface /** * Constructor. * - * @param ProductRepository $productRepository + * @param ProductRepository $productRepository Product Repository * @param ResourceModel $resourceModel Resource model * @param PriceData\PriceDataReaderInterface[] $priceReaderPool Price modifiers pool. */ From 98a0d28520c2b6b1ab68d7f52e6c4cebe88b2ea8 Mon Sep 17 00:00:00 2001 From: Kostadin Bashev Date: Wed, 25 Aug 2021 14:50:29 +0300 Subject: [PATCH 04/30] code quality fixes. --- .../Indexer/Fulltext/Datasource/PriceData.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php index af22aa0c0..32b6fc850 100644 --- a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php +++ b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php @@ -49,18 +49,18 @@ class PriceData implements DatasourceInterface /** * Constructor. * - * @param ProductRepository $productRepository Product Repository - * @param ResourceModel $resourceModel Resource model - * @param PriceData\PriceDataReaderInterface[] $priceReaderPool Price modifiers pool. + * @param ProductRepository $productRepository Product Repository + * @param ResourceModel $resourceModel Resource model + * @param PriceData\PriceDataReaderInterface[] $priceReaderPool Price modifiers pool. */ public function __construct( ProductRepository $productRepository, ResourceModel $resourceModel, $priceReaderPool = [] ) { - $this->productRepository = $productRepository; - $this->resourceModel = $resourceModel; - $this->priceReaderPool = $priceReaderPool; + $this->productRepository = $productRepository; + $this->resourceModel = $resourceModel; + $this->priceReaderPool = $priceReaderPool; } /** @@ -96,8 +96,7 @@ public function addData($storeId, array $indexData) if (isset($children)) { foreach ($children as $child) { - if ($child->getPriceInfo()->getPrice(FinalPrice::PRICE_CODE)->getAmount()->getValue() - < $child->getPriceInfo()->getPrice(RegularPrice::PRICE_CODE)->getAmount()->getValue()) { + if ($child->getPriceInfo()->getPrice(FinalPrice::PRICE_CODE)->getAmount()->getValue() < $child->getPriceInfo()->getPrice(RegularPrice::PRICE_CODE)->getAmount()->getValue()) { $isDiscount = true; break; } From 4abbb48c16d30fc60b08d6b6cbbfa44de2a38040 Mon Sep 17 00:00:00 2001 From: Kostadin Bashev Date: Wed, 25 Aug 2021 15:04:11 +0300 Subject: [PATCH 05/30] code quality fixes. --- composer.json | 3 ++- .../Product/Indexer/Fulltext/Datasource/PriceData.php | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index b18af0dc2..078c464a3 100644 --- a/composer.json +++ b/composer.json @@ -45,7 +45,8 @@ "magento/module-inventory-sales": ">=1.1.0", "magento/module-inventory-indexer": ">=2.0.0", "magento/magento-composer-installer": "*", - "elasticsearch/elasticsearch": "~6.7|~7.2" + "elasticsearch/elasticsearch": "~6.7|~7.2", + "smile/magento2-smilelab-phpcs": "^2.0" }, "replace": { "smile/module-elasticsuite-core": "self.version", diff --git a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php index 32b6fc850..6526f74a7 100644 --- a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php +++ b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php @@ -49,9 +49,9 @@ class PriceData implements DatasourceInterface /** * Constructor. * - * @param ProductRepository $productRepository Product Repository - * @param ResourceModel $resourceModel Resource model - * @param PriceData\PriceDataReaderInterface[] $priceReaderPool Price modifiers pool. + * @param ProductRepository $productRepository Product Repository + * @param ResourceModel $resourceModel Resource model + * @param PriceData\PriceDataReaderInterface[] $priceReaderPool Price modifiers pool. */ public function __construct( ProductRepository $productRepository, @@ -96,7 +96,8 @@ public function addData($storeId, array $indexData) if (isset($children)) { foreach ($children as $child) { - if ($child->getPriceInfo()->getPrice(FinalPrice::PRICE_CODE)->getAmount()->getValue() < $child->getPriceInfo()->getPrice(RegularPrice::PRICE_CODE)->getAmount()->getValue()) { + if ($child->getPriceInfo()->getPrice(FinalPrice::PRICE_CODE)->getAmount()->getValue() < $child + ->getPriceInfo()->getPrice(RegularPrice::PRICE_CODE)->getAmount()->getValue()) { $isDiscount = true; break; } From 9b6fb8b11cbca00f10b76c50ce2da6b02c10b19e Mon Sep 17 00:00:00 2001 From: Kostadin Bashev Date: Wed, 25 Aug 2021 15:48:28 +0300 Subject: [PATCH 06/30] code quality fixes. --- .../Model/Product/Indexer/Fulltext/Datasource/PriceData.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php index 6526f74a7..700da05b5 100644 --- a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php +++ b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php @@ -68,6 +68,7 @@ public function __construct( * * {@inheritdoc} * @throws \Magento\Framework\Exception\NoSuchEntityException + * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function addData($storeId, array $indexData) { From 58d46a662180cc4e3cba28e6b127a59dabcb3697 Mon Sep 17 00:00:00 2001 From: Kostadin Bashev Date: Thu, 4 Aug 2022 18:44:30 +0300 Subject: [PATCH 07/30] optimize performance --- .../Indexer/Fulltext/Datasource/PriceData.php | 55 ++++++++----------- 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php index 700da05b5..54ce30122 100644 --- a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php +++ b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php @@ -14,13 +14,9 @@ namespace Smile\ElasticsuiteCatalog\Model\Product\Indexer\Fulltext\Datasource; -use Magento\Catalog\Model\ProductRepository; -use Magento\Catalog\Pricing\Price\FinalPrice; -use Magento\Catalog\Pricing\Price\RegularPrice; -use Magento\ConfigurableProduct\Model\Product\Type\Configurable; -use Magento\GroupedProduct\Model\Product\Type\Grouped; -use Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Indexer\Fulltext\Datasource\PriceData as ResourceModel; use Smile\ElasticsuiteCore\Api\Index\DatasourceInterface; +use Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Indexer\Fulltext\Datasource\PriceData as ResourceModel; +use Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Indexer\Fulltext\Datasource\AttributeData as AttributeResourceModel; /** * Datasource used to append prices data to product during indexing. @@ -41,26 +37,31 @@ class PriceData implements DatasourceInterface */ private $resourceModel; + /** + * @var \Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Indexer\Fulltext\Datasource\AttributeData + */ + private $attributeResourceModel; + /** * @var PriceData\PriceDataReaderInterface[] */ private $priceReaderPool = []; - /** * Constructor. * - * @param ProductRepository $productRepository Product Repository - * @param ResourceModel $resourceModel Resource model - * @param PriceData\PriceDataReaderInterface[] $priceReaderPool Price modifiers pool. + * @param ResourceModel $resourceModel Resource model + * @param AttributeResourceModel $resourceModel Attribute Resource model + * @param PriceData\PriceDataReaderInterface[] $priceReaderPool Price modifiers pool. */ public function __construct( ProductRepository $productRepository, ResourceModel $resourceModel, + AttributeResourceModel $attributeResourceModel, $priceReaderPool = [] ) { - $this->productRepository = $productRepository; - $this->resourceModel = $resourceModel; - $this->priceReaderPool = $priceReaderPool; + $this->resourceModel = $resourceModel; + $this->priceReaderPool = $priceReaderPool; + $this->attributeResourceModel = $attributeResourceModel; } /** @@ -72,7 +73,8 @@ public function __construct( */ public function addData($storeId, array $indexData) { - $priceData = $this->resourceModel->loadPriceData($storeId, array_keys($indexData)); + $productIds = array_keys($indexData); + $priceData = $this->resourceModel->loadPriceData($storeId, $productIds); foreach ($priceData as $priceDataRow) { $productId = (int) $priceDataRow['entity_id']; @@ -82,24 +84,14 @@ public function addData($storeId, array $indexData) $originalPrice = $priceModifier->getOriginalPrice($priceDataRow); $price = $priceModifier->getPrice($priceDataRow); - $isDiscount = $price < $originalPrice; - if (in_array($productTypeId, [Grouped::TYPE_CODE, Configurable::TYPE_CODE])) { - $product = $this->productRepository->getById($productId); - + $isDiscount = $price < $originalPrice; + if (in_array($productTypeId, $this->attributeResourceModel->getCompositeTypes())) { $isDiscount = false; - if ($productTypeId === Grouped::TYPE_CODE) { - $children = $product->getTypeInstance()->getAssociatedProducts($product); - } - - if ($productTypeId === Configurable::TYPE_CODE) { - $children = $product->getTypeInstance()->getUsedProducts($product); - } - - if (isset($children)) { - foreach ($children as $child) { - if ($child->getPriceInfo()->getPrice(FinalPrice::PRICE_CODE)->getAmount()->getValue() < $child - ->getPriceInfo()->getPrice(RegularPrice::PRICE_CODE)->getAmount()->getValue()) { - $isDiscount = true; + $allChildrenIds = $this->attributeResourceModel->loadChildrens($productIds, $storeId); + $childPriceData = $this->resourceModel->loadPriceData($storeId, array_keys($allChildrenIds)); + foreach ($childPriceData as $childPrice) { + if ($childPrice['customer_group_id'] == $priceDataRow['customer_group_id']) { + if ($isDiscount = ($childPrice['final_price'] < $childPrice['price'])) { break; } } @@ -130,7 +122,6 @@ public function addData($storeId, array $indexData) /** * Retur - * * @param string $typeId Product type id. * * @return PriceData\PriceDataReaderInterface From bdb071b46ced6c0ac12f94e2f6b6ea1fcc188ee1 Mon Sep 17 00:00:00 2001 From: Kostadin Bashev Date: Thu, 4 Aug 2022 18:58:08 +0300 Subject: [PATCH 08/30] optimize performance --- .../Model/Product/Indexer/Fulltext/Datasource/PriceData.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php index 54ce30122..b22568e35 100644 --- a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php +++ b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php @@ -54,7 +54,6 @@ class PriceData implements DatasourceInterface * @param PriceData\PriceDataReaderInterface[] $priceReaderPool Price modifiers pool. */ public function __construct( - ProductRepository $productRepository, ResourceModel $resourceModel, AttributeResourceModel $attributeResourceModel, $priceReaderPool = [] From 47f231a48f2004b0a4d52682c6fd3db4837ebe78 Mon Sep 17 00:00:00 2001 From: Kostadin Bashev Date: Thu, 4 Aug 2022 19:02:06 +0300 Subject: [PATCH 09/30] optimize performance phpcs --- .../Model/Product/Indexer/Fulltext/Datasource/PriceData.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php index b22568e35..d7c8cba72 100644 --- a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php +++ b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php @@ -49,9 +49,9 @@ class PriceData implements DatasourceInterface /** * Constructor. * - * @param ResourceModel $resourceModel Resource model - * @param AttributeResourceModel $resourceModel Attribute Resource model - * @param PriceData\PriceDataReaderInterface[] $priceReaderPool Price modifiers pool. + * @param ResourceModel $resourceModel Resource model + * @param AttributeResourceModel $attributeResourceModel Attribute Resource model + * @param PriceData\PriceDataReaderInterface[] $priceReaderPool Price modifiers pool. */ public function __construct( ResourceModel $resourceModel, From 7aa29e8067bfb6497a4e24183e10753de698677b Mon Sep 17 00:00:00 2001 From: Kostadin Bashev Date: Thu, 4 Aug 2022 19:05:11 +0300 Subject: [PATCH 10/30] optimize performance phpcs --- .../Model/Product/Indexer/Fulltext/Datasource/PriceData.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php index d7c8cba72..a3c3db86d 100644 --- a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php +++ b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php @@ -49,9 +49,9 @@ class PriceData implements DatasourceInterface /** * Constructor. * - * @param ResourceModel $resourceModel Resource model - * @param AttributeResourceModel $attributeResourceModel Attribute Resource model - * @param PriceData\PriceDataReaderInterface[] $priceReaderPool Price modifiers pool. + * @param ResourceModel $resourceModel Resource model + * @param AttributeResourceModel $attributeResourceModel Attribute Resource model + * @param PriceData\PriceDataReaderInterface[] $priceReaderPool Price modifiers pool. */ public function __construct( ResourceModel $resourceModel, From 1bc9ad00f59aeaaefe84cb38adfe0fffb52917b9 Mon Sep 17 00:00:00 2001 From: Kostadin Bashev Date: Thu, 4 Aug 2022 19:06:23 +0300 Subject: [PATCH 11/30] optimize performance phpcs --- .../Model/Product/Indexer/Fulltext/Datasource/PriceData.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php index a3c3db86d..bea94fc9b 100644 --- a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php +++ b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php @@ -67,8 +67,6 @@ public function __construct( * Add price data to the index data. * * {@inheritdoc} - * @throws \Magento\Framework\Exception\NoSuchEntityException - * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function addData($storeId, array $indexData) { From a09d5af5c11e23c933685bdb9f850dc95954a357 Mon Sep 17 00:00:00 2001 From: Kostadin Bashev Date: Thu, 4 Aug 2022 19:09:59 +0300 Subject: [PATCH 12/30] optimize performance phpmd --- .../Model/Product/Indexer/Fulltext/Datasource/PriceData.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php index bea94fc9b..31af5ce7c 100644 --- a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php +++ b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php @@ -27,11 +27,6 @@ */ class PriceData implements DatasourceInterface { - /** - * @var \Magento\Catalog\Model\ProductRepository - */ - private $productRepository; - /** * @var \Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Indexer\Fulltext\Datasource\PriceData */ From 14fcce8748fe780a8fa1a63751546d8132756570 Mon Sep 17 00:00:00 2001 From: Kostadin Bashev Date: Thu, 4 Aug 2022 19:26:59 +0300 Subject: [PATCH 13/30] add price modifier --- .../Model/Product/Indexer/Fulltext/Datasource/PriceData.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php index 31af5ce7c..26a6f3c5b 100644 --- a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php +++ b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php @@ -81,9 +81,11 @@ public function addData($storeId, array $indexData) $isDiscount = false; $allChildrenIds = $this->attributeResourceModel->loadChildrens($productIds, $storeId); $childPriceData = $this->resourceModel->loadPriceData($storeId, array_keys($allChildrenIds)); + $priceModifier = $this->getPriceDataReader('default'); foreach ($childPriceData as $childPrice) { if ($childPrice['customer_group_id'] == $priceDataRow['customer_group_id']) { - if ($isDiscount = ($childPrice['final_price'] < $childPrice['price'])) { + if ($priceModifier->getPrice($childPrice) < $priceModifier->getOriginalPrice($childPrice)) { + $isDiscount = true; break; } } From 586483c61870ae4ea2ad195991b6ddf72f7ef6f1 Mon Sep 17 00:00:00 2001 From: Kostadin Bashev Date: Wed, 2 Nov 2022 13:14:06 +0200 Subject: [PATCH 14/30] move child data loading outside of foreach. --- .../Product/Indexer/Fulltext/Datasource/PriceData.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php index 26a6f3c5b..149ef4131 100644 --- a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php +++ b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php @@ -67,6 +67,8 @@ public function addData($storeId, array $indexData) { $productIds = array_keys($indexData); $priceData = $this->resourceModel->loadPriceData($storeId, $productIds); + $allChildrenIds = $this->attributeResourceModel->loadChildrens($productIds, $storeId); + $childPriceData = $this->resourceModel->loadPriceData($storeId, array_keys($allChildrenIds)); foreach ($priceData as $priceDataRow) { $productId = (int) $priceDataRow['entity_id']; @@ -79,8 +81,6 @@ public function addData($storeId, array $indexData) $isDiscount = $price < $originalPrice; if (in_array($productTypeId, $this->attributeResourceModel->getCompositeTypes())) { $isDiscount = false; - $allChildrenIds = $this->attributeResourceModel->loadChildrens($productIds, $storeId); - $childPriceData = $this->resourceModel->loadPriceData($storeId, array_keys($allChildrenIds)); $priceModifier = $this->getPriceDataReader('default'); foreach ($childPriceData as $childPrice) { if ($childPrice['customer_group_id'] == $priceDataRow['customer_group_id']) { @@ -93,8 +93,8 @@ public function addData($storeId, array $indexData) } $indexData[$productId]['price'][] = [ - 'price' => (float) $price, - 'original_price' => (float) $originalPrice, + 'price' => $price, + 'original_price' => $originalPrice, 'is_discount' => $isDiscount, 'customer_group_id' => (int) $priceDataRow['customer_group_id'], 'tax_class_id' => (int) $priceDataRow['tax_class_id'], From 9848de2cbc0febed69cf0f9e18e16e5e00f8c535 Mon Sep 17 00:00:00 2001 From: Kostadin Bashev Date: Wed, 2 Nov 2022 13:54:12 +0200 Subject: [PATCH 15/30] revert --- .../Model/Product/Indexer/Fulltext/Datasource/PriceData.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php index 149ef4131..1ce8a3bcb 100644 --- a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php +++ b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php @@ -67,8 +67,6 @@ public function addData($storeId, array $indexData) { $productIds = array_keys($indexData); $priceData = $this->resourceModel->loadPriceData($storeId, $productIds); - $allChildrenIds = $this->attributeResourceModel->loadChildrens($productIds, $storeId); - $childPriceData = $this->resourceModel->loadPriceData($storeId, array_keys($allChildrenIds)); foreach ($priceData as $priceDataRow) { $productId = (int) $priceDataRow['entity_id']; @@ -82,6 +80,8 @@ public function addData($storeId, array $indexData) if (in_array($productTypeId, $this->attributeResourceModel->getCompositeTypes())) { $isDiscount = false; $priceModifier = $this->getPriceDataReader('default'); + $allChildrenIds = $this->attributeResourceModel->loadChildrens([$productId], $storeId); + $childPriceData = $this->resourceModel->loadPriceData($storeId, array_keys($allChildrenIds)); foreach ($childPriceData as $childPrice) { if ($childPrice['customer_group_id'] == $priceDataRow['customer_group_id']) { if ($priceModifier->getPrice($childPrice) < $priceModifier->getOriginalPrice($childPrice)) { From f05274b61534c8cc885cfbcf085778da27e4ac6d Mon Sep 17 00:00:00 2001 From: Kostadin Bashev Date: Thu, 1 Dec 2022 16:29:34 +0200 Subject: [PATCH 16/30] move loading data outside of foreach --- composer.json | 3 +-- .../Model/Product/Indexer/Fulltext/Datasource/PriceData.php | 5 +++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 078c464a3..b18af0dc2 100644 --- a/composer.json +++ b/composer.json @@ -45,8 +45,7 @@ "magento/module-inventory-sales": ">=1.1.0", "magento/module-inventory-indexer": ">=2.0.0", "magento/magento-composer-installer": "*", - "elasticsearch/elasticsearch": "~6.7|~7.2", - "smile/magento2-smilelab-phpcs": "^2.0" + "elasticsearch/elasticsearch": "~6.7|~7.2" }, "replace": { "smile/module-elasticsuite-core": "self.version", diff --git a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php index 1ce8a3bcb..d312df6d0 100644 --- a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php +++ b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php @@ -68,6 +68,9 @@ public function addData($storeId, array $indexData) $productIds = array_keys($indexData); $priceData = $this->resourceModel->loadPriceData($storeId, $productIds); + $allChildrenIds = $this->attributeResourceModel->loadChildrens($productIds, $storeId); + $childPriceData = $this->resourceModel->loadPriceData($storeId, array_keys($allChildrenIds)); + foreach ($priceData as $priceDataRow) { $productId = (int) $priceDataRow['entity_id']; $productTypeId = $indexData[$productId]['type_id']; @@ -80,8 +83,6 @@ public function addData($storeId, array $indexData) if (in_array($productTypeId, $this->attributeResourceModel->getCompositeTypes())) { $isDiscount = false; $priceModifier = $this->getPriceDataReader('default'); - $allChildrenIds = $this->attributeResourceModel->loadChildrens([$productId], $storeId); - $childPriceData = $this->resourceModel->loadPriceData($storeId, array_keys($allChildrenIds)); foreach ($childPriceData as $childPrice) { if ($childPrice['customer_group_id'] == $priceDataRow['customer_group_id']) { if ($priceModifier->getPrice($childPrice) < $priceModifier->getOriginalPrice($childPrice)) { From 1e85e0a1ec1ce1aab2d5847bd4184ce7087d2fd1 Mon Sep 17 00:00:00 2001 From: Romain Ruaud Date: Wed, 1 Feb 2023 18:05:18 +0100 Subject: [PATCH 17/30] Adding support of extended_bounds for date_histogram --- .../Aggregation/Builder/DateHistogram.php | 4 +++ .../Aggregation/Bucket/DateHistogram.php | 27 +++++++------- .../Request/Aggregation/Bucket/Histogram.php | 35 +++++++++++++------ 3 files changed, 43 insertions(+), 23 deletions(-) diff --git a/src/module-elasticsuite-core/Search/Adapter/Elasticsuite/Request/Aggregation/Builder/DateHistogram.php b/src/module-elasticsuite-core/Search/Adapter/Elasticsuite/Request/Aggregation/Builder/DateHistogram.php index bbe999ac9..49e8f9817 100644 --- a/src/module-elasticsuite-core/Search/Adapter/Elasticsuite/Request/Aggregation/Builder/DateHistogram.php +++ b/src/module-elasticsuite-core/Search/Adapter/Elasticsuite/Request/Aggregation/Builder/DateHistogram.php @@ -45,6 +45,10 @@ public function buildBucket(BucketInterface $bucket) 'min_doc_count' => $bucket->getMinDocCount(), ]; + if (!empty($bucket->getExtendedBounds())) { + $aggParams['extended_bounds'] = $bucket->getExtendedBounds(); + } + return ['date_histogram' => $aggParams]; } } diff --git a/src/module-elasticsuite-core/Search/Request/Aggregation/Bucket/DateHistogram.php b/src/module-elasticsuite-core/Search/Request/Aggregation/Bucket/DateHistogram.php index d695c5bb9..b4dc4f99b 100644 --- a/src/module-elasticsuite-core/Search/Request/Aggregation/Bucket/DateHistogram.php +++ b/src/module-elasticsuite-core/Search/Request/Aggregation/Bucket/DateHistogram.php @@ -33,16 +33,17 @@ class DateHistogram extends Histogram * * @SuppressWarnings(PHPMD.ExcessiveParameterList) * - * @param string $name Bucket name. - * @param string $field Bucket field. - * @param MetricInterface[] $metrics Bucket metrics. - * @param BucketInterface[] $childBuckets Child buckets. - * @param PipelineInterface[] $pipelines Bucket pipelines. - * @param string $nestedPath Nested path for nested bucket. - * @param QueryInterface $filter Bucket filter. - * @param QueryInterface $nestedFilter Nested filter for the bucket. - * @param integer $interval Histogram interval. - * @param integer $minDocCount Histogram min doc count. + * @param string $name Bucket name. + * @param string $field Bucket field. + * @param MetricInterface[] $metrics Bucket metrics. + * @param BucketInterface[] $childBuckets Child buckets. + * @param PipelineInterface[] $pipelines Bucket pipelines. + * @param string $nestedPath Nested path for nested bucket. + * @param QueryInterface $filter Bucket filter. + * @param QueryInterface $nestedFilter Nested filter for the bucket. + * @param integer $interval Histogram interval. + * @param integer $minDocCount Histogram min doc count. + * @param array $extendedBounds Histogram extended bounds. */ public function __construct( $name, @@ -54,7 +55,8 @@ public function __construct( QueryInterface $filter = null, QueryInterface $nestedFilter = null, $interval = "1d", - $minDocCount = 0 + $minDocCount = 0, + $extendedBounds = [] ) { parent::__construct( $name, @@ -66,7 +68,8 @@ public function __construct( $filter, $nestedFilter, $interval, - $minDocCount + $minDocCount, + $extendedBounds ); } diff --git a/src/module-elasticsuite-core/Search/Request/Aggregation/Bucket/Histogram.php b/src/module-elasticsuite-core/Search/Request/Aggregation/Bucket/Histogram.php index f8722c36d..687951b27 100644 --- a/src/module-elasticsuite-core/Search/Request/Aggregation/Bucket/Histogram.php +++ b/src/module-elasticsuite-core/Search/Request/Aggregation/Bucket/Histogram.php @@ -43,16 +43,17 @@ class Histogram extends AbstractBucket * * @SuppressWarnings(PHPMD.ExcessiveParameterList) * - * @param string $name Bucket name. - * @param string $field Bucket field. - * @param MetricInterface[] $metrics Bucket metrics. - * @param BucketInterface[] $childBuckets Child buckets. - * @param PipelineInterface[] $pipelines Bucket pipelines. - * @param string $nestedPath Nested path for nested bucket. - * @param QueryInterface $filter Bucket filter. - * @param QueryInterface $nestedFilter Nested filter for the bucket. - * @param integer $interval Histogram interval. - * @param integer $minDocCount Histogram min doc count. + * @param string $name Bucket name. + * @param string $field Bucket field. + * @param MetricInterface[] $metrics Bucket metrics. + * @param BucketInterface[] $childBuckets Child buckets. + * @param PipelineInterface[] $pipelines Bucket pipelines. + * @param string $nestedPath Nested path for nested bucket. + * @param QueryInterface $filter Bucket filter. + * @param QueryInterface $nestedFilter Nested filter for the bucket. + * @param integer $interval Histogram interval. + * @param integer $minDocCount Histogram min doc count. + * @param array $extendedBounds Histogram extended bounds. */ public function __construct( $name, @@ -64,11 +65,13 @@ public function __construct( QueryInterface $filter = null, QueryInterface $nestedFilter = null, $interval = 1, - $minDocCount = 0 + $minDocCount = 0, + $extendedBounds = [] ) { parent::__construct($name, $field, $metrics, $childBuckets, $pipelines, $nestedPath, $filter, $nestedFilter); $this->interval = $interval; $this->minDocCount = $minDocCount; + $this->extendedBounds = $extendedBounds; } /** @@ -98,4 +101,14 @@ public function getMinDocCount() { return $this->minDocCount; } + + /** + * Get histogram extended bounds. + * + * @return array + */ + public function getExtendedBounds() + { + return $this->extendedBounds; + } } From 4fa37f61918adb8617ee3e61d275c3ae429484f4 Mon Sep 17 00:00:00 2001 From: Romain Ruaud Date: Fri, 3 Feb 2023 11:52:39 +0100 Subject: [PATCH 18/30] Change beta version to 2.4.6-beta2 and add PHP 8.2 tests --- .github/workflows/20-integration.yml | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/.github/workflows/20-integration.yml b/.github/workflows/20-integration.yml index 9272c1240..077085767 100644 --- a/.github/workflows/20-integration.yml +++ b/.github/workflows/20-integration.yml @@ -61,16 +61,24 @@ jobs: - php-versions: '8.1' magento-versions: '2.4.5-p1' magento-editions: 'enterprise' - experimental: true + experimental: true - php-versions: '8.1' - magento-versions: '2.4.6-beta1' + magento-versions: '2.4.6-beta2' magento-editions: 'community' experimental: true - php-versions: '8.1' - magento-versions: '2.4.6-beta1' + magento-versions: '2.4.6-beta2' magento-editions: 'enterprise' - experimental: true - + experimental: true + - php-versions: '8.2' + magento-versions: '2.4.6-beta2' + magento-editions: 'community' + experimental: true + - php-versions: '8.2' + magento-versions: '2.4.6-beta2' + magento-editions: 'enterprise' + experimental: true + continue-on-error: ${{ matrix.experimental }} env: From f5f4503e96478dca90dc76535e2962174d034a78 Mon Sep 17 00:00:00 2001 From: Pierre Gauthier Date: Mon, 6 Feb 2023 10:24:31 +0100 Subject: [PATCH 19/30] Filter boost and use search merchandising in autocomplete --- .../Autocomplete/Product/DataProvider.php | 23 +++++++++++++++- .../Block/Variables/Page/Search.php | 26 ++++++++++++++----- .../etc/elasticsuite_indices.xml | 23 ++++++++-------- 3 files changed, 53 insertions(+), 19 deletions(-) diff --git a/src/module-elasticsuite-catalog/Model/Autocomplete/Product/DataProvider.php b/src/module-elasticsuite-catalog/Model/Autocomplete/Product/DataProvider.php index fdb15dc6c..92ae5bf79 100644 --- a/src/module-elasticsuite-catalog/Model/Autocomplete/Product/DataProvider.php +++ b/src/module-elasticsuite-catalog/Model/Autocomplete/Product/DataProvider.php @@ -13,9 +13,10 @@ */ namespace Smile\ElasticsuiteCatalog\Model\Autocomplete\Product; -use Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Fulltext\Collection as ProductCollection; use Magento\Search\Model\Autocomplete\DataProviderInterface; use Smile\ElasticsuiteCatalog\Helper\Autocomplete as ConfigurationHelper; +use Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Fulltext\Collection as ProductCollection; +use Smile\ElasticsuiteCore\Api\Search\ContextInterface; /** * Catalog product autocomplete data provider. @@ -53,22 +54,30 @@ class DataProvider implements DataProviderInterface */ private $productCollection; + /** + * @var ContextInterface + */ + private $searchContext; + /** * Constructor. * * @param ItemFactory $itemFactory Suggest item factory. * @param Collection\Provider $productCollectionProvider Product collection provider. * @param ConfigurationHelper $configurationHelper Autocomplete configuration helper. + * @param ContextInterface $searchContext Query search context. * @param string $type Autocomplete provider type. */ public function __construct( ItemFactory $itemFactory, Collection\Provider $productCollectionProvider, ConfigurationHelper $configurationHelper, + ContextInterface $searchContext, $type = self::AUTOCOMPLETE_TYPE ) { $this->itemFactory = $itemFactory; $this->configurationHelper = $configurationHelper; + $this->searchContext = $searchContext; $this->type = $type; $this->productCollection = $this->prepareProductCollection($productCollectionProvider->getProductCollection()); } @@ -107,6 +116,18 @@ public function getItems() private function prepareProductCollection(ProductCollection $productCollection) { $productCollection->setPageSize($this->getResultsPageSize()); + $productCollection->setOrder('relevance', \Magento\Framework\Data\Collection::SORT_ORDER_ASC); + + if ($searchQuery = $this->searchContext->getCurrentSearchQuery()) { + if ($searchQuery->getId()) { + $productCollection->addSortFilterParameters( + 'relevance', + 'search_query.position', + 'search_query', + ['search_query.query_id' => $searchQuery->getId()] + ); + } + } return $productCollection; } diff --git a/src/module-elasticsuite-tracker/Block/Variables/Page/Search.php b/src/module-elasticsuite-tracker/Block/Variables/Page/Search.php index 0738c3d23..74d349ea1 100644 --- a/src/module-elasticsuite-tracker/Block/Variables/Page/Search.php +++ b/src/module-elasticsuite-tracker/Block/Variables/Page/Search.php @@ -38,16 +38,22 @@ class Search extends \Smile\ElasticsuiteTracker\Block\Variables\Page\AbstractBlo */ private $catalogSearchData; + /** + * @var \Smile\ElasticsuiteCore\Api\Search\ContextInterface + */ + private $searchContext; + /** * Set the default template for page variable blocks * - * @param Template\Context $context The template context - * @param \Magento\Framework\Json\Helper\Data $jsonHelper The Magento's JSON Helper - * @param \Smile\ElasticsuiteTracker\Helper\Data $trackerHelper The Smile Tracker helper - * @param \Magento\Framework\Registry $registry Magento Core Registry - * @param \Magento\Catalog\Model\Layer\Resolver $layerResolver The Magento layer resolver - * @param \Magento\CatalogSearch\Helper\Data $catalogSearchData The Catalogsearch data - * @param array $data The block data + * @param Template\Context $context The template context + * @param \Magento\Framework\Json\Helper\Data $jsonHelper The Magento's JSON Helper + * @param \Smile\ElasticsuiteTracker\Helper\Data $trackerHelper The Smile Tracker helper + * @param \Magento\Framework\Registry $registry Magento Core Registry + * @param \Magento\Catalog\Model\Layer\Resolver $layerResolver The Magento layer resolver + * @param \Magento\CatalogSearch\Helper\Data $catalogSearchData The Catalogsearch data + * @param \Smile\ElasticsuiteCore\Api\Search\ContextInterface $searchContext The search context + * @param array $data The block data */ public function __construct( Template\Context $context, @@ -56,10 +62,12 @@ public function __construct( \Magento\Framework\Registry $registry, \Magento\Catalog\Model\Layer\Resolver $layerResolver, \Magento\CatalogSearch\Helper\Data $catalogSearchData, + \Smile\ElasticsuiteCore\Api\Search\ContextInterface $searchContext, array $data = [] ) { $this->catalogLayer = $layerResolver->get(); $this->catalogSearchData = $catalogSearchData; + $this->searchContext = $searchContext; parent::__construct($context, $jsonHelper, $trackerHelper, $registry, $data); } @@ -72,6 +80,10 @@ public function getVariables() { $variables = ['search.query' => $this->catalogSearchData->getEscapedQueryText()]; + if ($searchQuery = $this->searchContext->getCurrentSearchQuery()) { + $variables['search.query_id'] = (int) $searchQuery->getQueryId(); + } + if ($layer = $this->catalogLayer) { $productCollection = $layer->getProductCollection(); $variables['search.is_spellchecked'] = (int) $productCollection->isSpellchecked(); diff --git a/src/module-elasticsuite-tracker/etc/elasticsuite_indices.xml b/src/module-elasticsuite-tracker/etc/elasticsuite_indices.xml index 15d363fab..0a92510e7 100644 --- a/src/module-elasticsuite-tracker/etc/elasticsuite_indices.xml +++ b/src/module-elasticsuite-tracker/etc/elasticsuite_indices.xml @@ -34,19 +34,19 @@ - + - + - + - + @@ -56,7 +56,7 @@ true - + @@ -66,14 +66,15 @@ - + true true + - + true @@ -81,7 +82,7 @@ true - + @@ -97,17 +98,17 @@ - + - + - + From 84269993adaf93d6f58bcc70420af0d9e8e34b0b Mon Sep 17 00:00:00 2001 From: Vadym Honcharuk Date: Wed, 8 Feb 2023 12:59:56 +0200 Subject: [PATCH 20/30] Fixing the maximum width of the index select dropdown --- .../view/adminhtml/web/css/es-analysis.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/module-elasticsuite-indices/view/adminhtml/web/css/es-analysis.css b/src/module-elasticsuite-indices/view/adminhtml/web/css/es-analysis.css index d7e080a9c..66da7508e 100644 --- a/src/module-elasticsuite-indices/view/adminhtml/web/css/es-analysis.css +++ b/src/module-elasticsuite-indices/view/adminhtml/web/css/es-analysis.css @@ -30,6 +30,10 @@ text-align: right; } +#admin__es-index-select { + max-width: 417px; +} + #admin__es-analyzer-select { padding-right: 0; width: 130px; From 8565dc446d74b852cb87d207151a80a45882abc6 Mon Sep 17 00:00:00 2001 From: Pierre Gauthier Date: Thu, 9 Feb 2023 15:20:58 +0100 Subject: [PATCH 21/30] [Optimizer] #1197602 - Sort by boost weight in admin grid --- .../Optimizer/Listing/DataProvider.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/module-elasticsuite-catalog-optimizer/Ui/Component/Optimizer/Listing/DataProvider.php b/src/module-elasticsuite-catalog-optimizer/Ui/Component/Optimizer/Listing/DataProvider.php index 5d8e86f5c..70d593bfd 100644 --- a/src/module-elasticsuite-catalog-optimizer/Ui/Component/Optimizer/Listing/DataProvider.php +++ b/src/module-elasticsuite-catalog-optimizer/Ui/Component/Optimizer/Listing/DataProvider.php @@ -13,8 +13,10 @@ */ namespace Smile\ElasticsuiteCatalogOptimizer\Ui\Component\Optimizer\Listing; +use Magento\Framework\Data\Collection; use Magento\Ui\DataProvider\AbstractDataProvider; use Smile\ElasticsuiteCatalogOptimizer\Model\ResourceModel\Optimizer\CollectionFactory; +use Zend_Db_Expr; /** * Data Provider for UI components based on Sellers @@ -107,4 +109,26 @@ public function addFilter(\Magento\Framework\Api\Filter $filter) } parent::addFilter($filter); } + + /** + * {@inheritdoc} + */ + public function addOrder($field, $direction) + { + // Add custom behavior for boost_weight sorting. + if ($field == 'boost_weight') { + // Put optimizer without boost weight at the end of the list. + parent::addOrder('model', Collection::SORT_ORDER_DESC); + + // Extract boost weight value from config field. + parent::addOrder( + new Zend_Db_Expr("SUBSTRING_INDEX(SUBSTRING_INDEX(config, 'constant_score_value\":\"', -1), '\"', 1)"), + $direction + ); + + return; + } + + parent::addOrder($field, $direction); + } } From ee580e2d92868e55683cd8cb155d68ccac76b2b4 Mon Sep 17 00:00:00 2001 From: Romain Ruaud Date: Fri, 10 Feb 2023 12:47:43 +0100 Subject: [PATCH 22/30] Ensure casting of query_id for already existing indices. --- .../Model/Event/Processor/Search.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/module-elasticsuite-tracker/Model/Event/Processor/Search.php b/src/module-elasticsuite-tracker/Model/Event/Processor/Search.php index 5becb7ce2..ffbc2b896 100644 --- a/src/module-elasticsuite-tracker/Model/Event/Processor/Search.php +++ b/src/module-elasticsuite-tracker/Model/Event/Processor/Search.php @@ -34,6 +34,13 @@ public function process($eventData) $eventData['page']['search']['is_spellchecked'] = (bool) $eventData['page']['search']['is_spellchecked']; } + // The query_id is an "integer" in the XML mapping, but if the index already exists, it will guess the mapping. + // So we need to cast as integer for the "first insert on an already existing index". + // Otherwise it would be mapped as a string and might cause failures when aggregating on this field. + if (isset($eventData['page']['search']['query_id'])) { + $eventData['page']['search']['query_id'] = (int) $eventData['page']['search']['query_id']; + } + return $eventData; } } From 1c8e1d7137e263b412efe808aef936f18df0f05a Mon Sep 17 00:00:00 2001 From: Pierre Gauthier Date: Fri, 10 Feb 2023 15:30:16 +0100 Subject: [PATCH 23/30] [Search Merchandizing] #1196125 - Set search query to load optimizers --- .../Adminhtml/Term/Merchandiser/Load.php | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/module-elasticsuite-catalog/Controller/Adminhtml/Term/Merchandiser/Load.php b/src/module-elasticsuite-catalog/Controller/Adminhtml/Term/Merchandiser/Load.php index dee64d75b..921298e64 100644 --- a/src/module-elasticsuite-catalog/Controller/Adminhtml/Term/Merchandiser/Load.php +++ b/src/module-elasticsuite-catalog/Controller/Adminhtml/Term/Merchandiser/Load.php @@ -18,6 +18,7 @@ use Magento\Search\Controller\Adminhtml\Term; use Magento\Search\Model\QueryFactory; use Smile\ElasticsuiteCatalog\Model\Search\PreviewFactory; +use Smile\ElasticsuiteCore\Api\Search\ContextInterface; /** * Search term merchandiser preview load controller. @@ -43,24 +44,32 @@ class Load extends Term */ private $previewFactory; + /** + * @var ContextInterface + */ + private $searchContext; + /** * Constructor. * - * @param Context $context Controller context. - * @param QueryFactory $queryFactory Search query factory. - * @param Data $jsonHelper Json Helper. - * @param PreviewFactory $previewFactory Preview factory. + * @param Context $context Controller context. + * @param QueryFactory $queryFactory Search query factory. + * @param Data $jsonHelper Json Helper. + * @param PreviewFactory $previewFactory Preview factory. + * @param ContextInterface $searchContext Search context. */ public function __construct( - Context $context, - \Magento\Search\Model\QueryFactory $queryFactory, - Data $jsonHelper, - PreviewFactory $previewFactory + Context $context, + QueryFactory $queryFactory, + Data $jsonHelper, + PreviewFactory $previewFactory, + ContextInterface $searchContext ) { parent::__construct($context); $this->queryFactory = $queryFactory; $this->jsonHelper = $jsonHelper; $this->previewFactory = $previewFactory; + $this->searchContext = $searchContext; } /** @@ -77,6 +86,7 @@ public function execute() $responseData = ['products' => [], 'size' => 0]; if ($query->getId()) { + $this->searchContext->setCurrentSearchQuery($query); $productPositions = $this->getRequest()->getParam('product_position', []); $query->setSortedProductIds(array_keys($productPositions)); From 164c13dd1a9d445f956ba61f47a5b96fc39afdcb Mon Sep 17 00:00:00 2001 From: "tuomas.anakkala tuomas.anakkala@vaimo.com" Date: Sat, 11 Feb 2023 12:50:04 +0200 Subject: [PATCH 24/30] Prevent adding null queryFilters --- .../Plugin/Widget/ProductsListPlugin.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/module-elasticsuite-virtual-category/Plugin/Widget/ProductsListPlugin.php b/src/module-elasticsuite-virtual-category/Plugin/Widget/ProductsListPlugin.php index 6afddf5ff..74f4bb5bb 100644 --- a/src/module-elasticsuite-virtual-category/Plugin/Widget/ProductsListPlugin.php +++ b/src/module-elasticsuite-virtual-category/Plugin/Widget/ProductsListPlugin.php @@ -161,7 +161,10 @@ public function afterCreateCollection(ProductsList $subject, $collection) foreach ($categoryIds as $categoryId) { try { $category = $this->categoryRepository->get($categoryId, $storeId); - $filterQueries[] = $this->filterProvider->getQueryFilter($category); + $queryFilter = $this->filterProvider->getQueryFilter($category); + if ($queryFilter !== null) { + $filterQueries[] = $queryFilter; + } } catch (NoSuchEntityException $exception) { continue; } From b79748ff19acac7ddbe5d500c8d307f87cc597bc Mon Sep 17 00:00:00 2001 From: prog08 <64687729+prog08@users.noreply.github.com> Date: Fri, 17 Feb 2023 12:41:24 +0200 Subject: [PATCH 25/30] fix: typo in variable name --- .../Model/ResourceModel/Product/Fulltext/Collection.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/module-elasticsuite-catalog/Model/ResourceModel/Product/Fulltext/Collection.php b/src/module-elasticsuite-catalog/Model/ResourceModel/Product/Fulltext/Collection.php index b59287bab..08c083e6b 100644 --- a/src/module-elasticsuite-catalog/Model/ResourceModel/Product/Fulltext/Collection.php +++ b/src/module-elasticsuite-catalog/Model/ResourceModel/Product/Fulltext/Collection.php @@ -704,13 +704,13 @@ private function prepareSortOrders() { $sortOrders = []; - $useProductuctLimitation = isset($this->_productLimitationFilters['sortParams']); + $useProductLimitation = isset($this->_productLimitationFilters['sortParams']); foreach ($this->_orders as $attribute => $direction) { $sortParams = ['direction' => $direction]; $sortField = $this->mapFieldName($attribute); - if ($useProductuctLimitation && isset($this->_productLimitationFilters['sortParams'][$attribute])) { + if ($useProductLimitation && isset($this->_productLimitationFilters['sortParams'][$attribute])) { $sortField = $this->_productLimitationFilters['sortParams'][$attribute]['sortField']; $sortParams = array_merge($sortParams, $this->_productLimitationFilters['sortParams'][$attribute]); } elseif ($attribute == 'price') { From 3d85edacff315cfa4313854e72201e74dd3d0996 Mon Sep 17 00:00:00 2001 From: Romain Ruaud Date: Tue, 21 Feb 2023 16:44:30 +0100 Subject: [PATCH 26/30] Update Ubuntu build version. --- .github/workflows/01-quality.yml | 4 ++-- .github/workflows/20-integration.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/01-quality.yml b/.github/workflows/01-quality.yml index 0a1bc26eb..92ffa722e 100644 --- a/.github/workflows/01-quality.yml +++ b/.github/workflows/01-quality.yml @@ -13,7 +13,7 @@ on: jobs: qualit: name: Code Quality - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 strategy: matrix: php-versions: ['7.4'] @@ -35,7 +35,7 @@ jobs: - name: "Downgrade Composer" run: composer self-update 2.1.14 - + - name: Validate composer.json and composer.lock run: composer validate diff --git a/.github/workflows/20-integration.yml b/.github/workflows/20-integration.yml index 077085767..7c5381af9 100644 --- a/.github/workflows/20-integration.yml +++ b/.github/workflows/20-integration.yml @@ -13,7 +13,7 @@ on: jobs: build: if: (github.event_name != 'pull_request') || contains(github.event.pull_request.labels.*.name, 'safe to test') - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 name: 'Integration' services: mysql: @@ -78,7 +78,7 @@ jobs: magento-versions: '2.4.6-beta2' magento-editions: 'enterprise' experimental: true - + continue-on-error: ${{ matrix.experimental }} env: From afa9369554c6d5eb305f5c3b52ac437d812d4fbf Mon Sep 17 00:00:00 2001 From: Romain Ruaud Date: Tue, 21 Feb 2023 17:59:12 +0100 Subject: [PATCH 27/30] Remove 2.4.6 beta from 2.10.x build. --- .github/workflows/20-integration.yml | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/.github/workflows/20-integration.yml b/.github/workflows/20-integration.yml index 7c5381af9..44c85d453 100644 --- a/.github/workflows/20-integration.yml +++ b/.github/workflows/20-integration.yml @@ -62,22 +62,6 @@ jobs: magento-versions: '2.4.5-p1' magento-editions: 'enterprise' experimental: true - - php-versions: '8.1' - magento-versions: '2.4.6-beta2' - magento-editions: 'community' - experimental: true - - php-versions: '8.1' - magento-versions: '2.4.6-beta2' - magento-editions: 'enterprise' - experimental: true - - php-versions: '8.2' - magento-versions: '2.4.6-beta2' - magento-editions: 'community' - experimental: true - - php-versions: '8.2' - magento-versions: '2.4.6-beta2' - magento-editions: 'enterprise' - experimental: true continue-on-error: ${{ matrix.experimental }} From f22680c6da88d88c5abd082ee48a6c0a35abc812 Mon Sep 17 00:00:00 2001 From: Romain Ruaud Date: Wed, 22 Feb 2023 11:32:49 +0100 Subject: [PATCH 28/30] Allow targeting child products when computing discount. --- .../Indexer/Fulltext/Datasource/PriceData.php | 71 +++++++++++++++---- .../etc/adminhtml/system.xml | 5 ++ .../etc/config.xml | 1 + .../i18n/en_US.csv | 2 + .../i18n/fr_FR.csv | 2 + 5 files changed, 67 insertions(+), 14 deletions(-) diff --git a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php index d312df6d0..c7ca34bf3 100644 --- a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php +++ b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php @@ -14,6 +14,9 @@ namespace Smile\ElasticsuiteCatalog\Model\Product\Indexer\Fulltext\Datasource; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\App\ObjectManager; +use Magento\Store\Model\ScopeInterface; use Smile\ElasticsuiteCore\Api\Index\DatasourceInterface; use Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Indexer\Fulltext\Datasource\PriceData as ResourceModel; use Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Indexer\Fulltext\Datasource\AttributeData as AttributeResourceModel; @@ -27,6 +30,9 @@ */ class PriceData implements DatasourceInterface { + /** @var string */ + private const XML_PATH_COMPUTE_CHILD_PRODUCT_DISCOUNT = 'smile_elasticsuite_catalogsearch_settings/catalogsearch/compute_child_product_discount'; + /** * @var \Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Indexer\Fulltext\Datasource\PriceData */ @@ -37,10 +43,23 @@ class PriceData implements DatasourceInterface */ private $attributeResourceModel; + /** + * Scope configuration + * + * @var ScopeConfigInterface + */ + private $scopeConfig; + /** * @var PriceData\PriceDataReaderInterface[] */ private $priceReaderPool = []; + + /** + * @var boolean + */ + private $isComputeChildDiscountEnabled; + /** * Constructor. * @@ -51,11 +70,13 @@ class PriceData implements DatasourceInterface public function __construct( ResourceModel $resourceModel, AttributeResourceModel $attributeResourceModel, - $priceReaderPool = [] + $priceReaderPool = [], + ScopeConfigInterface $scopeConfig = null ) { $this->resourceModel = $resourceModel; $this->priceReaderPool = $priceReaderPool; $this->attributeResourceModel = $attributeResourceModel; + $this->scopeConfig = $scopeConfig ?: ObjectManager::getInstance()->get(ScopeConfigInterface::class); } /** @@ -66,10 +87,12 @@ public function __construct( public function addData($storeId, array $indexData) { $productIds = array_keys($indexData); - $priceData = $this->resourceModel->loadPriceData($storeId, $productIds); + $priceData = $this->resourceModel->loadPriceData($storeId, $productIds); - $allChildrenIds = $this->attributeResourceModel->loadChildrens($productIds, $storeId); - $childPriceData = $this->resourceModel->loadPriceData($storeId, array_keys($allChildrenIds)); + if ($this->isComputeChildDiscountEnabled()) { + $allChildrenIds = $this->attributeResourceModel->loadChildrens($productIds, $storeId); + $childPriceData = $this->resourceModel->loadPriceData($storeId, array_keys($allChildrenIds)); + } foreach ($priceData as $priceDataRow) { $productId = (int) $priceDataRow['entity_id']; @@ -80,22 +103,25 @@ public function addData($storeId, array $indexData) $price = $priceModifier->getPrice($priceDataRow); $isDiscount = $price < $originalPrice; - if (in_array($productTypeId, $this->attributeResourceModel->getCompositeTypes())) { - $isDiscount = false; - $priceModifier = $this->getPriceDataReader('default'); - foreach ($childPriceData as $childPrice) { - if ($childPrice['customer_group_id'] == $priceDataRow['customer_group_id']) { - if ($priceModifier->getPrice($childPrice) < $priceModifier->getOriginalPrice($childPrice)) { - $isDiscount = true; - break; + + if ($this->isComputeChildDiscountEnabled()) { + if (in_array($productTypeId, $this->attributeResourceModel->getCompositeTypes())) { + $isDiscount = false; + $priceModifier = $this->getPriceDataReader('default'); + foreach ($childPriceData as $childPrice) { + if ($childPrice['customer_group_id'] == $priceDataRow['customer_group_id']) { + if ($priceModifier->getPrice($childPrice) < $priceModifier->getOriginalPrice($childPrice)) { + $isDiscount = true; + break; + } } } } } $indexData[$productId]['price'][] = [ - 'price' => $price, - 'original_price' => $originalPrice, + 'price' => (float) $price, + 'original_price' => (float) $originalPrice, 'is_discount' => $isDiscount, 'customer_group_id' => (int) $priceDataRow['customer_group_id'], 'tax_class_id' => (int) $priceDataRow['tax_class_id'], @@ -131,4 +157,21 @@ private function getPriceDataReader($typeId) return $priceModifier; } + + /** + * Is computing child product discount enabled. + * + * @return bool + */ + private function isComputeChildDiscountEnabled(): bool + { + if (!isset($this->isIndexingChildProductSkuEnabled)) { + $this->isComputeChildDiscountEnabled = (bool) $this->scopeConfig->getValue( + self::XML_PATH_COMPUTE_CHILD_PRODUCT_DISCOUNT, + ScopeInterface::SCOPE_STORE + ); + } + + return $this->isComputeChildDiscountEnabled; + } } diff --git a/src/module-elasticsuite-catalog/etc/adminhtml/system.xml b/src/module-elasticsuite-catalog/etc/adminhtml/system.xml index 97292f68f..1a1fd2b7a 100644 --- a/src/module-elasticsuite-catalog/etc/adminhtml/system.xml +++ b/src/module-elasticsuite-catalog/etc/adminhtml/system.xml @@ -80,6 +80,11 @@ Magento\Config\Model\Config\Source\Yesno + + + Magento\Config\Model\Config\Source\Yesno + + diff --git a/src/module-elasticsuite-catalog/etc/config.xml b/src/module-elasticsuite-catalog/etc/config.xml index 5e47ba2c5..74424e032 100644 --- a/src/module-elasticsuite-catalog/etc/config.xml +++ b/src/module-elasticsuite-catalog/etc/config.xml @@ -39,6 +39,7 @@ 3 0 0 + 0 diff --git a/src/module-elasticsuite-catalog/i18n/en_US.csv b/src/module-elasticsuite-catalog/i18n/en_US.csv index 83d1b4b9d..f08769195 100755 --- a/src/module-elasticsuite-catalog/i18n/en_US.csv +++ b/src/module-elasticsuite-catalog/i18n/en_US.csv @@ -117,3 +117,5 @@ Attributes,Attributes "If the category can be displayed in autocomplete results.","If the category can be displayed in autocomplete results." "Enable indexing child product SKU in dedicated subfield","Enable indexing child product SKU in dedicated subfield" "If enabled, child products SKUs of composite products will be indexed in a separate field and the ""sku"" field will only contain the parent product sku.","If enabled, child products SKUs of composite products will be indexed in a separate field and the ""sku"" field will only contain the parent product sku." +"Enable indexing discount on child products","Enable indexing discount on child products" +"Enable this if your catalog contains configurable products that are having childrens with different prices that could have separated discounts.","Enable this if your catalog contains configurable products that are having childrens with different prices that could have separated discounts." diff --git a/src/module-elasticsuite-catalog/i18n/fr_FR.csv b/src/module-elasticsuite-catalog/i18n/fr_FR.csv index b204eb3c9..6ee7356f5 100755 --- a/src/module-elasticsuite-catalog/i18n/fr_FR.csv +++ b/src/module-elasticsuite-catalog/i18n/fr_FR.csv @@ -117,3 +117,5 @@ Attributes,Attributs "If the category can be displayed in autocomplete results.","Si activé, la catégorie pourra être affichée dans les résultats de l'autocomplétion" "Enable indexing child product SKU in dedicated subfield","Indexer les SKUs des produits enfants séparéments" "If enabled, child products SKUs of composite products will be indexed in a separate field and the ""sku"" field will only contain the parent product sku.","Si activé, les SKUs des produits enfants des produits composites seront stockés dans un champ à part. Le champ ""sku"" du parent ne contiendra que son SKU." +"Enable indexing discount on child products","Calculer les discounts sur les produits enfants" +"Enable this if your catalog contains configurable products that are having childrens with different prices that could have separated discounts.","Activez cette option si votre catalogue contient des produits configurables ayant des enfants dont les prix de base sont différents et pouvant avoir des prix barrés différents." From 243d200425418ab2a1fe7f9dd02bb834b3332d84 Mon Sep 17 00:00:00 2001 From: Romain Ruaud Date: Wed, 22 Feb 2023 12:03:00 +0100 Subject: [PATCH 29/30] Code cleaning --- .../Model/Product/Indexer/Fulltext/Datasource/PriceData.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php index c7ca34bf3..ad7f1721e 100644 --- a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php +++ b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php @@ -31,7 +31,8 @@ class PriceData implements DatasourceInterface { /** @var string */ - private const XML_PATH_COMPUTE_CHILD_PRODUCT_DISCOUNT = 'smile_elasticsuite_catalogsearch_settings/catalogsearch/compute_child_product_discount'; + private const XML_PATH_COMPUTE_CHILD_PRODUCT_DISCOUNT + = 'smile_elasticsuite_catalogsearch_settings/catalogsearch/compute_child_product_discount'; /** * @var \Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Indexer\Fulltext\Datasource\PriceData @@ -66,6 +67,7 @@ class PriceData implements DatasourceInterface * @param ResourceModel $resourceModel Resource model * @param AttributeResourceModel $attributeResourceModel Attribute Resource model * @param PriceData\PriceDataReaderInterface[] $priceReaderPool Price modifiers pool. + * @param ScopeConfigInterface $scopeConfig Scope Config. */ public function __construct( ResourceModel $resourceModel, From bb999d4460ea7c7200111e9c5859793bc3177254 Mon Sep 17 00:00:00 2001 From: Romain Ruaud Date: Wed, 22 Feb 2023 12:07:22 +0100 Subject: [PATCH 30/30] Code cleaning --- .../Model/Product/Indexer/Fulltext/Datasource/PriceData.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php index ad7f1721e..eb3a857c9 100644 --- a/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php +++ b/src/module-elasticsuite-catalog/Model/Product/Indexer/Fulltext/Datasource/PriceData.php @@ -83,6 +83,7 @@ public function __construct( /** * Add price data to the index data. + * @SuppressWarnings(PHPMD.CyclomaticComplexity) * * {@inheritdoc} */