Skip to content

Commit 63566f3

Browse files
authored
Merge pull request #1521 from algolia/release/3.13.3
release/3.13.3
2 parents c80d0c5 + dc9b68a commit 63566f3

File tree

20 files changed

+234
-85
lines changed

20 files changed

+234
-85
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ composer.lock
44
vendor/
55
.php_cs.cache
66
.vscode
7+
.idea

CHANGELOG.md

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

3+
## 3.13.3
4+
5+
### Updates
6+
- Updated CSP whitelist
7+
- Updated code to show current version of AlgoliaSearch extension in Magento admin
8+
- Updated code to make compatible with PHP 7
9+
- Updated code and merged community submitted PRs
10+
- Updated code for consistent auth tokens
11+
- Updated code for Autocomplete highlights
12+
13+
### Bug Fixes
14+
- Fixed issues with Recommend items in mobile view
15+
- Fixed issue related to decompoundedAttributes admin config error
16+
- Fixed issue with Analytics Overview date format bug
17+
18+
319
## 3.13.2
420

521
### Updates

Helper/AlgoliaHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ public function mergeSettings($indexName, $settings, $mergeSettingsFrom = '')
289289
} catch (\Exception $e) {
290290
}
291291

292-
$removes = ['slaves', 'replicas'];
292+
$removes = ['slaves', 'replicas', 'decompoundedAttributes'];
293293

294294
if (isset($settings['attributesToIndex'])) {
295295
$settings['searchableAttributes'] = $settings['attributesToIndex'];
@@ -963,4 +963,4 @@ protected function getAlgoliaFiltersArrayWithoutCurrentRefinement($filters, $nee
963963

964964
return $filters;
965965
}
966-
}
966+
}

Helper/AnalyticsHelper.php

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Algolia\AlgoliaSearch\Config\AnalyticsConfig;
77
use Algolia\AlgoliaSearch\DataProvider\Analytics\IndexEntityDataProvider;
88
use Algolia\AlgoliaSearch\RequestOptions\RequestOptionsFactory;
9+
use Magento\Framework\Locale\ResolverInterface;
910

1011
class AnalyticsHelper
1112
{
@@ -14,9 +15,6 @@ class AnalyticsHelper
1415
public const ANALYTICS_FILTER_PATH = '/2/filters';
1516
public const ANALYTICS_CLICKS_PATH = '/2/clicks';
1617

17-
/** @var AlgoliaHelper */
18-
private $algoliaHelper;
19-
2018
/** @var ConfigHelper */
2119
private $configHelper;
2220

@@ -26,6 +24,12 @@ class AnalyticsHelper
2624
/** @var Logger */
2725
private $logger;
2826

27+
/** @var ResolverInterface */
28+
private $localeResolver;
29+
30+
public const DATE_FORMAT_PICKER = 'dd MMM yyyy';
31+
public const DATE_FORMAT_API = 'Y-m-d';
32+
2933
private $searches;
3034
private $users;
3135
private $rateOfNoResults;
@@ -58,25 +62,21 @@ class AnalyticsHelper
5862
protected $region;
5963

6064
/**
61-
* @param AlgoliaHelper $algoliaHelper
6265
* @param ConfigHelper $configHelper
6366
* @param IndexEntityDataProvider $entityHelper
6467
* @param Logger $logger
65-
* @param string $region
68+
* @param ResolverInterface $localeResolver
6669
*/
6770
public function __construct(
68-
AlgoliaHelper $algoliaHelper,
6971
ConfigHelper $configHelper,
7072
IndexEntityDataProvider $entityHelper,
7173
Logger $logger,
72-
string $region = 'us'
74+
ResolverInterface $localeResolver
7375
) {
74-
$this->algoliaHelper = $algoliaHelper;
7576
$this->configHelper = $configHelper;
76-
7777
$this->entityHelper = $entityHelper;
78-
7978
$this->logger = $logger;
79+
$this->localeResolver = $localeResolver;
8080
$this->region = $this->configHelper->getAnalyticsRegion();
8181
}
8282

@@ -371,4 +371,17 @@ public function getErrors()
371371
{
372372
return $this->errors;
373373
}
374+
375+
/**
376+
* @param string $timezone
377+
* @return \IntlDateFormatter
378+
*/
379+
public function getAnalyticsDatePickerFormatter(string $timezone): \IntlDateFormatter
380+
{
381+
$locale = $this->localeResolver->getLocale();
382+
$dateFormatter = new \IntlDateFormatter($locale, \IntlDateFormatter::NONE, \IntlDateFormatter::NONE, $timezone);
383+
$dateFormatter->setPattern(self::DATE_FORMAT_PICKER);
384+
return $dateFormatter;
385+
}
386+
374387
}

Helper/Configuration/NoticeHelper.php

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class NoticeHelper extends \Magento\Framework\App\Helper\AbstractHelper
4444
'getClickAnalyticsNotice',
4545
'getPersonalizationNotice',
4646
'getRecommendNotice',
47-
'getCookieConfigurationNotice',
47+
'getCookieConfigurationNotice',
4848
];
4949

