Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Optimizer] Add ability to apply optimizer to all categories except some #3343

Open
wants to merge 2 commits into
base: 2.10.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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} = ?)",
"osc.apply_to = 0 OR (osc.apply_to = 1 AND main_table.{$column} = ?) OR
(osc.apply_to = 2 AND main_table.{$column} != ?)",
(int) $idValue
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/module-elasticsuite-catalog-optimizer/i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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 (%)"
Expand Down
1 change: 1 addition & 0 deletions src/module-elasticsuite-catalog-optimizer/i18n/fr_FR.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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 (%)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,10 @@
<item name="value" xsi:type="number">1</item>
<item name="label" xsi:type="string" translate="true">Selected categories</item>
</item>
<item name="2" xsi:type="array">
<item name="value" xsi:type="number">2</item>
<item name="label" xsi:type="string" translate="true">All except selected categories</item>
</item>
</item>
<item name="config" xsi:type="array">
<item name="dataType" xsi:type="string">text</item>
Expand Down Expand Up @@ -596,6 +600,15 @@
</action>
</actions>
</rule>
<rule name="2">
<value>2</value>
<actions>
<action name="0">
<target>smile_elasticsuite_catalog_optimizer_form.smile_elasticsuite_catalog_optimizer_form.catalog_view_container.category_ids</target>
<callback>show</callback>
</action>
</actions>
</rule>
</rules>
<enabled>true</enabled>
</switcherConfig>
Expand Down
Loading