Skip to content

Commit 681b263

Browse files
authored
Merge pull request #1838 from algolia/release/3.16.1-dev
3.16.1-dev => main
2 parents dbfaace + e6b88bd commit 681b263

32 files changed

+1442
-535
lines changed

.circleci/config.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ jobs:
159159
working_directory: ~/Sites
160160
command: |
161161
bin/cli bash -c "cd ./dev/tests/integration && export $(cat .env | xargs) && ../../../vendor/bin/phpunit --debug --exclude-group problematic ../../../vendor/algolia/algoliasearch-magento-2/Test/Integration/"
162-
162+
163163
notify:
164164
docker:
165165
- image: cimg/base:current
@@ -173,6 +173,10 @@ jobs:
173173

174174
workflows:
175175
magento-build-and-test-workflow:
176+
when:
177+
matches:
178+
pattern: "^(feat|fix|chore)/MAGE.*"
179+
value: << pipeline.git.branch >>
176180
jobs:
177181
- magento-build:
178182
matrix:

.codacy.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
exclude_paths:
3+
- ".php-cs-fixer.php"
4+
- "dev/**"
5+
- "Test/**"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ vendor/
55
.php_cs.cache
66
.vscode
77
.idea
8+
node_modules

Api/Insights/EventProcessorInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public function setAuthenticatedUserToken(string $token): EventProcessorInterfac
4343

4444
public function setAnonymousUserToken(string $token): EventProcessorInterface;
4545

46+
/** @deprecated Store Manager now handled as injected dependency */
4647
public function setStoreManager(StoreManagerInterface $storeManager): EventProcessorInterface;
4748

