Skip to content

Commit

Permalink
Merge pull request #1466 from algolia/develop
Browse files Browse the repository at this point in the history
release/3.12.1
  • Loading branch information
mohitalgolia authored Jan 10, 2024
2 parents b51c6e9 + 1998c91 commit be7b243
Show file tree
Hide file tree
Showing 16 changed files with 806 additions and 28 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# CHANGE LOG

## 3.12.1

### Updates
- Updated insights library version from 2.6.0 to 2.11.0
- Updated all click events to add authenticatedUserToken for login customer
- Updated view events to add authenticatedUserToken for login customer
- Added German translations in plugin
- Updated code to provide a way for customers to modify timeout values for Algolia PHP Client

### Bug Fixes
- Fixed the issue with recommendations for grouped products in cart page
- Fixed the issue with InstantSearch filters with quotations

## 3.12.0

### Updates
Expand Down
10 changes: 6 additions & 4 deletions Helper/AlgoliaHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Algolia\AlgoliaSearch\Response\AbstractResponse;
use Algolia\AlgoliaSearch\Response\BatchIndexingResponse;
use Algolia\AlgoliaSearch\Response\MultiResponse;
use Algolia\AlgoliaSearch\Config\SearchConfig;
use Algolia\AlgoliaSearch\SearchClient;
use Algolia\AlgoliaSearch\SearchIndex;
use Algolia\AlgoliaSearch\Support\UserAgent;
Expand Down Expand Up @@ -89,10 +90,11 @@ public function getRequest()
public function resetCredentialsFromConfig()
{
if ($this->config->getApplicationID() && $this->config->getAPIKey()) {
$this->client = SearchClient::create(
$this->config->getApplicationID(),
$this->config->getAPIKey()
);
$config = SearchConfig::create($this->config->getApplicationID(), $this->config->getAPIKey());
$config->setConnectTimeout($this->config->getConnectionTimeout());
$config->setReadTimeout($this->config->getReadTimeout());
$config->setWriteTimeout($this->config->getWriteTimeout());
$this->client = SearchClient::createWithConfig($config);
}
}

Expand Down
7 changes: 4 additions & 3 deletions Helper/AnalyticsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ class AnalyticsHelper
private $analyticsConfig;

/**
* Can be changed through DI
* Region can be modified via the Magento configuration
*
* @var string
*/
private $region;
protected $region;

/**
* @param AlgoliaHelper $algoliaHelper
Expand All @@ -77,7 +77,7 @@ public function __construct(
$this->entityHelper = $entityHelper;

$this->logger = $logger;
$this->region = $region;
$this->region = $this->configHelper->getAnalyticsRegion();
}

private function setupAnalyticsClient()
Expand All @@ -86,6 +86,7 @@ private function setupAnalyticsClient()
return;
}


$this->analyticsClient = AnalyticsClient::create(
$this->configHelper->getApplicationID(),
$this->configHelper->getAPIKey(),
Expand Down
44 changes: 44 additions & 0 deletions Helper/ConfigHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ class ConfigHelper
'algoliasearch_advanced/advanced/backend_rendering_allowed_user_agents';
public const NON_CASTABLE_ATTRIBUTES = 'algoliasearch_advanced/advanced/non_castable_attributes';
public const MAX_RECORD_SIZE_LIMIT = 'algoliasearch_advanced/advanced/max_record_size_limit';
public const ANALYTICS_REGION = 'algoliasearch_advanced/advanced/analytics_region';
public const CONNECTION_TIMEOUT = 'algoliasearch_advanced/advanced/connection_timeout';
public const READ_TIMEOUT = 'algoliasearch_advanced/advanced/read_timeout';
public const WRITE_TIMEOUT = 'algoliasearch_advanced/advanced/write_timeout';

public const SHOW_OUT_OF_STOCK = 'cataloginventory/options/show_out_of_stock';

Expand Down Expand Up @@ -1174,6 +1178,33 @@ public function getIndexPrefix($storeId = null)
return $this->configInterface->getValue(self::INDEX_PREFIX, ScopeInterface::SCOPE_STORE, $storeId);
}

/**
* @param $storeId
* @return mixed'
*/
public function getConnectionTimeout($storeId = null)
{
return $this->configInterface->getValue(self::CONNECTION_TIMEOUT, ScopeInterface::SCOPE_STORE, $storeId);
}

/**
* @param $storeId
* @return mixed'
*/
public function getReadTimeout($storeId = null)
{
return $this->configInterface->getValue(self::READ_TIMEOUT, ScopeInterface::SCOPE_STORE, $storeId);
}

/**
* @param $storeId
* @return mixed'
*/
public function getWriteTimeout($storeId = null)
{
return $this->configInterface->getValue(self::WRITE_TIMEOUT, ScopeInterface::SCOPE_STORE, $storeId);
}

/**
* @param $storeId
* @return array|bool|float|int|mixed|string
Expand Down Expand Up @@ -1685,6 +1716,19 @@ public function getMaxRecordSizeLimit($storeId = null)
);
}

/**
* @param $storeId
* @return string
*/
public function getAnalyticsRegion($storeId = null)
{
return $this->configInterface->getValue(
self::ANALYTICS_REGION,
ScopeInterface::SCOPE_STORE,
$storeId
);
}

