Skip to content

Commit

Permalink
MAGE-1122 Add feature flag via admin config
Browse files Browse the repository at this point in the history
  • Loading branch information
cammonro committed Dec 10, 2024
1 parent 244bedc commit 8f8a1bb
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Helper/ConfigHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class ConfigHelper
public const CONNECTION_TIMEOUT = 'algoliasearch_advanced/advanced/connection_timeout';
public const READ_TIMEOUT = 'algoliasearch_advanced/advanced/read_timeout';
public const WRITE_TIMEOUT = 'algoliasearch_advanced/advanced/write_timeout';
public const AUTO_PRICE_INDEXING_ENABLED = 'algoliasearch_advanced/advanced/auto_price_indexing';

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

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

public function isAutoPriceIndexingEnabled(?int $storeId = null): bool
{
return $this->configInterface->isSetFlag(
self::AUTO_PRICE_INDEXING_ENABLED,
ScopeInterface::SCOPE_STORE,
$storeId
);
}

/**
* @param $storeId
* @return array|bool|float|int|mixed|string
Expand Down
4 changes: 3 additions & 1 deletion Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,9 @@ public function rebuildStoreProductIndexPage(
]
);

$this->missingPriceIndexHandler->refreshPriceIndex($collection);
if ($this->configHelper->isAutoPriceIndexingEnabled($storeId)) {
$this->missingPriceIndexHandler->refreshPriceIndex($collection);
}

$logMessage = 'LOADING: ' . $this->logger->getStoreName($storeId) . ',
collection page: ' . $page . ',
Expand Down
24 changes: 24 additions & 0 deletions Model/Config/AutomaticPriceIndexingComment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Algolia\AlgoliaSearch\Model\Config;

use Magento\Config\Model\Config\CommentInterface;
use Magento\Framework\UrlInterface;

class AutomaticPriceIndexingComment implements CommentInterface
{
public function __construct(
protected UrlInterface $urlInterface
) { }

public function getCommentText($elementValue)
{
$url = $this->urlInterface->getUrl('https://www.algolia.com/doc/integration/magento-2/how-it-works/indexing-queue/#configure-the-queue');

$comment = array();
$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.';
$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.';
$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.';
return implode('<br><br>', $comment);
}
}
10 changes: 10 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1337,6 +1337,16 @@
<field id="write_timeout" translate="label comment" type="text" sortOrder="110" showInDefault="1">
<label>Write Timeout (In Seconds)</label>
</field>
<field id="auto_price_indexing" translate="label comment" type="select" sortOrder="120" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enable automatic price indexing</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment>
<model>Algolia\AlgoliaSearch\Model\Config\AutomaticPriceIndexingComment</model>
</comment>
<depends>
<field id="active">1</field>
</depends>
</field>
</group>
<group id="queue" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Indexing Queue</label>
Expand Down
1 change: 1 addition & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<connection_timeout>2</connection_timeout>
<read_timeout>30</read_timeout>
<write_timeout>30</write_timeout>
<auto_price_indexing>0</auto_price_indexing>
</advanced>
<queue>
<number_of_element_by_page>300</number_of_element_by_page>
Expand Down

0 comments on commit 8f8a1bb

Please sign in to comment.