Skip to content

Commit ca83e9a

Browse files
authored
Merge pull request #1675 from algolia/release/3.14.4-dev
Release/3.14.4
2 parents e162a63 + 43939eb commit ca83e9a

File tree

17 files changed

+544
-59
lines changed

17 files changed

+544
-59
lines changed

CHANGELOG.md

+14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# CHANGE LOG
22

3+
## 3.14.4
4+
5+
### Features
6+
- Added a feature to enable automatic price indexing on the Advanced section of the configuration (This feature should help alleviate issues where missing pricing records prevent Algolia from being able to index products.)
7+
8+
### Updates
9+
- Updated `getCookie` method to make it more consistent
10+
- Removed dependency to `catalog_product_price` indexer
11+
12+
### Bug Fixes
13+
- Fixed a bug where the Landing Page Builder was crashing on save with customer group pricing was enabled.
14+
- Fixed issue where Insights information wasn't kept on the url after clicking "add to cart" on PLP powered by InstantSearch
15+
- Fixed a bug where synonyms were unintentionally duplicated on the Algolia dashboard
16+
317
## 3.14.3
418

519
### Updates

Controller/Adminhtml/Landingpage/Save.php

+9-7
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,15 @@ public function execute()
107107
$data['configuration'] = $data['algolia_configuration'];
108108
if ($this->configHelper->isCustomerGroupsEnabled($data['store_id'])) {
109109
$configuration = json_decode($data['algolia_configuration'], true);
110-
$priceConfig = $configuration['price'.$data['price_key']];
111-
$customerGroups = $this->customerGroupCollectionFactory->create();
112-
$store = $this->storeManager->getStore($data['store_id']);
113-
$baseCurrencyCode = $store->getBaseCurrencyCode();
114-
foreach ($customerGroups as $group) {
115-
$groupId = (int) $group->getData('customer_group_id');
116-
$configuration['price.'.$baseCurrencyCode.'.group_'.$groupId] = $priceConfig;
110+
if (isset($configuration['price'.$data['price_key']])) {
111+
$priceConfig = $configuration['price'.$data['price_key']];
112+
$customerGroups = $this->customerGroupCollectionFactory->create();
113+
$store = $this->storeManager->getStore($data['store_id']);
114+
$baseCurrencyCode = $store->getBaseCurrencyCode();
115+
foreach ($customerGroups as $group) {
116+
$groupId = (int) $group->getData('customer_group_id');
117+
$configuration['price.'.$baseCurrencyCode.'.group_'.$groupId] = $priceConfig;
118+
}
117119
}
118120
$data['configuration'] = json_encode($configuration);
119121
}

Helper/AlgoliaHelper.php

+29-7
Original file line numberDiff line numberDiff line change
@@ -359,12 +359,6 @@ public function mergeSettings($indexName, $settings, $mergeSettingsFrom = '')
359359
} catch (\Exception $e) {
360360
}
361361

362-
$removes = ['slaves', 'replicas', 'decompoundedAttributes'];
363-
364-
if (isset($onlineSettings['mode']) && $onlineSettings['mode'] == 'neuralSearch') {
365-
$removes[] = 'mode';
366-
}
367-
368362
if (isset($settings['attributesToIndex'])) {
369363
$settings['searchableAttributes'] = $settings['attributesToIndex'];
370364
unset($settings['attributesToIndex']);
@@ -375,7 +369,7 @@ public function mergeSettings($indexName, $settings, $mergeSettingsFrom = '')
375369
unset($onlineSettings['attributesToIndex']);
376370
}
377371