4849
/**

CHANGELOG.md

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

3+
## 3.16.1
4+
5+
### Updates
6+
- Add checks on configuration migration processed on data patch
7+
- `EventProcessor` now calculates decimal precision on currency based on `Magento\Framework\Locale\FormatInterface`
8+
- Updated various unit/integration tests
9+
10+
### Bug fixes
11+
- Fixed Indexing Queue display in backend templates.
12+
- Fixed Indexing Queue merging mechanism, it should now have way better performances with delta indexing (updates) jobs.
13+
- Fixed implicit nullable types for PHP 8.4
14+
- Ensure that only non-redirect URL rewrites are considered when generating product URLs - thank you @fasimana
15+
- Apply rounding to insight events revenue values to avoid floating point precision errors - thank you @PromInc
16+
- Fix issue where double conversion occurred during price indexing in case of multi currency stores - thank you @natedawg92
17+
- Fix issue where non-clickable links where rendered on InstantSearch - thank you @PromInc
18+
- Fixed some Codacy issues
19+
320
## 3.16.0
421

522
### Features

Helper/Configuration/NoticeHelper.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ protected function getQueueNotice()
9999
in approx. ' . $eta . '.
100100
You may want to <a href="' . $indexingQueuePageUrl . '">clear the queue</a> or <a href="' . $indexingQueueConfigUrl . '">configure indexing queue</a>.
101101
<br><br>
102+
Depending on your configuration set on "Advanced > Maximum number of records processed per indexing job" and if the jobs can be merged into batches, you can expect higher performances.
103+
<br><br>
102104
Find out more about Indexing Queue in <a href="https://www.algolia.com/doc/integration/magento-2/how-it-works/indexing-queue/?utm_source=magento&utm_medium=extension&utm_campaign=magento_2&utm_term=shop-owner&utm_content=doc-link" target="_blank">documentation</a>.';
103105
}
104106

Helper/Entity/Product/PriceManager/ProductWithChildren.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,17 @@ protected function getMinMaxPrices(Product $product, $withTax, $subProducts, $cu
5858
} else {
5959
$minPrice = $specialPrice[0];
6060
}
61-
$price = $minPrice ?? $this->getTaxPrice($product, $subProduct->getFinalPrice(), $withTax);
62-
$basePrice = $this->getTaxPrice($product, $subProduct->getPrice(), $withTax);
61+
62+
$finalPrice = $subProduct->getFinalPrice();
63+
$basePrice = $subProduct->getPrice();
64+
65+
if ($currencyCode !== $this->baseCurrencyCode) {
66+
$finalPrice = $this->convertPrice($finalPrice, $currencyCode);
67+
$basePrice = $this->convertPrice($basePrice, $currencyCode);
68+
}
69+
70+
$price = $minPrice ?? $this->getTaxPrice($product, $finalPrice, $withTax);
71+
$basePrice = $this->getTaxPrice($product, $basePrice, $withTax);
6372
$min = min($min, $price);
6473
$original = min($original, $basePrice);
6574
$max = max($max, $price);
@@ -68,14 +77,7 @@ protected function getMinMaxPrices(Product $product, $withTax, $subProducts, $cu
6877
} else {
6978
$originalMax = $original = $min = $max;
7079
}
71-
if ($currencyCode !== $this->baseCurrencyCode) {
72-
$min = $this->convertPrice($min, $currencyCode);
73-
$original = $this->convertPrice($original, $currencyCode);
74-
if ($min !== $max) {
75-
$max = $this->convertPrice($max, $currencyCode);
76-
$originalMax = $this->convertPrice($originalMax, $currencyCode);
77-
}
78-
}
80+
7981
return [$min, $max, $original, $originalMax];
8082
}
8183

Helper/InsightsHelper.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ public function getEventProcessor(): EventProcessorInterface
9191
$this->eventProcessor = $this->eventProcessorFactory->create([
9292
'client' => $this->getInsightsClient(),
9393
'userToken' => $this->getAnonymousUserToken(),
94-
'authenticatedUserToken' => $this->getAuthenticatedUserToken(),
95-
'storeManager' => $this->storeManager
94+
'authenticatedUserToken' => $this->getAuthenticatedUserToken()
9695
]);
9796
}
9897
return $this->eventProcessor;

Model/Job.php

Lines changed: 34 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
namespace Algolia\AlgoliaSearch\Model;
44

55
use Algolia\AlgoliaSearch\Api\Data\JobInterface;
6+
use Magento\Framework\Data\Collection\AbstractDb;
7+
use Magento\Framework\Exception\AlreadyExistsException;
8+
use Magento\Framework\Model\Context;
9+
use Magento\Framework\Model\ResourceModel\AbstractResource;
10+
use Magento\Framework\ObjectManagerInterface;
11+
use Magento\Framework\Registry;
612

713
/**
814
* @api
@@ -26,46 +32,33 @@ class Job extends \Magento\Framework\Model\AbstractModel implements JobInterface
2632
{
2733
protected $_eventPrefix = 'algoliasearch_queue_job';
2834

29-
/** @var \Magento\Framework\ObjectManagerInterface */
30-
protected $objectManager;
31-
32-
/**
33-
* @param \Magento\Framework\Model\Context $context
34-
* @param \Magento\Framework\Registry $registry
35-
* @param \Magento\Framework\ObjectManagerInterface $objectManager
36-
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
37-
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
38-
* @param array $data
39-
*/
4035
public function __construct(
41-
\Magento\Framework\Model\Context $context,
42-
\Magento\Framework\Registry $registry,
43-
\Magento\Framework\ObjectManagerInterface $objectManager,
44-
?\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
45-
?\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
46-
array $data = []
36+
Context $context,
37+
Registry $registry,
38+
protected ObjectManagerInterface $objectManager,
39+
?AbstractResource $resource = null,
40+
?AbstractDb $resourceCollection = null,
41+
array $data = []
4742
) {
4843
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
49-
50-
$this->objectManager = $objectManager;
5144
}
5245

