Skip to content

Commit 018aeaa

Browse files
committed
MAGE-640 Make category page ID attribute configurable
1 parent 76a563d commit 018aeaa

File tree

4 files changed

+31
-8
lines changed

4 files changed

+31
-8
lines changed

Helper/ConfigHelper.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class ConfigHelper
5050
public const USE_ADAPTIVE_IMAGE = 'algoliasearch_products/products/use_adaptive_image';
5151
public const INDEX_OUT_OF_STOCK_OPTIONS = 'algoliasearch_products/products/index_out_of_stock_options';
5252
public const ENABLE_VISUAL_MERCHANDISING = 'algoliasearch_products/products/enable_visual_merchandising';
53+
public const CATEGORY_PAGE_ID_ATTRIBUTE_NAME = 'algoliasearch_products/products/category_page_id_attribute_name';
5354

5455
public const CATEGORY_ATTRIBUTES = 'algoliasearch_categories/categories/category_additional_attributes';
5556
public const CATEGORY_CUSTOM_RANKING = 'algoliasearch_categories/categories/custom_ranking_category_attributes';
@@ -885,6 +886,15 @@ public function isVisualMerchEnabled($storeId = null): bool
885886
return $this->configInterface->isSetFlag(self::ENABLE_VISUAL_MERCHANDISING, ScopeInterface::SCOPE_STORE, $storeId);
886887
}
887888

889+
/**
890+
* @param $storeId
891+
* @return string
892+
*/
893+
public function getCategoryPageIdAttributeName($storeId = null): string
894+
{
895+
return (string) $this->configInterface->getValue(self::CATEGORY_PAGE_ID_ATTRIBUTE_NAME, ScopeInterface::SCOPE_STORE, $storeId);
896+
}
897+
888898
/**
889899
* @param $storeId
890900
* @return mixed
@@ -1624,4 +1634,4 @@ public function isAutocompleteNavigatorEnabled($storeId = null)
16241634
$storeId
16251635
);
16261636
}
1627-
}
1637+
}

Helper/Entity/ProductHelper.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
class ProductHelper
3737
{
3838
public const CATEGORY_SEPARATOR = ' /// ';
39-
public const CATEGORY_PAGE_ID_ATTRIBUTE = 'categoryPageId';
4039

4140
/**
4241
* @var CollectionFactory
@@ -852,8 +851,8 @@ protected function addCategoryData(array $algoliaData, Product $product): array
852851
$algoliaData['categories_without_path'] = $categoryData['categoryNames'];
853852
$algoliaData['categoryIds'] = array_values(array_unique($categoryData['categoryIds']));
854853

855-
if ($this->configHelper->isVisualMerchEnabled()) {
856-
$algoliaData[self::CATEGORY_PAGE_ID_ATTRIBUTE] = $this->flattenCategoryPaths($categoryData['categoriesWithPath']);
854+
if ($this->configHelper->isVisualMerchEnabled($product->getStoreId())) {
855+
$algoliaData[$this->configHelper->getCategoryPageIdAttributeName($product->getStoreId())] = $this->flattenCategoryPaths($categoryData['categoriesWithPath']);
857856
}
858857

859858
return $algoliaData;
@@ -1286,7 +1285,7 @@ protected function getAttributesForFaceting($storeId)
12861285
$attributesForFaceting[] = 'categoryIds';
12871286

12881287
if ($this->configHelper->isVisualMerchEnabled($storeId)) {
1289-
$attributesForFaceting[] = 'searchable(' . self::CATEGORY_PAGE_ID_ATTRIBUTE . ')';
1288+
$attributesForFaceting[] = 'searchable(' . $this->configHelper->getCategoryPageIdAttributeName($storeId) . ')';
12901289
}
12911290

12921291
return $attributesForFaceting;

etc/adminhtml/system.xml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@
326326
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
327327
<comment>
328328
<![CDATA[
329-
Virtual Replica is only available on Premium plans <a target="_blank" href="https://www.algolia.com/doc/integration/magento-2/how-it-works/indexing/?client=php#switching-to-virtual-replica">documentation</a>
329+
Virtual Replica is only available on Premium plans <a target="_blank" href="https://www.algolia.com/doc/integration/magento-2/how-it-works/indexing/?client=php#switching-to-virtual-replica">documentation</a>
330330
]]>
331331
</comment>
332332
<depends>
@@ -459,10 +459,23 @@
459459
If enabled, products will be indexed into Algolia with a compatible category data format that supports advanced merchandising features
460460
such as visual rules and the new Merchandising Studio.
461461
<br><br>
462-
NOTE: Merchandising Studio is only available on Premium plans.
462+
<strong>NOTE:</strong> After enabling, you must run a full product reindex to ensure that the attribute data is properly applied to your storefront catalog.
463+
Merchandising Studio is only available on Premium plans.
463464
]]>
464465
</comment>
465466
</field>
467+
<field id="category_page_id_attribute_name" translate="label comment" type="text" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="1">
468+
<label>Category page ID attribute</label>
469+
<comment>
470+
<![CDATA[
471+
Specify the name of the attribute that will contain your <a href="https://www.algolia.com/doc/guides/managing-results/rules/merchandising-and-promoting/how-to/merchandising-category-pages/#configure-the-visual-editor-for-category-merchandising" target="_blank">category page ID</a>. Default is <code>categoryPageId</code>.
472+
]]>
473+
</comment>
474+
<validate>required-entry validate-data</validate>
475+
<depends>
476+
<field id="enable_visual_merchandising">1</field>
477+
</depends>
478+
</field>
466479
</group>
467480
</section>
468481
<section id="algoliasearch_categories" translate="label" type="text" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
@@ -1210,4 +1223,4 @@
12101223
</group>
12111224
</section>
12121225
</system>
1213-
</config>
1226+
</config>

etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<product_additional_attributes><![CDATA[{"_1581608784535_535":{"attribute":"name","searchable":"1","order":"unordered","retrievable":"1"},"_1581608793630_630":{"attribute":"sku","searchable":"1","order":"unordered","retrievable":"1"},"_1582212731087_87":{"attribute":"manufacturer","searchable":"1","order":"unordered","retrievable":"1"},"_1582212739021_21":{"attribute":"categories","searchable":"1","order":"unordered","retrievable":"1"},"_1582212749587_587":{"attribute":"color","searchable":"1","order":"unordered","retrievable":"1"},"_1582212776086_86":{"attribute":"price","searchable":"2","order":"unordered","retrievable":"1"},"_1582212790407_407":{"attribute":"rating_summary","searchable":"2","order":"unordered","retrievable":"1"}}]]></product_additional_attributes>
2828
<custom_ranking_product_attributes><![CDATA[{"_1600352070901_901":{"attribute":"in_stock","order":"desc"},"_1600352075148_148":{"attribute":"ordered_qty","order":"desc"},"_1600352080300_300":{"attribute":"created_at","order":"desc"}}]]></custom_ranking_product_attributes>
2929
<enable_visual_merchandising>0</enable_visual_merchandising>
30+
<category_page_id_attribute_name>categoryPageId</category_page_id_attribute_name>
3031
</products>
3132
</algoliasearch_products>
3233
<algoliasearch_categories>

0 commit comments

Comments
 (0)