Skip to content

Commit

Permalink
Merge pull request #1281 from algolia/release/3.9.1
Browse files Browse the repository at this point in the history
Release/3.9.1
  • Loading branch information
mohitalgolia authored Nov 30, 2022
2 parents f5d7f97 + d681ac5 commit 8fae416
Show file tree
Hide file tree
Showing 31 changed files with 1,676 additions and 801 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ dev/bin/auth.json
composer.lock
vendor/
.php_cs.cache
.vscode
129 changes: 104 additions & 25 deletions Block/Algolia.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
use Algolia\AlgoliaSearch\Helper\Data as CoreHelper;
use Algolia\AlgoliaSearch\Helper\Entity\CategoryHelper;
use Algolia\AlgoliaSearch\Helper\Entity\ProductHelper;
use Algolia\AlgoliaSearch\Helper\Entity\SuggestionHelper;
use Algolia\AlgoliaSearch\Helper\LandingPageHelper;
use Magento\Catalog\Model\Product;
use Magento\Checkout\Model\Session as CheckoutSession;
use Magento\Customer\Model\Context as CustomerContext;
use Magento\Framework\App\ActionInterface;
Expand All @@ -21,29 +23,103 @@
use Magento\Framework\Stdlib\DateTime\DateTime;
use Magento\Framework\Url\Helper\Data;
use Magento\Framework\View\Element\Template;
use Magento\Sales\Model\Order;
use Magento\Search\Helper\Data as CatalogSearchHelper;