378-
foreach ($removes as $remove) {
372+
foreach ($this->getSettingsToRemove($onlineSettings) as $remove) {
379373
if (isset($onlineSettings[$remove])) {
380374
unset($onlineSettings[$remove]);
381375
}
@@ -388,6 +382,34 @@ public function mergeSettings($indexName, $settings, $mergeSettingsFrom = '')
388382
return $onlineSettings;
389383
}
390384

385+
/**
386+
* These settings are to be managed by other processes
387+
* @param string[] $onlineSettings
388+
* @return string[]
389+
*/
390+
protected function getSettingsToRemove(array $onlineSettings): array
391+
{
392+
$removals = ['slaves', 'replicas', 'decompoundedAttributes'];
393+
394+
if (isset($onlineSettings['mode']) && $onlineSettings['mode'] == 'neuralSearch') {
395+
$removals[] = 'mode';
396+
}
397+
398+
return array_merge($removals, $this->getSynonymSettingNames());
399+
}
400+
401+
/**
402+
* @return string[]
403+
*/
404+
protected function getSynonymSettingNames(): array
405+
{
406+
return [
407+
'synonyms',
408+
'altCorrections',
409+
'placeholders'
410+
];
411+
}
412+
391413
/**
392414
* Legacy function signature to add objects to Algolia
393415
* @param array $objects

Helper/ConfigHelper.php

+10
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

+24-32
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Algolia\AlgoliaSearch\Helper\Entity\ProductHelper;
1313
use Algolia\AlgoliaSearch\Helper\Entity\SuggestionHelper;
1414
use Algolia\AlgoliaSearch\Service\IndexNameFetcher;
15+
use Algolia\AlgoliaSearch\Service\Product\MissingPriceIndexHandler;
1516
use Magento\Catalog\Model\Category;
1617
use Magento\Catalog\Model\Product;
1718
use Magento\Catalog\Model\ResourceModel\Product\Collection;
@@ -35,21 +36,22 @@ class Data
3536
protected IndexerInterface $priceIndexer;
3637

3738
public function __construct(
38-
protected AlgoliaHelper $algoliaHelper,
39-
protected ConfigHelper $configHelper,
40-
protected ProductHelper $productHelper,
41-
protected CategoryHelper $categoryHelper,
42-
protected PageHelper $pageHelper,
43-
protected SuggestionHelper $suggestionHelper,
44-
protected AdditionalSectionHelper $additionalSectionHelper,
45-
protected Emulation $emulation,
46-
protected Logger $logger,
47-
protected ResourceConnection $resource,
48-
protected ManagerInterface $eventManager,
49-
protected ScopeCodeResolver $scopeCodeResolver,
50-
protected StoreManagerInterface $storeManager,
51-
protected IndexNameFetcher $indexNameFetcher,
52-
IndexerRegistry $indexerRegistry
39+
protected AlgoliaHelper $algoliaHelper,
40+
protected ConfigHelper $configHelper,
41+
protected ProductHelper $productHelper,
42+
protected CategoryHelper $categoryHelper,
43+
protected PageHelper $pageHelper,
44+
protected SuggestionHelper $suggestionHelper,
45+
protected AdditionalSectionHelper $additionalSectionHelper,
46+
protected Emulation $emulation,
47+
protected Logger $logger,
48+
protected ResourceConnection $resource,
49+
protected ManagerInterface $eventManager,
50+
protected ScopeCodeResolver $scopeCodeResolver,
51+
protected StoreManagerInterface $storeManager,
52+
protected IndexNameFetcher $indexNameFetcher,
53+
protected MissingPriceIndexHandler $missingPriceIndexHandler,
54+
IndexerRegistry $indexerRegistry
5355
)
5456
{
5557
$this->priceIndexer = $indexerRegistry->get('catalog_product_price');
@@ -78,7 +80,7 @@ public function deleteObjects(int $storeId, array $ids, string $indexName): void
7880
$this->algoliaHelper->deleteObjects($ids, $indexName);
7981
}
8082

81-
/**
83+
/**`
8284
* @param string $query
8385
* @param int $storeId
8486
* @param array|null $searchParams
@@ -370,8 +372,6 @@ public function rebuildStoreProductIndex(int $storeId, array $productIds): void
370372
return;
371373
}
372374

373-
$this->checkPriceIndex($productIds);
374-
375375
$this->startEmulation($storeId);
376376
$this->logger->start('Indexing');
377377
try {
@@ -686,6 +686,7 @@ public function rebuildStoreProductIndexPage(
686686
page ' . $page . ',
687687
pageSize ' . $pageSize;
688688
$this->logger->start($wrapperLogMessage);
689+
689690
if ($emulationInfo === null) {
690691
$this->startEmulation($storeId);
691692
}
@@ -711,6 +712,11 @@ public function rebuildStoreProductIndexPage(
711712
'store' => $storeId
712713
]
713714
);
715+
716+
if ($this->configHelper->isAutoPriceIndexingEnabled($storeId)) {
717+
$this->missingPriceIndexHandler->refreshPriceIndex($collection);
718+
}
719+
714720
$logMessage = 'LOADING: ' . $this->logger->getStoreName($storeId) . ',
715721
collection page: ' . $page . ',
716722
pageSize: ' . $pageSize;
@@ -936,18 +942,4 @@ protected function deleteInactiveIds($storeId, $objectIds, $indexName): void
936942
$idsToDeleteFromAlgolia = array_diff($objectIds, $dbIds);
937943
$this->algoliaHelper->deleteObjects($idsToDeleteFromAlgolia, $indexName);
938944
}
939-
940-
/**
941-
* If the price index is stale
942-
* @param array $productIds
943-
* @return void
944-
*/
945-
protected function checkPriceIndex(array $productIds): void
946-
{
947-
$state = $this->priceIndexer->getState()->getStatus();
948-
if ($state === \Magento\Framework\Indexer\StateInterface::STATUS_INVALID) {
949-
$this->priceIndexer->reindexList($productIds);
950-
}
951-
}
952-
953945
}
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+
}

0 commit comments

Comments
 (0)