Skip to content

Commit

Permalink
Merge pull request #1677 from algolia/release/3.14.4
Browse files Browse the repository at this point in the history
3.14.4 to main
  • Loading branch information
damcou authored Jan 15, 2025
2 parents e162a63 + ca83e9a commit 505d2e2
Show file tree
Hide file tree
Showing 17 changed files with 544 additions and 59 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# CHANGE LOG

## 3.14.4

### Features
- 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.)

### Updates
- Updated `getCookie` method to make it more consistent
- Removed dependency to `catalog_product_price` indexer

### Bug Fixes
- Fixed a bug where the Landing Page Builder was crashing on save with customer group pricing was enabled.
- Fixed issue where Insights information wasn't kept on the url after clicking "add to cart" on PLP powered by InstantSearch
- Fixed a bug where synonyms were unintentionally duplicated on the Algolia dashboard

## 3.14.3

### Updates
Expand Down
16 changes: 9 additions & 7 deletions Controller/Adminhtml/Landingpage/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,15 @@ public function execute()
$data['configuration'] = $data['algolia_configuration'];
if ($this->configHelper->isCustomerGroupsEnabled($data['store_id'])) {
$configuration = json_decode($data['algolia_configuration'], true);
$priceConfig = $configuration['price'.$data['price_key']];
$customerGroups = $this->customerGroupCollectionFactory->create();
$store = $this->storeManager->getStore($data['store_id']);
$baseCurrencyCode = $store->getBaseCurrencyCode();
foreach ($customerGroups as $group) {
$groupId = (int) $group->getData('customer_group_id');
$configuration['price.'.$baseCurrencyCode.'.group_'.$groupId] = $priceConfig;
if (isset($configuration['price'.$data['price_key']])) {
$priceConfig = $configuration['price'.$data['price_key']];
$customerGroups = $this->customerGroupCollectionFactory->create();
$store = $this->storeManager->getStore($data['store_id']);
$baseCurrencyCode = $store->getBaseCurrencyCode();
foreach ($customerGroups as $group) {
$groupId = (int) $group->getData('customer_group_id');
$configuration['price.'.$baseCurrencyCode.'.group_'.$groupId] = $priceConfig;
}
}
$data['configuration'] = json_encode($configuration);
}
Expand Down
36 changes: 29 additions & 7 deletions Helper/AlgoliaHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,6 @@ public function mergeSettings($indexName, $settings, $mergeSettingsFrom = '')
} catch (\Exception $e) {
}

$removes = ['slaves', 'replicas', 'decompoundedAttributes'];

if (isset($onlineSettings['mode']) && $onlineSettings['mode'] == 'neuralSearch') {
$removes[] = 'mode';
}

if (isset($settings['attributesToIndex'])) {
$settings['searchableAttributes'] = $settings['attributesToIndex'];
unset($settings['attributesToIndex']);
Expand All @@ -375,7 +369,7 @@ public function mergeSettings($indexName, $settings, $mergeSettingsFrom = '')
unset($onlineSettings['attributesToIndex']);
}

