Skip to content

Commit 8f8a1bb

Browse files
committed
MAGE-1122 Add feature flag via admin config
1 parent 244bedc commit 8f8a1bb

File tree

5 files changed

+48
-1
lines changed

5 files changed

+48
-1
lines changed

Helper/ConfigHelper.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class ConfigHelper
108108
public const CONNECTION_TIMEOUT = 'algoliasearch_advanced/advanced/connection_timeout';
109109
public const READ_TIMEOUT = 'algoliasearch_advanced/advanced/read_timeout';
110110
public const WRITE_TIMEOUT = 'algoliasearch_advanced/advanced/write_timeout';
111+
public const AUTO_PRICE_INDEXING_ENABLED = 'algoliasearch_advanced/advanced/auto_price_indexing';
111112

112113
public const SHOW_OUT_OF_STOCK = 'cataloginventory/options/show_out_of_stock';
113114

@@ -1272,6 +1273,15 @@ public function getWriteTimeout($storeId = null)
12721273
return $this->configInterface->getValue(self::WRITE_TIMEOUT, ScopeInterface::SCOPE_STORE, $storeId);
12731274
}
12741275

1276+
public function isAutoPriceIndexingEnabled(?int $storeId = null): bool
1277+
{
1278+
return $this->configInterface->isSetFlag(
1279+
self::AUTO_PRICE_INDEXING_ENABLED,
1280+
ScopeInterface::SCOPE_STORE,
1281+
$storeId
1282+
);
1283+
}
1284+
12751285
/**
12761286
* @param $storeId
12771287
* @return array|bool|float|int|mixed|string

Helper/Data.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,9 @@ public function rebuildStoreProductIndexPage(
713713
]
714714
);
715715

716-
$this->missingPriceIndexHandler->refreshPriceIndex($collection);
716+
if ($this->configHelper->isAutoPriceIndexingEnabled($storeId)) {
717+
$this->missingPriceIndexHandler->refreshPriceIndex($collection);
718+
}
717719

718720
$logMessage = 'LOADING: ' . $this->logger->getStoreName($storeId) . ',
719721
collection page: ' . $page . ',
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Algolia\AlgoliaSearch\Model\Config;
4+
5+
use Magento\Config\Model\Config\CommentInterface;
6+
use Magento\Framework\UrlInterface;
7+
8+
class AutomaticPriceIndexingComment implements CommentInterface
9+
{
10+
public function __construct(
11+
protected UrlInterface $urlInterface
12+
) { }
13+
14+
public function getCommentText($elementValue)
15+
{
16+
$url = $this->urlInterface->getUrl('https://www.algolia.com/doc/integration/magento-2/how-it-works/indexing-queue/#configure-the-queue');
17+
18+
$comment = array();
19+
$comment[] = 'Algolia relies on the core Magento Product Price index when serializing product data. If the price index is not up to date, Algolia will not be able to accurately determine what should be included in the search index.';
20+
$comment[] = 'If you are experiencing problems with products not syncing to Algolia due to this issue, enabling this setting will allow Algolia to automatically update the price index as needed.';
21+
$comment[] = 'NOTE: This can introduce a marginal amount of overhead to the indexing process so only enable if necessary. Be sure to <a href="' . $url . '" target="_blank">optimize the indexing queue</a> based on the impact of this operation.';
22+
return implode('<br><br>', $comment);
23+
}
24+
}

etc/adminhtml/system.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,16 @@
13371337
<field id="write_timeout" translate="label comment" type="text" sortOrder="110" showInDefault="1">
13381338
<label>Write Timeout (In Seconds)</label>
13391339
</field>
1340+
<field id="auto_price_indexing" translate="label comment" type="select" sortOrder="120" showInDefault="1" showInWebsite="1" showInStore="1">
1341+
<label>Enable automatic price indexing</label>
1342+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
1343+
<comment>
1344+
<model>Algolia\AlgoliaSearch\Model\Config\AutomaticPriceIndexingComment</model>
1345+
</comment>
1346+
<depends>
1347+
<field id="active">1</field>
1348+
</depends>
1349+
</field>
13401350
</group>
13411351
<group id="queue" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
13421352
<label>Indexing Queue</label>

etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
<connection_timeout>2</connection_timeout>
9595
<read_timeout>30</read_timeout>
9696
<write_timeout>30</write_timeout>
97+
<auto_price_indexing>0</auto_price_indexing>
9798
</advanced>
9899
<queue>
99100
<number_of_element_by_page>300</number_of_element_by_page>

0 commit comments

Comments
 (0)