/**
* @param $storeId
* @return bool
Expand Down
16 changes: 16 additions & 0 deletions Model/Source/AnalyticsRegion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Algolia\AlgoliaSearch\Model\Source;

use Magento\Framework\Option\ArrayInterface;

class AnalyticsRegion implements ArrayInterface
{
public function toOptionArray()
{
return [
['value' => 'us', 'label' => __('United States')],
['value' => 'de', 'label' => __('Europe (Germany)')],
];
}
}
9 changes: 8 additions & 1 deletion Observer/Insights/CustomerLogout.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

class CustomerLogout implements ObserverInterface
{
public const UNSET_AUTHENTICATION_USER_TOKEN_COOKIE_NAME = "unset_authentication_token";
/**
* @var PhpCookieManager
*/
Expand Down Expand Up @@ -42,9 +43,15 @@ public function __construct(
public function execute(\Magento\Framework\Event\Observer $observer)
{
if ($this->cookieManager->getCookie(InsightsHelper::ALGOLIA_CUSTOMER_USER_TOKEN_COOKIE_NAME)) {
$metaDataUnset = $this->cookieMetadataFactory->createPublicCookieMetadata()
->setDurationOneYear()
->setPath('/')
->setHttpOnly(false)
->setSecure(false);
$this->cookieManager->setPublicCookie(self::UNSET_AUTHENTICATION_USER_TOKEN_COOKIE_NAME, 1, $metaDataUnset);
$metadata = $this->cookieMetadataFactory->createCookieMetadata();
$metadata->setPath('/');
$this->cookieManager->deleteCookie(InsightsHelper::ALGOLIA_CUSTOMER_USER_TOKEN_COOKIE_NAME, $metadata);
}
}
}
}
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Algolia Search & Discovery extension for Magento 2
==================================================