class Algolia extends Template implements CollectionDataSourceInterface
{
private $config;
private $catalogSearchHelper;
private $registry;
private $productHelper;
private $currency;
private $format;
private $algoliaHelper;
private $urlHelper;
private $formKey;
private $httpContext;
private $coreHelper;
private $categoryHelper;
private $landingPageHelper;
private $personalizationHelper;
private $checkoutSession;
private $date;

private $priceKey;
/**
* @var ConfigHelper
*/
protected $config;
/**
* @var CatalogSearchHelper
*/
protected $catalogSearchHelper;
/**
* @var Registry
*/
protected $registry;
/**
* @var ProductHelper
*/
protected $productHelper;
/**
* @var Currency
*/
protected $currency;
/**
* @var Format
*/
protected $format;
/**
* @var AlgoliaHelper
*/
protected $algoliaHelper;
/**
* @var Data
*/
protected $urlHelper;
/**
* @var FormKey
*/
protected $formKey;
/**
* @var HttpContext
*/
protected $httpContext;
/**
* @var CoreHelper
*/
protected $coreHelper;
/**
* @var CategoryHelper
*/
protected $categoryHelper;
/**
* @var SuggestionHelper
*/
protected $suggestionHelper;
/**
* @var LandingPageHelper
*/
protected $landingPageHelper;
/**
* @var PersonalizationHelper
*/
protected $personalizationHelper;
/**
* @var CheckoutSession
*/
protected $checkoutSession;
/**
* @var DateTime
*/
protected $date;

protected $priceKey;

/**
* @param Template\Context $context
* @param ConfigHelper $config
* @param CatalogSearchHelper $catalogSearchHelper
* @param ProductHelper $productHelper
* @param Currency $currency
* @param Format $format
* @param Registry $registry
* @param AlgoliaHelper $algoliaHelper
* @param Data $urlHelper
* @param FormKey $formKey
* @param HttpContext $httpContext
* @param CoreHelper $coreHelper
* @param CategoryHelper $categoryHelper
* @param SuggestionHelper $suggestionHelper
* @param LandingPageHelper $landingPageHelper
* @param PersonalizationHelper $personalizationHelper
* @param CheckoutSession $checkoutSession
* @param DateTime $date
* @param array $data
*/
public function __construct(
Template\Context $context,
ConfigHelper $config,
Expand All @@ -58,6 +134,7 @@ public function __construct(
HttpContext $httpContext,
CoreHelper $coreHelper,
CategoryHelper $categoryHelper,
SuggestionHelper $suggestionHelper,
LandingPageHelper $landingPageHelper,
PersonalizationHelper $personalizationHelper,
CheckoutSession $checkoutSession,
Expand All @@ -76,6 +153,7 @@ public function __construct(
$this->httpContext = $httpContext;
$this->coreHelper = $coreHelper;
$this->categoryHelper = $categoryHelper;
$this->suggestionHelper = $suggestionHelper;
$this->landingPageHelper = $landingPageHelper;
$this->personalizationHelper = $personalizationHelper;
$this->checkoutSession = $checkoutSession;
Expand Down Expand Up @@ -115,6 +193,11 @@ public function getCategoryHelper()
return $this->categoryHelper;
}

public function getSuggestionHelper()
{
return $this->suggestionHelper;
}

public function getCatalogSearchHelper()
{
return $this->catalogSearchHelper;
Expand Down Expand Up @@ -175,13 +258,13 @@ public function getCurrentCategory()
return $this->registry->registry('current_category');
}

/** @return \Magento\Catalog\Model\Product */
/** @return Product */
public function getCurrentProduct()
{
return $this->registry->registry('product');
}

/** @return \Magento\Sales\Model\Order */
/** @return Order */
public function getLastOrder()
{
return $this->checkoutSession->getLastRealOrder();
Expand All @@ -202,20 +285,17 @@ public function getTimestamp()
return $this->date->gmtTimestamp('today midnight');
}

private function getAddToCartUrl($additional = [])
protected function getAddToCartUrl($additional = [])
{
$continueUrl = $this->urlHelper->getEncodedUrl($this->_urlBuilder->getCurrentUrl());
$urlParamName = ActionInterface::PARAM_NAME_URL_ENCODED;

$routeParams = [
$urlParamName => $continueUrl,
'_secure' => $this->algoliaHelper->getRequest()->isSecure(),
];

if ($additional !== []) {
$routeParams = array_merge($routeParams, $additional);
}

return $this->_urlBuilder->getUrl('checkout/cart/add', $routeParams);
}

Expand All @@ -225,7 +305,6 @@ protected function getCurrentLandingPage()
if (!$landingPageId) {
return null;
}

return $this->landingPageHelper->getLandingPage($landingPageId);
}
}
25 changes: 13 additions & 12 deletions Block/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public function getConfiguration()

$categoryHelper = $this->getCategoryHelper();

$suggestionHelper = $this->getSuggestionHelper();

$productHelper = $this->getProductHelper();

$algoliaHelper = $this->getAlgoliaHelper();
Expand Down Expand Up @@ -213,6 +215,7 @@ public function getConfiguration()
'priceFormat' => $priceFormat,
'maxValuesPerFacet' => (int) $config->getMaxValuesPerFacet(),
'autofocus' => true,
'resultPageUrl' => $this->getCatalogSearchHelper()->getResultUrl(),
'request' => [
'query' => html_entity_decode($query),
'refinementKey' => $refinementKey,
Expand All @@ -225,10 +228,10 @@ public function getConfiguration()
'showCatsNotIncludedInNavigation' => $config->showCatsNotIncludedInNavigation(),
'showSuggestionsOnNoResultsPage' => $config->showSuggestionsOnNoResultsPage(),
'baseUrl' => $baseUrl,
'popularQueries' => $config->getPopularQueries(),
'popularQueries' => $suggestionHelper->getPopularQueries($this->getStoreId()),
'useAdaptiveImage' => $config->useAdaptiveImage(),
'urls' => [
'logo' => $this->getViewFileUrl('Algolia_AlgoliaSearch::images/search-by-algolia.svg'),
'logo' => $this->getViewFileUrl('Algolia_AlgoliaSearch::images/algolia-logo-blue.svg'),
],
'ccAnalytics' => [
'enabled' => $config->isClickConversionAnalyticsEnabled(),
Expand Down Expand Up @@ -305,17 +308,15 @@ public function getConfiguration()

$transport = new DataObject($algoliaJsConfig);
$this->_eventManager->dispatch('algolia_after_create_configuration', ['configuration' => $transport]);
$algoliaJsConfig = $transport->getData();

return $algoliaJsConfig;
return $transport->getData();
}

private function areCategoriesInFacets($facets)
protected function areCategoriesInFacets($facets)
{
return in_array('categories', array_column($facets, 'attribute'));
}

private function getUrlTrackedParameters()
protected function getUrlTrackedParameters()
{
$urlTrackedParameters = ['query', 'attribute:*', 'index'];

Expand All @@ -326,7 +327,7 @@ private function getUrlTrackedParameters()
return $urlTrackedParameters;
}

private function getOrderedProductIds(ConfigHelper $configHelper, Http $request)
protected function getOrderedProductIds(ConfigHelper $configHelper, Http $request)
{
$ids = [];

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

private function isLandingPage()
protected function isLandingPage()
{
return $this->getRequest()->getFullActionName() === 'algolia_landingpage_view';
}

private function getLandingPageId()
protected function getLandingPageId()
{
return $this->isLandingPage() ? $this->getCurrentLandingPage()->getId() : '';
}

private function getLandingPageQuery()
protected function getLandingPageQuery()
{
return $this->isLandingPage() ? $this->getCurrentLandingPage()->getQuery() : '';
}

private function getLandingPageConfiguration()
protected function getLandingPageConfiguration()
{
return $this->isLandingPage() ? $this->getCurrentLandingPage()->getConfiguration() : json_encode([]);
}
Expand Down
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# CHANGE LOG

## 3.9.1

### UPDATES
- 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.
- 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
- Refactored the casting Attributes
- Managing Max record size via the admin


### FIXES
- Autocomplete category links not preselecting facets on the target URL
- Fixed bug related to conjunctive facets and adaptive images in autocomplete
- Fixed issue with showing __empty__ in the url if autocomplete was disabled
- Fixed autocomplete suggestions
- Instant search fixes when the price was set to retrievable = 'no'
- Price attribute fixes in autocomplete when the price attribute is set to Non-Retrievable
- Add to cart triggering duplicate view event for the Algolia recommend products
- Issues while saving and loading data by the wrong cache key for the popular queries
- Issues with max_retries in clear old jobs function in the queue
- Place Order duplicate Conversion issue for Grouped Product
- Fixes issues with store-specific category index



## 3.9.0

### New Features
Expand Down
19 changes: 16 additions & 3 deletions Helper/AlgoliaHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,7 @@ private function prepareRecords(&$objects, $indexName)
private function getMaxRecordSize()
{
if (!$this->maxRecordSize) {
$this->maxRecordSize = $this->config->getMaxRecordSizeLimit()
? $this->config->getMaxRecordSizeLimit() : $this->config->getDefaultMaxRecordSize();
$this->maxRecordSize = $this->config->getMaxRecordSizeLimit();
}

return $this->maxRecordSize;
Expand Down Expand Up @@ -611,13 +610,27 @@ private function castRecord($object)
return $object;
}

/**
* This method serves to prevent parse of float values that exceed PHP_FLOAT_MAX as INF will break
* JSON encoding.
*
* To further customize the handling of values that may be incorrectly interpreted as numeric by
* PHP you can implement an "after" plugin on this method.
*
* @param $value - what PHP thinks is a floating point number
* @return bool
*/
public function isValidFloat(string $value) : bool {
return floatval($value) !== INF;
}

private function castAttribute($value)
{
if (is_numeric($value) && floatval($value) === floatval((int) $value)) {
return (int) $value;
}

if (is_numeric($value)) {
if (is_numeric($value) && $this->isValidFloat($value)) {
return floatval($value);
}

Expand Down
Loading

0 comments on commit 8fae416

Please sign in to comment.