Skip to content

Commit 9879eb2

Browse files
authored
Merge branch 'develop' into german_translations
2 parents b312be2 + 7326355 commit 9879eb2

File tree

13 files changed

+582
-516
lines changed

13 files changed

+582
-516
lines changed

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
# CHANGE LOG
22

3+
## 3.10.2
4+
5+
### UPDATES
6+
- Ensured compatibility of the extension with Magento 2.4.6
7+
- Updated the code to allow for convenient customization of object serialization
8+
- Enhanced comments for non-castable attributes in system configuration
9+
- Updated the code to ensure that accurate prices are indexed for bundle products when the dynamic price attribute is turned off
10+
- Updated autocomplete to include userToken and enablePersonalization tag in search requests
11+
12+
13+
14+
### Bug Fixes
15+
- Fixed issue with section.label in autocomplete
16+
- Resolved issue with nbOfQuerySuggestions in autocomplete
17+
- Fixed routing error related to disabling searchBox for instant search page
18+
- Resolved deployment issue with prefixed Magento database tables
19+
- Fixed spacing issue with pagination on instant search page
20+
21+
322
## 3.10.1
423

524
### UPDATES

Helper/Entity/Product/PriceManager/Bundle.php

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ class Bundle extends ProductWithChildren
1919
*/
2020
protected function addAdditionalData($product, $withTax, $subProducts, $currencyCode, $field) {
2121
$data = $this->getMinMaxPrices($product, $withTax, $subProducts, $currencyCode);
22-
$dashedFormat = $this->getDashedPriceFormat($data['min_price'], $data['max'], $currencyCode);
23-
if ($data['min_price'] !== $data['max']) {
24-
$this->handleBundleNonEqualMinMaxPrices($field, $currencyCode, $data['min_price'], $data['max'], $dashedFormat);
22+
$dashedFormat = $this->getDashedPriceFormat($data['min_price'], $data['max_price'], $currencyCode);
23+
if ($data['min_price'] !== $data['max_price']) {
24+
$this->handleBundleNonEqualMinMaxPrices($field, $currencyCode, $data['min_price'], $data['max_price'], $dashedFormat);
2525
}
26-
$this->handleOriginalPrice($field, $currencyCode, $data['min_price'], $data['max'], $data['min_original'], $data['max_original']);
26+
27+
$this->handleOriginalPrice($field, $currencyCode, $data['min_price'], $data['max_price'], $data['min_original'], $data['max_original']);
2728
if (!$this->customData[$field][$currencyCode]['default']) {
28-
$this->handleZeroDefaultPrice($field, $currencyCode, $data['min_price'], $data['max']);
29+
$this->handleZeroDefaultPrice($field, $currencyCode, $data['min_price'], $data['max_price']);
2930
}
3031
if ($this->areCustomersGroupsEnabled) {
3132
$groupedDashedFormat = $this->getBundleDashedPriceFormat($data['min'], $data['max'], $currencyCode);
@@ -42,25 +43,29 @@ protected function addAdditionalData($product, $withTax, $subProducts, $currency
4243
*/
4344
protected function getMinMaxPrices(Product $product, $withTax, $subProducts, $currencyCode)
4445
{
45-
$regularPrice = $product->getPriceInfo()->getPrice('regular_price')->getMinimalPrice()->getValue();
46+
$product->setData('website_id', $product->getStore()->getWebsiteId());
4647
$minPrice = $product->getPriceInfo()->getPrice('final_price')->getMinimalPrice()->getValue();
4748
$minOriginalPrice = $product->getPriceInfo()->getPrice('regular_price')->getMinimalPrice()->getValue();
4849
$maxOriginalPrice = $product->getPriceInfo()->getPrice('regular_price')->getMaximalPrice()->getValue();
4950
$max = $product->getPriceInfo()->getPrice('final_price')->getMaximalPrice()->getValue();
5051
$minArray = [];
52+
$maxArray = [];
5153
foreach ($this->groups as $group) {
5254
$groupId = (int) $group->getData('customer_group_id');
53-
foreach ($subProducts as $subProduct) {
54-
$subProduct->setData('customer_group_id', $groupId);
55-
$subProductFinalPrice = $this->getTaxPrice($product, $subProduct->getPriceModel()->getFinalPrice(1, $subProduct), $withTax);
56-
$priceDiff = $subProduct->getPrice() - $subProductFinalPrice;
57-
$minArray[$groupId][] = $regularPrice - $priceDiff;
58-
}
55+
$product->setData('customer_group_id', $groupId);
56+
$minPrice = $product->getPriceInfo()->getPrice('final_price')->getMinimalPrice()->getValue();
57+
$minArray[$groupId] = $product->getPriceInfo()->getPrice('final_price')->getMinimalPrice()->getValue();
58+
$maxArray[$groupId] = $product->getPriceInfo()->getPrice('final_price')->getMaximalPrice()->getValue();
59+
$product->setData('customer_group_id', null);
5960
}
6061

6162
$minPriceArray = [];
6263
foreach ($minArray as $groupId => $min) {
63-
$minPriceArray[$groupId] = min($min);
64+
$minPriceArray[$groupId] = $min;
65+
}
66+
$maxPriceArray = [];
67+
foreach ($maxArray as $groupId => $max) {
68+
$maxPriceArray[$groupId] = $max;
6469
}
6570

6671
if ($currencyCode !== $this->baseCurrencyCode) {
@@ -70,15 +75,15 @@ protected function getMinMaxPrices(Product $product, $withTax, $subProducts, $cu
7075
foreach ($minPriceArray as $groupId => $price) {
7176
$minPriceArray[$groupId] = $this->convertPrice($price, $currencyCode);
7277
}
73-
if ($min !== $max) {
78+
if ($minPrice !== $max) {
7479
$max = $this->convertPrice($max, $currencyCode);
7580
}
7681
}
77-
7882
return [
7983
'min' => $minPriceArray,
80-
'max' => $max,
84+
'max' => $maxPriceArray,
8185
'min_price' => $minPrice,
86+
'max_price' => $max,
8287
'min_original' => $minOriginalPrice,
8388
'max_original' => $maxOriginalPrice
8489
];
@@ -117,10 +122,10 @@ protected function handleBundleNonEqualMinMaxPrices($field, $currencyCode, $min,
117122
protected function getBundleDashedPriceFormat($minPrices, $max, $currencyCode) {
118123
$dashedFormatPrice = [];
119124
foreach ($minPrices as $groupId => $min) {
120-
if ($min === $max) {
125+
if ($min === $max[$groupId]) {
121126
$dashedFormatPrice [$groupId] = '';
122127
}
123-
$dashedFormatPrice[$groupId] = $this->formatPrice($min, $currencyCode) . ' - ' . $this->formatPrice($max, $currencyCode);
128+
$dashedFormatPrice[$groupId] = $this->formatPrice($min, $currencyCode) . ' - ' . $this->formatPrice($max[$groupId], $currencyCode);
124129
}
125130
return $dashedFormatPrice;
126131
}
@@ -139,12 +144,12 @@ protected function setFinalGroupPricesBundle($field, $currencyCode, $min, $max,
139144
foreach ($this->groups as $group) {
140145
$groupId = (int) $group->getData('customer_group_id');
141146
$this->customData[$field][$currencyCode]['group_' . $groupId] = $min[$groupId];
142-
if ($min === $max) {
147+
if ($min[$groupId] === $max[$groupId]) {
143148
$this->customData[$field][$currencyCode]['group_' . $groupId . '_formated'] =
144149
$this->customData[$field][$currencyCode]['default_formated'];
145150
} else {
146151
$this->customData[$field][$currencyCode]['group_' . $groupId . '_formated'] = $dashedFormat[$groupId];
147152
}
148153
}
149154
}
150-
}
155+
}

Helper/Entity/ProductHelper.php

Lines changed: 63 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -167,23 +167,24 @@ class ProductHelper
167167
* @param ImageHelper $imageHelper
168168
*/
169169
public function __construct(
170-
Config $eavConfig,
171-
ConfigHelper $configHelper,
172-
AlgoliaHelper $algoliaHelper,
173-
Logger $logger,
174-
StoreManagerInterface $storeManager,
175-
ManagerInterface $eventManager,
176-
Visibility $visibility,
177-
Stock $stockHelper,
170+
Config $eavConfig,
171+
ConfigHelper $configHelper,
172+
AlgoliaHelper $algoliaHelper,
173+
Logger $logger,
174+
StoreManagerInterface $storeManager,
175+
ManagerInterface $eventManager,
176+
Visibility $visibility,
177+
Stock $stockHelper,
178178
StockRegistryInterface $stockRegistry,
179-
CurrencyHelper $currencyManager,
180-
CategoryHelper $categoryHelper,
181-
PriceManager $priceManager,
182-
Type $productType,
183-
CollectionFactory $productCollectionFactory,
184-
GroupCollection $groupCollection,
185-
ImageHelper $imageHelper
186-
) {
179+
CurrencyHelper $currencyManager,
180+
CategoryHelper $categoryHelper,
181+
PriceManager $priceManager,
182+
Type $productType,
183+
CollectionFactory $productCollectionFactory,
184+
GroupCollection $groupCollection,
185+
ImageHelper $imageHelper
186+
)
187+
{
187188
$this->eavConfig = $eavConfig;
188189
$this->configHelper = $configHelper;
189190
$this->algoliaHelper = $algoliaHelper;
@@ -295,7 +296,8 @@ public function getProductCollectionQuery(
295296
$productIds = null,
296297
$onlyVisible = true,
297298
$includeNotVisibleIndividually = false
298-
) {
299+
)
300+
{
299301
$productCollection = $this->productCollectionFactory->create();
300302
$products = $productCollection
301303
->setStoreId($storeId)
@@ -401,12 +403,12 @@ public function setSettings($indexName, $indexNameTmp, $storeId, $saveToTmpIndic
401403
$attributesForFaceting = $this->getAttributesForFaceting($storeId);
402404

403405
$indexSettings = [
404-
'searchableAttributes' => $searchableAttributes,
405-
'customRanking' => $customRanking,
406+
'searchableAttributes' => $searchableAttributes,
407+
'customRanking' => $customRanking,
406408
'unretrievableAttributes' => $unretrievableAttributes,
407-
'attributesForFaceting' => $attributesForFaceting,
408-
'maxValuesPerFacet' => (int) $this->configHelper->getMaxValuesPerFacet($storeId),
409-
'removeWordsIfNoResults' => $this->configHelper->getRemoveWordsIfNoResult($storeId),
409+
'attributesForFaceting' => $attributesForFaceting,
410+
'maxValuesPerFacet' => (int)$this->configHelper->getMaxValuesPerFacet($storeId),
411+
'removeWordsIfNoResults' => $this->configHelper->getRemoveWordsIfNoResult($storeId),
410412
];
411413

412414
// Additional index settings from event observer
@@ -419,7 +421,7 @@ public function setSettings($indexName, $indexNameTmp, $storeId, $saveToTmpIndic
419421
$this->eventManager->dispatch(
420422
'algolia_products_index_before_set_settings',
421423
[
422-
'store_id' => $storeId,
424+
'store_id' => $storeId,
423425
'index_settings' => $transport,
424426
]
425427
);
@@ -485,7 +487,7 @@ public function setSettings($indexName, $indexNameTmp, $storeId, $saveToTmpIndic
485487
} else {
486488
foreach ($sortingIndices as $values) {
487489
$replicaName = $values['name'];
488-
array_unshift($customRanking,$values['ranking'][0]);
490+
array_unshift($customRanking, $values['ranking'][0]);
489491
$replicaSetting['customRanking'] = $customRanking;
490492
$this->algoliaHelper->setSettings($replicaName, $replicaSetting, false, false);
491493
$this->logger->log('Setting settings to "' . $replicaName . '" replica.');
@@ -578,12 +580,12 @@ public function getObject(Product $product)
578580
];
579581

580582
$customData = [
581-
'objectID' => $product->getId(),
582-
'name' => $product->getName(),
583-
'url' => $product->getUrlModel()->getUrl($product, $urlParams),
584-
'visibility_search' => (int) (in_array($visibility, $visibleInSearch)),
585-
'visibility_catalog' => (int) (in_array($visibility, $visibleInCatalog)),
586-
'type_id' => $product->getTypeId(),
583+
'objectID' => $product->getId(),
584+
'name' => $product->getName(),
585+
'url' => $product->getUrlModel()->getUrl($product, $urlParams),
586+
'visibility_search' => (int)(in_array($visibility, $visibleInSearch)),
587+
'visibility_catalog' => (int)(in_array($visibility, $visibleInCatalog)),
588+
'type_id' => $product->getTypeId(),
587589
];
588590

589591
$additionalAttributes = $this->getAdditionalAttributes($product->getStoreId());
@@ -886,7 +888,7 @@ protected function addStockQty($defaultData, $customData, $additionalAttributes,
886888

887889
$stockItem = $this->stockRegistry->getStockItem($product->getId());
888890
if ($stockItem) {
889-
$customData['stock_qty'] = (int) $stockItem->getQty();
891+
$customData['stock_qty'] = (int)$stockItem->getQty();
890892
}
891893
}
892894

@@ -980,7 +982,7 @@ protected function addNullValue($customData, $subProducts, $attribute, Attribute
980982
}
981983

982984
if (is_array($values) && count($values) > 0) {
983-
$customData[$attributeName] = array_values(array_unique($values));
985+
$customData[$attributeName] = $this->getSanitizedArrayValues($values, $attributeName);
984986
}
985987

986988
if (count($subProductImages) > 0) {
@@ -991,12 +993,27 @@ protected function addNullValue($customData, $subProducts, $attribute, Attribute
991993
}
992994

993995
/**
994-
* @param $valueText
995-
* @param Product $subProduct
996-
* @param AttributeResource $attributeResource
996+
* By default Algolia will remove all redundant attribute values that are fetched from the child simple products.
997+
*
998+
* Overridable via Preference to allow implementer to enforce their own uniqueness rules while leveraging existing indexing code.
999+
* e.g. $values = (in_array($attributeName, self::NON_UNIQUE_ATTRIBUTES)) ? $values : array_unique($values);
1000+
*
1001+
* @param array $values
1002+
* @param string $attributeName
1003+
* @return array
1004+
*/
1005+
protected function getSanitizedArrayValues(array $values, string $attributeName): array
1006+
{
1007+
return array_values(array_unique($values));
1008+
}
1009+
1010+
/**
1011+
* @param string|array $valueText - bit of a misnomer - essentially the retrieved values to be indexed for a given product's attribute
1012+
* @param Product $subProduct - the simple product to index
1013+
* @param AttributeResource $attributeResource - the attribute being indexed
9971014
* @return array
9981015
*/
999-
protected function getValues($valueText, Product $subProduct, AttributeResource $attributeResource)
1016+
protected function getValues($valueText, Product $subProduct, AttributeResource $attributeResource): array
10001017
{
10011018
$values = [];
10021019

@@ -1065,7 +1082,8 @@ protected function addNonNullValue(
10651082
Product $product,
10661083
$attribute,
10671084
AttributeResource $attributeResource
1068-
) {
1085+
)
1086+
{
10691087
$valueText = null;
10701088

10711089
if (!is_array($value) && $attributeResource->usesSource()) {
@@ -1165,7 +1183,7 @@ protected function getAttributesForFaceting($storeId)
11651183

11661184
if ($this->configHelper->isCustomerGroupsEnabled($storeId)) {
11671185
foreach ($this->groupCollection as $group) {
1168-
$group_id = (int) $group->getData('customer_group_id');
1186+
$group_id = (int)$group->getData('customer_group_id');
11691187

11701188
$attributesForFaceting[] = 'price.' . $currency_code . '.group_' . $group_id;
11711189
}
@@ -1338,10 +1356,10 @@ public function canProductBeReindexed($product, $storeId, $isChildProduct = fals
13381356
}
13391357

13401358
if ($isChildProduct === false && !in_array($product->getVisibility(), [
1341-
Visibility::VISIBILITY_BOTH,
1342-
Visibility::VISIBILITY_IN_SEARCH,
1343-
Visibility::VISIBILITY_IN_CATALOG,
1344-
])) {
1359+
Visibility::VISIBILITY_BOTH,
1360+
Visibility::VISIBILITY_IN_SEARCH,
1361+
Visibility::VISIBILITY_IN_CATALOG,
1362+
])) {
13451363
throw (new ProductNotVisibleException())
13461364
->withProduct($product)
13471365
->withStoreId($storeId);
@@ -1381,10 +1399,11 @@ public function productIsInStock($product, $storeId)
13811399
* @param $replica
13821400
* @return array
13831401
*/
1384-
protected function handleVirtualReplica($replicas, $indexName) {
1402+
protected function handleVirtualReplica($replicas, $indexName)
1403+
{
13851404
$virtualReplicaArray = [];
13861405
foreach ($replicas as $replica) {
1387-
$virtualReplicaArray[] = 'virtual('.$replica.')';
1406+
$virtualReplicaArray[] = 'virtual(' . $replica . ')';
13881407
}
13891408
return $virtualReplicaArray;
13901409
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Algolia Search for Magento 2
22
==================
33

4-
![Latest version](https://img.shields.io/badge/latest-3.10.1-green)
4+
![Latest version](https://img.shields.io/badge/latest-3.10.2-green)
55
![Magento 2](https://img.shields.io/badge/Magento-2.4.x-orange)
66

77
![PHP](https://img.shields.io/badge/PHP-8.1,7.4-blue)

Setup/Patch/Schema/RecommendConfigPatch.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function apply()
6262

6363
$this->moduleDataSetup->getConnection()->startSetup();
6464
$connection = $this->moduleDataSetup->getConnection();
65-
$table = $connection->getTableName('core_config_data');
65+
$table = $this->moduleDataSetup->getTable('core_config_data');
6666
foreach ($movedConfigDirectives as $from => $to) {
6767
try {
6868
$connection->query('UPDATE ' . $table . ' SET path = "' . $to . '" WHERE path = "' . $from . '"');

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Algolia Search integration for Magento 2",
44
"type": "magento2-module",
55
"license": ["MIT"],
6-
"version": "3.10.1",
6+
"version": "3.10.2",
77
"require": {
88
"magento/framework": "~102.0|~103.0",
99
"algolia/algoliasearch-client-php": "3.2",

etc/adminhtml/system.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,7 @@
11301130
<backend_model>Magento\Config\Model\Config\Backend\Serialized\ArraySerialized</backend_model>
11311131
<comment>
11321132
<![CDATA[
1133-
Choose here the textfield attributes that you don't want to be turned into numeric values (i.e. : if you don't want "00123" turned into "123")
1133+
Choose here the textfield/non-castable attributes that you don't want to be turned into numeric values (i.e. : if you don't want "00123" turned into "123" or "34567834545672" turned into "345678E+2")
11341134
]]>
11351135
</comment>
11361136
</field>

etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
3-
<module name="Algolia_AlgoliaSearch" setup_version="3.10.1">
3+
<module name="Algolia_AlgoliaSearch" setup_version="3.10.2">
44
<sequence>
55
<module name="Magento_Theme"/>
66
<module name="Magento_Backend"/>

0 commit comments

Comments
 (0)