![Latest version](https://img.shields.io/badge/latest-3.12.0-green)
![Latest version](https://img.shields.io/badge/latest-3.12.1-green)
![Magento 2](https://img.shields.io/badge/Magento-2.4.x-orange)

![PHP](https://img.shields.io/badge/PHP-8.2%2C8.1%2C7.4-blue)
Expand Down Expand Up @@ -81,7 +81,8 @@ Knowing the version of the library will help you understand what is available in
| v3.x | [0.38.0](https://github.com/algolia/autocomplete.js/tree/v0.38.0) | [4.15.0](https://github.com/algolia/instantsearch.js/tree/v4.15.0) | [1.7.1](https://github.com/algolia/search-insights.js/tree/v1.7.1) | NA |
| v3.9.1 | [1.6.3](https://github.com/algolia/autocomplete.js/tree/v1.6.3) | [4.41.0](https://github.com/algolia/instantsearch.js/tree/v4.41.0) | [1.7.1](https://github.com/algolia/search-insights.js/tree/v1.7.1) | [1.5.0](https://github.com/algolia/recommend/tree/v1.5.0) |
| v3.10.x | [1.6.3](https://github.com/algolia/autocomplete.js/tree/v1.6.3) | [4.41.0](https://github.com/algolia/instantsearch.js/tree/v4.41.0) | [1.7.1](https://github.com/algolia/search-insights.js/tree/v1.7.1) | [1.8.0](https://github.com/algolia/recommend/tree/v1.8.0) |
| >=v3.11.0 | [1.6.3](https://github.com/algolia/autocomplete.js/tree/v1.6.3) | [4.41.0](https://github.com/algolia/instantsearch.js/tree/v4.41.0) | [2.6.0](https://github.com/algolia/search-insights.js/tree/v2.6.0) | [1.8.0](https://github.com/algolia/recommend/tree/v1.8.0) |
| v3.11.0 | [1.6.3](https://github.com/algolia/autocomplete.js/tree/v1.6.3) | [4.41.0](https://github.com/algolia/instantsearch.js/tree/v4.41.0) | [2.6.0](https://github.com/algolia/search-insights.js/tree/v2.6.0) | [1.8.0](https://github.com/algolia/recommend/tree/v1.8.0) |
| >=v3.12.1 | [1.6.3](https://github.com/algolia/autocomplete.js/tree/v1.6.3) | [4.41.0](https://github.com/algolia/instantsearch.js/tree/v4.41.0) | [2.11.0](https://github.com/algolia/search-insights.js/tree/v2.11.0) | [1.8.0](https://github.com/algolia/recommend/tree/v1.8.0) |

The autocomplete and instantsearch libraries are accessible in the `algoliaBundle` global. This bundle is a prepackage javascript file that contains it's dependencies. What is included in this bundle can be seen here:

Expand Down
34 changes: 26 additions & 8 deletions ViewModel/Recommend/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
namespace Algolia\AlgoliaSearch\ViewModel\Recommend;

use Algolia\AlgoliaSearch\Helper\ConfigHelper;
use Algolia\AlgoliaSearch\Helper\Entity\ProductHelper;
use Magento\Checkout\Model\Session;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\View\Element\Block\ArgumentInterface;
use Magento\Framework\View\Element\Template\Context;
use Magento\Store\Model\StoreManagerInterface;

class Cart implements ArgumentInterface
{
Expand All @@ -20,34 +23,49 @@ class Cart implements ArgumentInterface
protected $configHelper;

/**
* @param Context $context
* @var ProductHelper
*/
protected $productHelper;

/**
* @param StoreManagerInterface $storeManager
* @param Session $checkoutSession
* @param ConfigHelper $configHelper
* @param array $data
* @param ProductHelper $productHelper
*/
public function __construct(
Context $context,
StoreManagerInterface $storeManager,
Session $checkoutSession,
ConfigHelper $configHelper,
array $data = []
ProductHelper $productHelper
) {
$this->storeManager = $storeManager;
$this->checkoutSession = $checkoutSession;
$this->configHelper = $configHelper;
$this->productHelper = $productHelper;
}

/**
* @return array
* @throws \Magento\Framework\Exception\LocalizedException
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws LocalizedException
* @throws NoSuchEntityException
*/
public function getAllCartItems()
{
$cartItems = [];
$visibleCartItem = [];
$itemCollection = $this->checkoutSession->getQuote()->getAllVisibleItems();
foreach ($itemCollection as $item) {
$cartItems[] = $item->getProductId();
}
return array_unique($cartItems);
$storeId = $this->storeManager->getStore()->getId();
$cartProductCollection = $this->productHelper->getProductCollectionQuery($storeId, array_unique($cartItems));
if ($cartProductCollection->getSize() > 0 ){
foreach ($cartProductCollection as $product) {
$visibleCartItem[] = $product->getId();
}
}
return $visibleCartItem;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Algolia Search & Discovery extension for Magento 2",
"type": "magento2-module",
"license": ["MIT"],
"version": "3.12.0",
"version": "3.12.1",
"require": {
"magento/framework": "~102.0|~103.0",
"algolia/algoliasearch-client-php": "3.3.2",
Expand Down
19 changes: 16 additions & 3 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@
</field>
</group>
<group id="algolia_cookie_configuration" translate="label" type="text" sortOrder="70" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Algolia Cookie Configuration</label>
<label>Algolia Cookie Configuration</label>
<attribute type="expanded">1</attribute>
<comment>
<![CDATA[
If your Magento cookie settings, specifically <b>General > Web > Default Cookie Settings > Cookie Restriction Mode</b> is set to "No," we will consider it as Implicit Cookie Consent. In this case, the useCookie will be set to True by default for all insight events. Conversely, if <b>Cookie Restriction Mode is set to 'Yes,'</b> Insight events will not be allowed without explicit cookie consent.
]]>
</comment>
</comment>
<field id="default_consent_cookie_name" translate="label comment" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Consent Cookie Name</label>
<comment>
Expand Down Expand Up @@ -1170,7 +1170,7 @@
<field id="customer_groups_enable" translate="label comment" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enable Customer Groups</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<backend_model>Algolia\AlgoliaSearch\Model\Backend\Replica</backend_model>
<backend_model>Algolia\AlgoliaSearch\Model\Backend\Replica</backend_model>
<comment>
<![CDATA[
Do you want to take into account customer groups and display the price of the logged-in group instead of the default price?
Expand Down Expand Up @@ -1259,6 +1259,19 @@
If your Algolia plan allows a higher record size limit, you can customize the record size limit.]]>
</comment>
</field>
<field id="analytics_region" translate="label comment" type="select" sortOrder="96" showInDefault="1">
<label>Analytics Region</label>
<source_model>Algolia\AlgoliaSearch\Model\Source\AnalyticsRegion</source_model>
</field>
<field id="connection_timeout" translate="label comment" type="text" sortOrder="100" showInDefault="1">
<label>Connection Timeout (In Seconds)</label>
</field>
<field id="read_timeout" translate="label comment" type="text" sortOrder="105" showInDefault="1">
<label>Read Timeout (In Seconds)</label>
</field>
<field id="write_timeout" translate="label comment" type="text" sortOrder="110" showInDefault="1">
<label>Write Timeout (In Seconds)</label>
</field>
</group>
<group id="queue" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Indexing Queue</label>
Expand Down
4 changes: 4 additions & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@
<algoliasearch_advanced>
<advanced>
<max_record_size_limit>10000</max_record_size_limit>
<analytics_region>us</analytics_region>
<connection_timeout>2</connection_timeout>
<read_timeout>30</read_timeout>
<write_timeout>30</write_timeout>
</advanced>
<queue>
<number_of_element_by_page>300</number_of_element_by_page>
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Algolia_AlgoliaSearch" setup_version="3.12.0">
<module name="Algolia_AlgoliaSearch" setup_version="3.12.1">
<sequence>
<module name="Magento_Theme"/>
<module name="Magento_Backend"/>
Expand Down
Loading

0 comments on commit be7b243

Please sign in to comment.