From 31dc678d8b73ad1f4b84ed553173a7175b9a0a6b Mon Sep 17 00:00:00 2001 From: Vadym Honcharuk Date: Wed, 7 Aug 2024 18:50:44 +0300 Subject: [PATCH 1/2] [Optimizer] Feature #2766, add ability to apply optimizer to all categories except some --- .../Model/Optimizer/Limitation/ReadHandler.php | 4 ++-- .../Model/Optimizer/Preview.php | 7 ++++++- .../Model/ResourceModel/Optimizer.php | 2 +- .../Model/ResourceModel/Optimizer/Limitation.php | 2 +- .../Optimizer/Form/Modifier/Limitation.php | 4 ++-- .../i18n/en_US.csv | 3 ++- .../i18n/fr_FR.csv | 1 + .../smile_elasticsuite_catalog_optimizer_form.xml | 13 +++++++++++++ 8 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/module-elasticsuite-catalog-optimizer/Model/Optimizer/Limitation/ReadHandler.php b/src/module-elasticsuite-catalog-optimizer/Model/Optimizer/Limitation/ReadHandler.php index 0e217f14b..af27a2d65 100644 --- a/src/module-elasticsuite-catalog-optimizer/Model/Optimizer/Limitation/ReadHandler.php +++ b/src/module-elasticsuite-catalog-optimizer/Model/Optimizer/Limitation/ReadHandler.php @@ -64,10 +64,10 @@ public function execute($entity, $arguments = []) */ private function setCategoryLimitation($entity, $searchContainers) { - $applyTo = (bool) ($searchContainers['catalog_view_container'] ?? false); + $applyTo = ((int) $searchContainers['catalog_view_container'] ?? 0); if ($applyTo) { - $containerData = ['apply_to' => (int) true]; + $containerData = ['apply_to' => $applyTo]; $categoryIds = $this->resource->getCategoryIdsByOptimizer($entity); if (!empty($categoryIds)) { $containerData['category_ids'] = $categoryIds; diff --git a/src/module-elasticsuite-catalog-optimizer/Model/Optimizer/Preview.php b/src/module-elasticsuite-catalog-optimizer/Model/Optimizer/Preview.php index c70d0a9cb..27decb7b8 100644 --- a/src/module-elasticsuite-catalog-optimizer/Model/Optimizer/Preview.php +++ b/src/module-elasticsuite-catalog-optimizer/Model/Optimizer/Preview.php @@ -204,9 +204,14 @@ private function canApply() : bool } } elseif ($canApply && $this->containerConfiguration->getName() === 'catalog_view_container') { $config = $this->optimizer->getCatalogViewContainer(); - if ((int) ($config['apply_to'] ?? 0) === 1 && !empty($config['category_ids'])) { + $applyTo = (int) $config['apply_to'] ?? 0; + if (($applyTo > 0) && !empty($config['category_ids'])) { $categoryIds = array_filter($config['category_ids']); $canApply = in_array($this->category->getId(), $categoryIds, true); + + if ($applyTo > 1) { + $canApply = !$canApply; + } } } diff --git a/src/module-elasticsuite-catalog-optimizer/Model/ResourceModel/Optimizer.php b/src/module-elasticsuite-catalog-optimizer/Model/ResourceModel/Optimizer.php index 0556580e7..b15be3896 100644 --- a/src/module-elasticsuite-catalog-optimizer/Model/ResourceModel/Optimizer.php +++ b/src/module-elasticsuite-catalog-optimizer/Model/ResourceModel/Optimizer.php @@ -159,7 +159,7 @@ private function saveSearchContainerRelation(\Magento\Framework\Model\AbstractMo $searchContainerName = 'quick_search_container'; } $searchContainerData = $object->getData($searchContainerName); - $applyTo = is_array($searchContainerData) ? ((bool) $searchContainerData['apply_to'] ?? false) : false; + $applyTo = is_array($searchContainerData) ? ($searchContainerData['apply_to'] ?? 0) : 0; $searchContainerLinks[(string) $searchContainer] = [ OptimizerInterface::OPTIMIZER_ID => (int) $object->getId(), OptimizerInterface::SEARCH_CONTAINER => (string) $searchContainer, diff --git a/src/module-elasticsuite-catalog-optimizer/Model/ResourceModel/Optimizer/Limitation.php b/src/module-elasticsuite-catalog-optimizer/Model/ResourceModel/Optimizer/Limitation.php index 2fb2eb2c3..a2787ac6c 100644 --- a/src/module-elasticsuite-catalog-optimizer/Model/ResourceModel/Optimizer/Limitation.php +++ b/src/module-elasticsuite-catalog-optimizer/Model/ResourceModel/Optimizer/Limitation.php @@ -162,7 +162,7 @@ private function getApplicationData($container, $column, $idValue) ->where($this->getConnection()->quoteInto("osc.search_container = ?", (string) $container)) ->where( $this->getConnection()->quoteInto( - "osc.apply_to = 0 OR (osc.apply_to = 1 AND main_table.{$column} = ?)", + "osc.apply_to = 0 OR (osc.apply_to = 1 AND main_table.{$column} = ?) OR (osc.apply_to = 2 AND main_table.{$column} != ?)", (int) $idValue ) ) diff --git a/src/module-elasticsuite-catalog-optimizer/Ui/Component/Optimizer/Form/Modifier/Limitation.php b/src/module-elasticsuite-catalog-optimizer/Ui/Component/Optimizer/Form/Modifier/Limitation.php index cebb431fa..6af32a2f8 100644 --- a/src/module-elasticsuite-catalog-optimizer/Ui/Component/Optimizer/Form/Modifier/Limitation.php +++ b/src/module-elasticsuite-catalog-optimizer/Ui/Component/Optimizer/Form/Modifier/Limitation.php @@ -59,9 +59,9 @@ public function modifyData(array $data) $data[$optimizer->getId()]['search_container'] = array_keys($searchContainers); - $applyToCategories = (bool) ($searchContainers['catalog_view_container'] ?? false); + $applyToCategories = (int) ($searchContainers['catalog_view_container'] ?? 0); if ($applyToCategories) { - $containerData = ['apply_to' => (int) true]; + $containerData = ['apply_to' => $applyToCategories]; $categoryIds = $this->resource->getCategoryIdsByOptimizer($optimizer); if (!empty($categoryIds)) { $containerData['category_ids'] = $categoryIds; diff --git a/src/module-elasticsuite-catalog-optimizer/i18n/en_US.csv b/src/module-elasticsuite-catalog-optimizer/i18n/en_US.csv index c0ec104a1..f4969c714 100644 --- a/src/module-elasticsuite-catalog-optimizer/i18n/en_US.csv +++ b/src/module-elasticsuite-catalog-optimizer/i18n/en_US.csv @@ -52,8 +52,9 @@ Actions,Actions Cancel,Cancel "Add Selected Terms","Add Selected Terms" "Category Product View","Category Product View" -"All Categories","All Categories" +"All Categories","All categories" "Selected categories","Selected categories" +"All except selected categories","All except selected categories" "Apply to categories","Apply to categories" Configuration,Configuration "Boost value (%)","Boost value (%)" diff --git a/src/module-elasticsuite-catalog-optimizer/i18n/fr_FR.csv b/src/module-elasticsuite-catalog-optimizer/i18n/fr_FR.csv index c16b9e8d3..5c7511b56 100644 --- a/src/module-elasticsuite-catalog-optimizer/i18n/fr_FR.csv +++ b/src/module-elasticsuite-catalog-optimizer/i18n/fr_FR.csv @@ -54,6 +54,7 @@ Cancel,Annuler "Category Product View","Navigation Catalogue" "All Categories","Toutes les catégories" "Selected categories","Catégories sélectionnées" +"All except selected categories","Toutes les catégories sauf celles sélectionnées" "Apply to categories","Appliquer aux catégories" Configuration,Configuration "Boost value (%)","Valeur du boost (%)" diff --git a/src/module-elasticsuite-catalog-optimizer/view/adminhtml/ui_component/smile_elasticsuite_catalog_optimizer_form.xml b/src/module-elasticsuite-catalog-optimizer/view/adminhtml/ui_component/smile_elasticsuite_catalog_optimizer_form.xml index e9bee3fe9..559a100e7 100644 --- a/src/module-elasticsuite-catalog-optimizer/view/adminhtml/ui_component/smile_elasticsuite_catalog_optimizer_form.xml +++ b/src/module-elasticsuite-catalog-optimizer/view/adminhtml/ui_component/smile_elasticsuite_catalog_optimizer_form.xml @@ -565,6 +565,10 @@ 1 Selected categories + + 2 + All except selected categories + text @@ -596,6 +600,15 @@ + + 2 + + + smile_elasticsuite_catalog_optimizer_form.smile_elasticsuite_catalog_optimizer_form.catalog_view_container.category_ids + show + + + true From 572e2315a60581cacc35d59d48446bd9977c4894 Mon Sep 17 00:00:00 2001 From: Vadym Honcharuk Date: Wed, 7 Aug 2024 19:05:14 +0300 Subject: [PATCH 2/2] [Optimizer] Feature #2766, phpcs cleaning --- .../Model/ResourceModel/Optimizer/Limitation.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/module-elasticsuite-catalog-optimizer/Model/ResourceModel/Optimizer/Limitation.php b/src/module-elasticsuite-catalog-optimizer/Model/ResourceModel/Optimizer/Limitation.php index a2787ac6c..5655155ef 100644 --- a/src/module-elasticsuite-catalog-optimizer/Model/ResourceModel/Optimizer/Limitation.php +++ b/src/module-elasticsuite-catalog-optimizer/Model/ResourceModel/Optimizer/Limitation.php @@ -162,7 +162,8 @@ private function getApplicationData($container, $column, $idValue) ->where($this->getConnection()->quoteInto("osc.search_container = ?", (string) $container)) ->where( $this->getConnection()->quoteInto( - "osc.apply_to = 0 OR (osc.apply_to = 1 AND main_table.{$column} = ?) OR (osc.apply_to = 2 AND main_table.{$column} != ?)", + "osc.apply_to = 0 OR (osc.apply_to = 1 AND main_table.{$column} = ?) OR + (osc.apply_to = 2 AND main_table.{$column} != ?)", (int) $idValue ) )