5050
/** @var array[] */
@@ -157,23 +157,33 @@ protected function getMsiNotice()
157157
];
158158
}
159159

160-
protected function getVersionNotice()
160+
protected function getVersionNotice(): void
161161
{
162+
$currentVersion = $this->configHelper->getExtensionVersion();
162163
$newVersion = $this->getNewVersionNotification();
163-
if ($newVersion === null) {
164+
if (!$currentVersion && !$newVersion) {
164165
return;
165166
}
166167

167-
$noticeTitle = 'Algolia Extension update';
168-
$noticeContent = 'You are using old version of Algolia extension. Latest version of the extension is v <b>' . $newVersion['version'] . '</b><br />
168+
$notice = [
169+
'selector' => '.entry-edit',
170+
'method' => 'before'
171+
];
172+
173+
if ($newVersion) {
174+
$noticeTitle = 'Algolia extension update';
175+
$noticeContent = 'You are using an old version of Algolia extension. Latest version of the extension is v <b>' . $newVersion['version'] . '</b><br />
169176
It is highly recommended to update your version to avoid any unexpected issues and to get new features.<br />
170177
See details on our <a target="_blank" href="' . $newVersion['url'] . '">Github repository</a>.';
178+
$notice['message'] = $this->formatNotice($noticeTitle, $noticeContent);
179+
}
180+
else {
181+
$noticeTitle = 'Algolia extension version';
182+
$noticeContent = "You are using version <strong>$currentVersion</strong> of the Algolia Magento integration.";
183+
$notice['message'] = $this->formatNotice($noticeTitle, $noticeContent, 'icon-bulb');
184+
}
171185

172-
$this->notices[] = [
173-
'selector' => '.entry-edit',
174-
'method' => 'before',
175-
'message' => $this->formatNotice($noticeTitle, $noticeContent),
176-
];
186+
$this->notices[] = $notice;
177187
}
178188

179189
protected function getClickAnalyticsNotice()
@@ -208,7 +218,7 @@ protected function getClickAnalyticsNotice()
208218
'message' => $noticeContent,
209219
];
210220
}
211-
221+
212222
protected function getCookieConfigurationNotice()
213223
{
214224
$noticeContent = '';

Helper/Entity/Product/PriceManager/ProductWithoutChildren.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function __construct(
9292
Rule $rule,
9393
ProductFactory $productloader,
9494
ScopedProductTierPriceManagementInterface $productTierPrice,
95-
Logger $logger,
95+
Logger $logger
9696
) {
9797
$this->configHelper = $configHelper;
9898
$this->customerGroupCollectionFactory = $customerGroupCollectionFactory;

Helper/InsightsHelper.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ class InsightsHelper
1717

1818
public const ALGOLIA_CUSTOMER_USER_TOKEN_COOKIE_NAME = 'aa-search';
1919

20+
/**
21+
* Up to 129 chars per https://www.algolia.com/doc/rest-api/insights/#method-param-usertoken
22+
* But capping at legacy 64 chars for backward compat
23+
*/
24+
/** @var int */
25+
public const ALGOLIA_USER_TOKEN_MAX_LENGTH = 64;
26+
2027
/** @var ConfigHelper */
2128
private $configHelper;
2229

@@ -25,7 +32,7 @@ class InsightsHelper
2532

2633
/** @var SessionManagerInterface */
2734
private $sessionManager;
28-
35+
2936
/** @var CookieManagerInterface */
3037
private $cookieManager;
3138

README.md

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

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

77
![PHP](https://img.shields.io/badge/PHP-8.2%2C8.1%2C7.4-blue)

ViewModel/Adminhtml/Analytics/Overview.php

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Algolia\AlgoliaSearch\ViewModel\Adminhtml\BackendView;
88
use Magento\Framework\Exception\LocalizedException;
99
use Magento\Framework\Exception\NoSuchEntityException;
10+
use Magento\Framework\Locale\ResolverInterface;
1011
use Magento\Store\Api\Data\StoreInterface;
1112

1213
class Overview implements \Magento\Framework\View\Element\Block\ArgumentInterface
@@ -26,24 +27,30 @@ class Overview implements \Magento\Framework\View\Element\Block\ArgumentInterfac
2627
/** @var IndexEntityDataProvider */
2728
private $indexEntityDataProvider;
2829

30+
/** @var ResolverInterface */
31+
private $localeResolver;
32+
2933
/** @var array */
3034
private $analyticsParams = [];
3135

3236
/**
33-
* Index constructor.
37+
* Index constructor.
3438
*
3539
* @param BackendView $backendView
3640
* @param AnalyticsHelper $analyticsHelper
3741
* @param IndexEntityDataProvider $indexEntityDataProvider
42+
* @param ResolverInterface $localeResolver
3843
*/
3944
public function __construct(
4045
BackendView $backendView,
4146
AnalyticsHelper $analyticsHelper,
42-
IndexEntityDataProvider $indexEntityDataProvider
47+
IndexEntityDataProvider $indexEntityDataProvider,
48+
ResolverInterface $localeResolver
4349
) {
4450
$this->backendView = $backendView;
4551
$this->analyticsHelper = $analyticsHelper;
4652
$this->indexEntityDataProvider = $indexEntityDataProvider;
53+
$this->localeResolver = $localeResolver;
4754
}
4855

4956
/**
@@ -54,9 +61,13 @@ public function getBackendView()
5461
return $this->backendView;
5562
}
5663

57-
public function getTimeZone()
64+
/**
65+
* @return string
66+
* @throws NoSuchEntityException
67+
*/
68+
public function getTimeZone(): string
5869
{
59-
return $this->backendView->getDateTime()->getConfigTimezone(
70+
return (string) $this->backendView->getDateTime()->getConfigTimezone(
6071
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
6172
$this->getStore()->getId()
6273
);
@@ -81,18 +92,16 @@ public function getIndexName()
8192
*
8293
* @return array
8394
*/
84-
public function getAnalyticsParams($additional = [])
95+
public function getAnalyticsParams(array $additional = []): array
8596
{
8697
if (empty($this->analyticsParams)) {
8798
$params = ['index' => $this->getIndexName()];
8899
if ($formData = $this->getBackendView()->getBackendSession()->getAlgoliaAnalyticsFormData()) {
89-
$dateTime = $this->getBackendView()->getDateTime();
90-
$timeZone = $this->getTimeZone();
91-
if (isset($formData['from']) && $formData['from'] !== '') {
92-
$params['startDate'] = $dateTime->date($formData['from'], $timeZone, true, false)->format('Y-m-d');
100+
if (!empty($formData['from'])) {
101+
$params['startDate'] = $this->formatFormSubmittedDate($formData['from']);
93102
}
94-
if (isset($formData['to']) && $formData['to'] !== '') {
95-
$params['endDate'] = $dateTime->date($formData['to'], $timeZone, true, false)->format('Y-m-d');
103+
if (!empty($formData['to'])) {
104+
$params['endDate'] = $this->formatFormSubmittedDate($formData['to']);
96105
}
97106
}
98107

@@ -102,6 +111,39 @@ public function getAnalyticsParams($additional = [])
102111
return array_merge($this->analyticsParams, $additional);
103112
}
104113

114+
/**
115+
* @param string $dateString
116+
* @return string
117+
* @throws NoSuchEntityException
118+
*/
119+
protected function formatFormSubmittedDate(string $dateString): string
120+
{
121+
$timezone = $this->getTimeZone();
122+
$dateTime = $this->parseFormSubmittedDate($dateString, $timezone);
123+
return $dateTime->format(AnalyticsHelper::DATE_FORMAT_API);
124+
}
125+
126+
/**
127+
* @param string|null $dateString
128+
* @param string|null $timezone
129+
* @return \DateTime
130+
* @throws NoSuchEntityException
131+
*/
132+
protected function parseFormSubmittedDate(string $dateString = null, string $timezone = null): \DateTime
133+
{
134+
if (empty($timezone)) {
135+
$timezone = $this->getTimeZone();
136+
}
137+
138+
if (empty($dateString)) {
139+
return new \DateTime('now', new \DateTimeZone($timezone));
140+
}
141+
142+
$dateFormatter = $this->analyticsHelper->getAnalyticsDatePickerFormatter($timezone);
143+
$parsedDate = $dateFormatter->parse($dateString);
144+
return (new \DateTime('now', new \DateTimeZone($timezone)))->setTimestamp($parsedDate);
145+
}
146+
105147
public function getTotalCountOfSearches()
106148
{
107149
return $this->analyticsHelper->getTotalCountOfSearches($this->getAnalyticsParams());
@@ -306,14 +348,15 @@ public function getNoResultSearches()
306348
*
307349
* @return bool
308350
*/
309-
public function checkIsValidDateRange()
351+
public function checkIsValidDateRange(): bool
310352
{
311353
if ($formData = $this->getBackendView()->getBackendSession()->getAlgoliaAnalyticsFormData()) {
312-
if (isset($formData['from']) && !empty($formData['from'])) {
313-
$dateTime = $this->getBackendView()->getDateTime();
314-
$timeZone = $this->getTimeZone();
315-
$startDate = $dateTime->date($formData['from'], $timeZone, true, false);
316-
$diff = date_diff($startDate, $dateTime->date(null, $timeZone, true, null));
354+
if (!empty($formData['from'])) {
355+
$timezone = $this->getTimeZone();
356+
357+
$startDate = $this->parseFormSubmittedDate($formData['from'], $timezone);
358+
$now = $this->parseFormSubmittedDate(null, $timezone);
359+
$diff = date_diff($startDate, $now);
317360

318361
if ($diff->days > $this->getAnalyticRetentionDays()) {
319362
return false;

composer.json

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

0 commit comments

Comments
 (0)