Skip to content

Commit c6c8130

Browse files
authored
Merge pull request #1710 from algolia/feat/MAGE-975-dynamic-widgets
MAGE-975 dynamic facets
2 parents ef1c3ad + 87725fa commit c6c8130

File tree

7 files changed

+1034
-798
lines changed

7 files changed

+1034
-798
lines changed

Block/Configuration.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ public function getConfiguration()
197197
'categorySeparator' => $config->getCategorySeparator(),
198198
'categoryPageIdAttribute' => $config->getCategoryPageIdAttributeName(),
199199
'isCategoryNavigationEnabled' => self::IS_CATEGORY_NAVIGATION_ENABLED,
200-
'hidePagination' => $config->hidePaginationInInstantSearchPage()
200+
'hidePagination' => $config->hidePaginationInInstantSearchPage(),
201+
'isDynamicFacetsEnabled' => $config->isDynamicFacetsEnabled()
201202
],
202203
'autocomplete' => [
203204
'enabled' => $config->isAutoCompleteEnabled(),

Helper/ConfigHelper.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class ConfigHelper
3838
public const NUMBER_OF_PRODUCT_RESULTS = 'algoliasearch_instant/instant/number_product_results';
3939
public const FACETS = 'algoliasearch_instant/instant_facets/facets';
4040
public const MAX_VALUES_PER_FACET = 'algoliasearch_instant/instant_facets/max_values_per_facet';
41+
public const ENABLE_DYNAMIC_FACETS = 'algoliasearch_instant/instant_facets/enable_dynamic_facets';
42+
4143
public const SORTING_INDICES = 'algoliasearch_instant/instant_sorts/sorts';
4244
public const SEARCHBOX_ENABLE = 'algoliasearch_instant/instant_options/instantsearch_searchbox';
4345
public const SHOW_SUGGESTIONS_NO_RESULTS = 'algoliasearch_instant/instant_options/show_suggestions_on_no_result_page';
@@ -1343,6 +1345,19 @@ public function getFacets($storeId = null)
13431345
return [];
13441346
}
13451347

1348+
/**
1349+
* @param int|null $storeId
1350+
* @return bool
1351+
*/
1352+
public function isDynamicFacetsEnabled(?int $storeId = null): bool
1353+
{
1354+
return $this->configInterface->isSetFlag(
1355+
self::ENABLE_DYNAMIC_FACETS,
1356+
ScopeInterface::SCOPE_STORE,
1357+
$storeId
1358+
);
1359+
}
1360+
13461361
/**
13471362
* @param $storeId
13481363
* @return array

Helper/Entity/ProductHelper.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,14 @@ public function getIndexSettings(?int $storeId = null): array
285285
'customRanking' => $this->getCustomRanking($storeId),
286286
'unretrievableAttributes' => $this->getUnretrieveableAttributes($storeId),
287287
'attributesForFaceting' => $this->facetBuilder->getAttributesForFaceting($storeId),
288-
'renderingContent' => $this->facetBuilder->getRenderingContent($storeId),
289288
'maxValuesPerFacet' => $this->configHelper->getMaxValuesPerFacet($storeId),
290289
'removeWordsIfNoResults' => $this->configHelper->getRemoveWordsIfNoResult($storeId),
291290
];
292291

292+
if ($this->configHelper->isDynamicFacetsEnabled($storeId)) {
293+
$indexSettings['renderingContent'] = $this->facetBuilder->getRenderingContent($storeId);
294+
}
295+
293296
// Additional index settings from event observer
294297
$transport = new DataObject($indexSettings);
295298
// Only for backward compatibility

etc/adminhtml/system.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,29 @@
434434
]]>
435435
</comment>
436436
</field>
437+
<field id="enable_dynamic_facets" translate="label comment" type="select" sortOrder="10" showInDefault="1"
438+
showInWebsite="1" showInStore="1">
439+
<label>Enable dynamic facets</label>
440+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
441+
<comment>
442+
<![CDATA[
443+
While the rendering of facets is configured based on your Magento admin settings, it is possible to override
444+
these settings via merchandising rules in Algolia. Enable "dynamic facets" to allow InstantSearch
445+
to render facets based on the rule conditions you define in either the Algolia Dashboard or Merchandising Studio.
446+
<br><br>
447+
This feature utilizes the "Facet display" configuration in the Algolia Dashboard (a.k.a. <code>renderingContent</code>).
448+
If you have customized this setting in the Dashboard for your products index, please note that enabling this option will allow Magento to overwrite your configuration.
449+
<br><br>
450+
<span class="algolia-config-warning">&#9888;</span>
451+
<strong>IMPORTANT!</strong> Do not enable dynamic facets unless you have the "renderingContent" feature enabled on your Algolia application. Otherwise this configuration
452+
can cause your indexing to fail.
453+
454+
]]>
455+
</comment>
456+
<depends>
457+
<field id="is_instant_enabled">1</field>
458+
</depends>
459+
</field>
437460
<depends>
438461
<field id="algoliasearch_instant/instant/is_instant_enabled">1</field>
439462
</depends>

etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<instant_facets>
3232
<facets><![CDATA[{"_1458145454535_587":{"attribute":"price","type":"slider","label":"Price","searchable":"2","create_rule":"2"},"_2541608784525_123":{"attribute":"categories","type":"conjunctive","label":"Categories","searchable":"2","create_rule":"2"},"_3211608784535_456":{"attribute":"color","type":"disjunctive","label":"Colors","searchable":"1","create_rule":"2"}}]]></facets>
3333
<max_values_per_facet>10</max_values_per_facet>
34+
<enable_dynamic_facets>0</enable_dynamic_facets>
3435
</instant_facets>
3536
<instant_sorts>
3637
<sorts><![CDATA[{"_4581608784535_789":{"attribute":"price","sort":"asc","sortLabel":"Lowest price"},"_2541555584535_585":{"attribute":"price","sort":"desc","sortLabel":"Highest price"},"_5581608784535_898":{"attribute":"created_at","sort":"desc","sortLabel":"Newest first"}}]]></sorts>

view/adminhtml/web/js/config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ require(
1111
// rows
1212
const rowIds = [
1313
'#row_algoliasearch_instant_instant_facets_facets',
14-
'#row_algoliasearch_instant_instant_facets_max_values_per_facet'
14+
'#row_algoliasearch_instant_instant_facets_max_values_per_facet',
15+
'#row_algoliasearch_instant_instant_facets_enable_dynamic_facets'
1516
];
1617

1718
let rowWarning = '<div class="algolia_dashboard_warning">';

0 commit comments

Comments
 (0)