Skip to content

Commit 8fae416

Browse files
authored
Merge pull request #1281 from algolia/release/3.9.1
Release/3.9.1
2 parents f5d7f97 + d681ac5 commit 8fae416

31 files changed

+1676
-801
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ dev/bin/auth.json
33
composer.lock
44
vendor/
55
.php_cs.cache
6+
.vscode

Block/Algolia.php

Lines changed: 104 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
use Algolia\AlgoliaSearch\Helper\Data as CoreHelper;
99
use Algolia\AlgoliaSearch\Helper\Entity\CategoryHelper;
1010
use Algolia\AlgoliaSearch\Helper\Entity\ProductHelper;
11+
use Algolia\AlgoliaSearch\Helper\Entity\SuggestionHelper;
1112
use Algolia\AlgoliaSearch\Helper\LandingPageHelper;
13+
use Magento\Catalog\Model\Product;
1214
use Magento\Checkout\Model\Session as CheckoutSession;
1315
use Magento\Customer\Model\Context as CustomerContext;
1416
use Magento\Framework\App\ActionInterface;
@@ -21,29 +23,103 @@
2123
use Magento\Framework\Stdlib\DateTime\DateTime;
2224
use Magento\Framework\Url\Helper\Data;
2325
use Magento\Framework\View\Element\Template;
26+
use Magento\Sales\Model\Order;
2427
use Magento\Search\Helper\Data as CatalogSearchHelper;
2528