foreach ($removes as $remove) {
foreach ($this->getSettingsToRemove($onlineSettings) as $remove) {
if (isset($onlineSettings[$remove])) {
unset($onlineSettings[$remove]);
}
Expand All @@ -388,6 +382,34 @@ public function mergeSettings($indexName, $settings, $mergeSettingsFrom = '')
return $onlineSettings;
}

/**
* These settings are to be managed by other processes
* @param string[] $onlineSettings
* @return string[]
*/
protected function getSettingsToRemove(array $onlineSettings): array
{
$removals = ['slaves', 'replicas', 'decompoundedAttributes'];

if (isset($onlineSettings['mode']) && $onlineSettings['mode'] == 'neuralSearch') {
$removals[] = 'mode';
}

return array_merge($removals, $this->getSynonymSettingNames());
}

/**
* @return string[]
*/
protected function getSynonymSettingNames(): array
{
return [
'synonyms',
'altCorrections',
'placeholders'
];
}

/**
* Legacy function signature to add objects to Algolia
* @param array $objects
Expand Down
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
56 changes: 24 additions & 32 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Algolia\AlgoliaSearch\Helper\Entity\ProductHelper;
use Algolia\AlgoliaSearch\Helper\Entity\SuggestionHelper;
use Algolia\AlgoliaSearch\Service\IndexNameFetcher;
use Algolia\AlgoliaSearch\Service\Product\MissingPriceIndexHandler;
use Magento\Catalog\Model\Category;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\ResourceModel\Product\Collection;
Expand All @@ -35,21 +36,22 @@ class Data
protected IndexerInterface $priceIndexer;

public function __construct(
protected AlgoliaHelper $algoliaHelper,
protected ConfigHelper $configHelper,
protected ProductHelper $productHelper,
protected CategoryHelper $categoryHelper,
protected PageHelper $pageHelper,
protected SuggestionHelper $suggestionHelper,
protected AdditionalSectionHelper $additionalSectionHelper,
protected Emulation $emulation,
protected Logger $logger,
protected ResourceConnection $resource,
protected ManagerInterface $eventManager,
protected ScopeCodeResolver $scopeCodeResolver,
protected StoreManagerInterface $storeManager,
protected IndexNameFetcher $indexNameFetcher,
IndexerRegistry $indexerRegistry
protected AlgoliaHelper $algoliaHelper,
protected ConfigHelper $configHelper,
protected ProductHelper $productHelper,
protected CategoryHelper $categoryHelper,
protected PageHelper $pageHelper,
protected SuggestionHelper $suggestionHelper,
protected AdditionalSectionHelper $additionalSectionHelper,
protected Emulation $emulation,
protected Logger $logger,
protected ResourceConnection $resource,
protected ManagerInterface $eventManager,
protected ScopeCodeResolver $scopeCodeResolver,
protected StoreManagerInterface $storeManager,
protected IndexNameFetcher $indexNameFetcher,
protected MissingPriceIndexHandler $missingPriceIndexHandler,
IndexerRegistry $indexerRegistry
)
{
$this->priceIndexer = $indexerRegistry->get('catalog_product_price');
Expand Down Expand Up @@ -78,7 +80,7 @@ public function deleteObjects(int $storeId, array $ids, string $indexName): void
$this->algoliaHelper->deleteObjects($ids, $indexName);
}

/**
/**`
* @param string $query
* @param int $storeId
* @param array|null $searchParams
Expand Down Expand Up @@ -370,8 +372,6 @@ public function rebuildStoreProductIndex(int $storeId, array $productIds): void
return;
}

$this->checkPriceIndex($productIds);

$this->startEmulation($storeId);
$this->logger->start('Indexing');
try {
Expand Down Expand Up @@ -686,6 +686,7 @@ public function rebuildStoreProductIndexPage(
page ' . $page . ',
pageSize ' . $pageSize;
$this->logger->start($wrapperLogMessage);

if ($emulationInfo === null) {
$this->startEmulation($storeId);
}
Expand All @@ -711,6 +712,11 @@ public function rebuildStoreProductIndexPage(
'store' => $storeId
]
);

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

$logMessage = 'LOADING: ' . $this->logger->getStoreName($storeId) . ',
collection page: ' . $page . ',
pageSize: ' . $pageSize;
Expand Down Expand Up @@ -936,18 +942,4 @@ protected function deleteInactiveIds($storeId, $objectIds, $indexName): void
$idsToDeleteFromAlgolia = array_diff($objectIds, $dbIds);
$this->algoliaHelper->deleteObjects($idsToDeleteFromAlgolia, $indexName);
}

/**
* If the price index is stale
* @param array $productIds
* @return void
*/
protected function checkPriceIndex(array $productIds): void
{
$state = $this->priceIndexer->getState()->getStatus();
if ($state === \Magento\Framework\Indexer\StateInterface::STATUS_INVALID) {
$this->priceIndexer->reindexList($productIds);
}
}

}
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);
}
}
Loading

0 comments on commit 505d2e2

Please sign in to comment.