5346
/**
5447
* Magento Constructor
5548
*
5649
* @return void
5750
*/
58-
protected function _construct()
51+
protected function _construct(): void
5952
{
60-
$this->_init(\Algolia\AlgoliaSearch\Model\ResourceModel\Job::class);
53+
$this->_init(ResourceModel\Job::class);
6154
}
6255

6356
/**
64-
* @throws \Magento\Framework\Exception\AlreadyExistsException
65-
*
6657
* @return $this
58+
* @throws AlreadyExistsException|\Exception
59+
*
6760
*/
68-
public function execute()
61+
public function execute(): Job
6962
{
7063
$model = $this->objectManager->get($this->getClass());
7164
$method = $this->getMethod();
@@ -83,7 +76,7 @@ public function execute()
8376
/**
8477
* @return $this
8578
*/
86-
public function prepare()
79+
public function prepare(): Job
8780
{
8881
if ($this->getMergedIds() === null) {
8982
$this->setMergedIds([$this->getId()]);
@@ -94,8 +87,8 @@ public function prepare()
9487

9588
$this->setDecodedData($decodedData);
9689

97-
if (isset($decodedData['store_id'])) {
98-
$this->setStoreId($decodedData['store_id']);
90+
if (isset($decodedData['storeId'])) {
91+
$this->setStoreId($decodedData['storeId']);
9992
}
10093
}
10194

@@ -108,7 +101,7 @@ public function prepare()
108101
*
109102
* @return bool
110103
*/
111-
public function canMerge(Job $job, $maxJobDataSize)
104+
public function canMerge(Job $job, $maxJobDataSize): bool
112105
{
113106
if ($this->getClass() !== $job->getClass()) {
114107
return false;
@@ -124,44 +117,17 @@ public function canMerge(Job $job, $maxJobDataSize)
124117

125118
$decodedData = $this->getDecodedData();
126119

127-
// @todo Remove legacy checks on 3.16.0
128-
if ((!isset($decodedData['product_ids']) || count($decodedData['product_ids']) <= 0)
129-
&& (!isset($decodedData['category_ids']) || count($decodedData['category_ids']) < 0)
130-
&& (!isset($decodedData['entity_ids']) || count($decodedData['entity_ids']) < 0)
131-
&& (!isset($decodedData['page_ids']) || count($decodedData['page_ids']) < 0)) {
120+
if (!isset($decodedData['entityIds']) || count($decodedData['entityIds']) <= 0) {
132121
return false;
133122
}
134123

135124
$candidateDecodedData = $job->getDecodedData();
136125

137-
// @todo Remove legacy checks on 3.16.0
138-
if ((!isset($candidateDecodedData['product_ids']) || count($candidateDecodedData['product_ids']) <= 0)
139-
&& (!isset($candidateDecodedData['category_ids']) || count($candidateDecodedData['category_ids']) < 0)
140-
&& (!isset($candidateDecodedData['entity_ids']) || count($candidateDecodedData['entity_ids']) < 0)
141-
&& (!isset($candidateDecodedData['page_ids']) || count($candidateDecodedData['page_ids']) < 0)) {
126+
if (!isset($candidateDecodedData['entityIds']) || count($candidateDecodedData['entityIds']) <= 0) {
142127
return false;
143128
}
144129

145-
// @todo Remove on 3.16.0
146-
if (isset($decodedData['product_ids'])
147-
&& count($decodedData['product_ids']) + count($candidateDecodedData['product_ids']) > $maxJobDataSize) {
148-
return false;
149-
}
150-
151-
// @todo Remove on 3.16.0
152-
if (isset($decodedData['category_ids'])
153-
&& count($decodedData['category_ids']) + count($candidateDecodedData['category_ids']) > $maxJobDataSize) {
154-
return false;
155-
}
156-
157-
// @todo Remove on 3.16.0
158-
if (isset($decodedData['page_ids'])
159-
&& count($decodedData['page_ids']) + count($candidateDecodedData['page_ids']) > $maxJobDataSize) {
160-
return false;
161-
}
162-
163-
if (isset($decodedData['entity_ids'])
164-
&& count($decodedData['entity_ids']) + count($candidateDecodedData['entity_ids']) > $maxJobDataSize) {
130+
if (count($decodedData['entityIds']) + count($candidateDecodedData['entityIds']) > $maxJobDataSize) {
165131
return false;
166132
}
167133

@@ -173,7 +139,7 @@ public function canMerge(Job $job, $maxJobDataSize)
173139
*
174140
* @return Job
175141
*/
176-
public function merge(Job $mergedJob)
142+
public function merge(Job $mergedJob): Job
177143
{
178144
$mergedIds = $this->getMergedIds();
179145
array_push($mergedIds, $mergedJob->getId());
@@ -185,35 +151,13 @@ public function merge(Job $mergedJob)
185151

186152
$dataSize = $this->getDataSize();
187153

188-
// @todo Remove useless code on 3.16.0
189-
if (isset($decodedData['product_ids'])) {
190-
$decodedData['product_ids'] = array_unique(array_merge(
191-
$decodedData['product_ids'],
192-
$mergedJobDecodedData['product_ids']
193-
));
194-
195-
$dataSize = count($decodedData['product_ids']);
196-
} elseif (isset($decodedData['category_ids'])) {
197-
$decodedData['category_ids'] = array_unique(array_merge(
198-
$decodedData['category_ids'],
199-
$mergedJobDecodedData['category_ids']
200-
));
201-
202-
$dataSize = count($decodedData['category_ids']);
203-
} elseif (isset($decodedData['page_ids'])) {
204-
$decodedData['page_ids'] = array_unique(array_merge(
205-
$decodedData['page_ids'],
206-
$mergedJobDecodedData['page_ids']
207-
));
208-
209-
$dataSize = count($decodedData['page_ids']);
210-
} elseif (isset($decodedData['entity_ids'])) {
211-
$decodedData['entity_ids'] = array_unique(array_merge(
212-
$decodedData['entity_ids'],
213-
$mergedJobDecodedData['entity_ids']
154+
if (isset($decodedData['entityIds'])) {
155+
$decodedData['entityIds'] = array_unique(array_merge(
156+
$decodedData['entityIds'],
157+
$mergedJobDecodedData['entityIds']
214158
));
215159

216-
$dataSize = count($decodedData['entity_ids']);
160+
$dataSize = count($decodedData['entityIds']);
217161
}
218162

219163
$this->setDecodedData($decodedData);
@@ -225,7 +169,7 @@ public function merge(Job $mergedJob)
225169
/**
226170
* @return array
227171
*/
228-
public function getDefaultValues()
172+
public function getDefaultValues(): array
229173
{
230174
$values = [];
231175

@@ -235,7 +179,7 @@ public function getDefaultValues()
235179
/**
236180
* @return string
237181
*/
238-
public function getStatus()
182+
public function getStatus(): string
239183
{
240184
$status = JobInterface::STATUS_PROCESSING;
241185

@@ -253,11 +197,11 @@ public function getStatus()
253197
/**
254198
* @param \Exception $e
255199
*
256-
* @throws \Magento\Framework\Exception\AlreadyExistsException
200+
* @throws AlreadyExistsException
257201
*
258202
* @return Job
259203
*/
260-
public function saveError(\Exception $e)
204+
public function saveError(\Exception $e): Job
261205
{
262206
$this->setErrorLog($e->getMessage());
263207
$this->getResource()->save($this);

Model/Product/Url.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public function getUrl(Product $product, $params = [])
6767
UrlRewrite::ENTITY_ID => $product->getId(),
6868
UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE,
6969
UrlRewrite::STORE_ID => $storeId,
70+
UrlRewrite::REDIRECT_TYPE => 0,
7071
];
7172
if ($categoryId) {
7273
$filterData[UrlRewrite::METADATA]['category_id'] = $categoryId;

0 commit comments

Comments
 (0)