2629
class Algolia extends Template implements CollectionDataSourceInterface
2730
{
28-
private $config;
29-
private $catalogSearchHelper;
30-
private $registry;
31-
private $productHelper;
32-
private $currency;
33-
private $format;
34-
private $algoliaHelper;
35-
private $urlHelper;
36-
private $formKey;
37-
private $httpContext;
38-
private $coreHelper;
39-
private $categoryHelper;
40-
private $landingPageHelper;
41-
private $personalizationHelper;
42-
private $checkoutSession;
43-
private $date;
44-
45-
private $priceKey;
31+
/**
32+
* @var ConfigHelper
33+
*/
34+
protected $config;
35+
/**
36+
* @var CatalogSearchHelper
37+
*/
38+
protected $catalogSearchHelper;
39+
/**
40+
* @var Registry
41+
*/
42+
protected $registry;
43+
/**
44+
* @var ProductHelper
45+
*/
46+
protected $productHelper;
47+
/**
48+
* @var Currency
49+
*/
50+
protected $currency;
51+
/**
52+
* @var Format
53+
*/
54+
protected $format;
55+
/**
56+
* @var AlgoliaHelper
57+
*/
58+
protected $algoliaHelper;
59+
/**
60+
* @var Data
61+
*/
62+
protected $urlHelper;
63+
/**
64+
* @var FormKey
65+
*/
66+
protected $formKey;
67+
/**
68+
* @var HttpContext
69+
*/
70+
protected $httpContext;
71+
/**
72+
* @var CoreHelper
73+
*/
74+
protected $coreHelper;
75+
/**
76+
* @var CategoryHelper
77+
*/
78+
protected $categoryHelper;
79+
/**
80+
* @var SuggestionHelper
81+
*/
82+
protected $suggestionHelper;
83+
/**
84+
* @var LandingPageHelper
85+
*/
86+
protected $landingPageHelper;
87+
/**
88+
* @var PersonalizationHelper
89+
*/
90+
protected $personalizationHelper;
91+
/**
92+
* @var CheckoutSession
93+
*/
94+
protected $checkoutSession;
95+
/**
96+
* @var DateTime
97+
*/
98+
protected $date;
99+
100+
protected $priceKey;
46101

102+
/**
103+
* @param Template\Context $context
104+
* @param ConfigHelper $config
105+
* @param CatalogSearchHelper $catalogSearchHelper
106+
* @param ProductHelper $productHelper
107+
* @param Currency $currency
108+
* @param Format $format
109+
* @param Registry $registry
110+
* @param AlgoliaHelper $algoliaHelper
111+
* @param Data $urlHelper
112+
* @param FormKey $formKey
113+
* @param HttpContext $httpContext
114+
* @param CoreHelper $coreHelper
115+
* @param CategoryHelper $categoryHelper
116+
* @param SuggestionHelper $suggestionHelper
117+
* @param LandingPageHelper $landingPageHelper
118+
* @param PersonalizationHelper $personalizationHelper
119+
* @param CheckoutSession $checkoutSession
120+
* @param DateTime $date
121+
* @param array $data
122+
*/
47123
public function __construct(
48124
Template\Context $context,
49125
ConfigHelper $config,
@@ -58,6 +134,7 @@ public function __construct(
58134
HttpContext $httpContext,
59135
CoreHelper $coreHelper,
60136
CategoryHelper $categoryHelper,
137+
SuggestionHelper $suggestionHelper,
61138
LandingPageHelper $landingPageHelper,
62139
PersonalizationHelper $personalizationHelper,
63140
CheckoutSession $checkoutSession,
@@ -76,6 +153,7 @@ public function __construct(
76153
$this->httpContext = $httpContext;
77154
$this->coreHelper = $coreHelper;
78155
$this->categoryHelper = $categoryHelper;
156+
$this->suggestionHelper = $suggestionHelper;
79157
$this->landingPageHelper = $landingPageHelper;
80158
$this->personalizationHelper = $personalizationHelper;
81159
$this->checkoutSession = $checkoutSession;
@@ -115,6 +193,11 @@ public function getCategoryHelper()
115193
return $this->categoryHelper;
116194
}
117195

196+
public function getSuggestionHelper()
197+
{
198+
return $this->suggestionHelper;
199+
}
200+
118201
public function getCatalogSearchHelper()
119202
{
120203
return $this->catalogSearchHelper;
@@ -175,13 +258,13 @@ public function getCurrentCategory()
175258
return $this->registry->registry('current_category');
176259
}
177260

178-
/** @return \Magento\Catalog\Model\Product */
261+
/** @return Product */
179262
public function getCurrentProduct()
180263
{
181264
return $this->registry->registry('product');
182265
}
183266

184-
/** @return \Magento\Sales\Model\Order */
267+
/** @return Order */
185268
public function getLastOrder()
186269
{
187270
return $this->checkoutSession->getLastRealOrder();
@@ -202,20 +285,17 @@ public function getTimestamp()
202285
return $this->date->gmtTimestamp('today midnight');
203286
}
204287

205-
private function getAddToCartUrl($additional = [])
288+
protected function getAddToCartUrl($additional = [])
206289
{
207290
$continueUrl = $this->urlHelper->getEncodedUrl($this->_urlBuilder->getCurrentUrl());
208291
$urlParamName = ActionInterface::PARAM_NAME_URL_ENCODED;
209-
210292
$routeParams = [
211293
$urlParamName => $continueUrl,
212294
'_secure' => $this->algoliaHelper->getRequest()->isSecure(),
213295
];
214-
215296
if ($additional !== []) {
216297
$routeParams = array_merge($routeParams, $additional);
217298
}
218-
219299
return $this->_urlBuilder->getUrl('checkout/cart/add', $routeParams);
220300
}
221301

@@ -225,7 +305,6 @@ protected function getCurrentLandingPage()
225305
if (!$landingPageId) {
226306
return null;
227307
}
228-
229308
return $this->landingPageHelper->getLandingPage($landingPageId);
230309
}
231310
}

Block/Configuration.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public function getConfiguration()
4040

4141
$categoryHelper = $this->getCategoryHelper();
4242

43+
$suggestionHelper = $this->getSuggestionHelper();
44+
4345
$productHelper = $this->getProductHelper();
4446

4547
$algoliaHelper = $this->getAlgoliaHelper();
@@ -213,6 +215,7 @@ public function getConfiguration()
213215
'priceFormat' => $priceFormat,
214216
'maxValuesPerFacet' => (int) $config->getMaxValuesPerFacet(),
215217
'autofocus' => true,
218+
'resultPageUrl' => $this->getCatalogSearchHelper()->getResultUrl(),
216219
'request' => [
217220
'query' => html_entity_decode($query),
218221
'refinementKey' => $refinementKey,
@@ -225,10 +228,10 @@ public function getConfiguration()
225228
'showCatsNotIncludedInNavigation' => $config->showCatsNotIncludedInNavigation(),
226229
'showSuggestionsOnNoResultsPage' => $config->showSuggestionsOnNoResultsPage(),
227230
'baseUrl' => $baseUrl,
228-
'popularQueries' => $config->getPopularQueries(),
231+
'popularQueries' => $suggestionHelper->getPopularQueries($this->getStoreId()),
229232
'useAdaptiveImage' => $config->useAdaptiveImage(),
230233
'urls' => [
231-
'logo' => $this->getViewFileUrl('Algolia_AlgoliaSearch::images/search-by-algolia.svg'),
234+
'logo' => $this->getViewFileUrl('Algolia_AlgoliaSearch::images/algolia-logo-blue.svg'),
232235
],
233236
'ccAnalytics' => [
234237
'enabled' => $config->isClickConversionAnalyticsEnabled(),
@@ -305,17 +308,15 @@ public function getConfiguration()
305308

306309
$transport = new DataObject($algoliaJsConfig);
307310
$this->_eventManager->dispatch('algolia_after_create_configuration', ['configuration' => $transport]);
308-
$algoliaJsConfig = $transport->getData();
309-
310-
return $algoliaJsConfig;
311+
return $transport->getData();
311312
}
312313

313-
private function areCategoriesInFacets($facets)
314+
protected function areCategoriesInFacets($facets)
314315
{
315316
return in_array('categories', array_column($facets, 'attribute'));
316317
}
317318

318-
private function getUrlTrackedParameters()
319+
protected function getUrlTrackedParameters()
319320
{
320321
$urlTrackedParameters = ['query', 'attribute:*', 'index'];
321322

@@ -326,7 +327,7 @@ private function getUrlTrackedParameters()
326327
return $urlTrackedParameters;
327328
}
328329

329-
private function getOrderedProductIds(ConfigHelper $configHelper, Http $request)
330+
protected function getOrderedProductIds(ConfigHelper $configHelper, Http $request)
330331
{
331332
$ids = [];
332333

@@ -349,22 +350,22 @@ private function getOrderedProductIds(ConfigHelper $configHelper, Http $request)
349350
return $ids;
350351
}
351352

352-
private function isLandingPage()
353+
protected function isLandingPage()
353354
{
354355
return $this->getRequest()->getFullActionName() === 'algolia_landingpage_view';
355356
}
356357

357-
private function getLandingPageId()
358+
protected function getLandingPageId()
358359
{
359360
return $this->isLandingPage() ? $this->getCurrentLandingPage()->getId() : '';
360361
}
361362

362-
private function getLandingPageQuery()
363+
protected function getLandingPageQuery()
363364
{
364365
return $this->isLandingPage() ? $this->getCurrentLandingPage()->getQuery() : '';
365366
}
366367

367-
private function getLandingPageConfiguration()
368+
protected function getLandingPageConfiguration()
368369
{
369370
return $this->isLandingPage() ? $this->getCurrentLandingPage()->getConfiguration() : json_encode([]);
370371
}

CHANGELOG.md

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

3+
## 3.9.1
4+
5+
### UPDATES
6+
- Refactored the Autocomplete to provide an extensible model for function-based templates by utilizing tagged template literals. The approach supports the use of RequireJS mixins for overriding the template functionality.
7+
- Update the synonym area notice in the Magento admin to point customers to use the Algolia dashboard for Synonym management as Magento Dashboard will be deprecated in a future release
8+
- Refactored the casting Attributes
9+
- Managing Max record size via the admin
10+
11+
12+
### FIXES
13+
- Autocomplete category links not preselecting facets on the target URL
14+
- Fixed bug related to conjunctive facets and adaptive images in autocomplete
15+
- Fixed issue with showing __empty__ in the url if autocomplete was disabled
16+
- Fixed autocomplete suggestions
17+
- Instant search fixes when the price was set to retrievable = 'no'
18+
- Price attribute fixes in autocomplete when the price attribute is set to Non-Retrievable
19+
- Add to cart triggering duplicate view event for the Algolia recommend products
20+
- Issues while saving and loading data by the wrong cache key for the popular queries
21+
- Issues with max_retries in clear old jobs function in the queue
22+
- Place Order duplicate Conversion issue for Grouped Product
23+
- Fixes issues with store-specific category index
24+
25+
26+
327
## 3.9.0
428

529
### New Features

Helper/AlgoliaHelper.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,8 +502,7 @@ private function prepareRecords(&$objects, $indexName)
502502
private function getMaxRecordSize()
503503
{
504504
if (!$this->maxRecordSize) {
505-
$this->maxRecordSize = $this->config->getMaxRecordSizeLimit()
506-
? $this->config->getMaxRecordSizeLimit() : $this->config->getDefaultMaxRecordSize();
505+
$this->maxRecordSize = $this->config->getMaxRecordSizeLimit();
507506
}
508507

509508
return $this->maxRecordSize;
@@ -611,13 +610,27 @@ private function castRecord($object)
611610
return $object;
612611
}
613612

613+
/**
614+
* This method serves to prevent parse of float values that exceed PHP_FLOAT_MAX as INF will break
615+
* JSON encoding.
616+
*
617+
* To further customize the handling of values that may be incorrectly interpreted as numeric by
618+
* PHP you can implement an "after" plugin on this method.
619+
*
620+
* @param $value - what PHP thinks is a floating point number
621+
* @return bool
622+
*/
623+
public function isValidFloat(string $value) : bool {
624+
return floatval($value) !== INF;
625+
}
626+
614627
private function castAttribute($value)
615628
{
616629
if (is_numeric($value) && floatval($value) === floatval((int) $value)) {
617630
return (int) $value;
618631
}
619632

620-
if (is_numeric($value)) {
633+
if (is_numeric($value) && $this->isValidFloat($value)) {
621634
return floatval($value);
622635
}
623636

0 commit comments

Comments
 (0)