Skip to content

Commit be7b243

Browse files
authored
Merge pull request #1466 from algolia/develop
release/3.12.1
2 parents b51c6e9 + 1998c91 commit be7b243

File tree

16 files changed

+806
-28
lines changed

16 files changed

+806
-28
lines changed

CHANGELOG.md

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

3+
## 3.12.1
4+
5+
### Updates
6+
- Updated insights library version from 2.6.0 to 2.11.0
7+
- Updated all click events to add authenticatedUserToken for login customer
8+
- Updated view events to add authenticatedUserToken for login customer
9+
- Added German translations in plugin
10+
- Updated code to provide a way for customers to modify timeout values for Algolia PHP Client
11+
12+
### Bug Fixes
13+
- Fixed the issue with recommendations for grouped products in cart page
14+
- Fixed the issue with InstantSearch filters with quotations
15+
316
## 3.12.0
417

518
### Updates

Helper/AlgoliaHelper.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Algolia\AlgoliaSearch\Response\AbstractResponse;
77
use Algolia\AlgoliaSearch\Response\BatchIndexingResponse;
88
use Algolia\AlgoliaSearch\Response\MultiResponse;
9+
use Algolia\AlgoliaSearch\Config\SearchConfig;
910
use Algolia\AlgoliaSearch\SearchClient;
1011
use Algolia\AlgoliaSearch\SearchIndex;
1112
use Algolia\AlgoliaSearch\Support\UserAgent;
@@ -89,10 +90,11 @@ public function getRequest()
8990
public function resetCredentialsFromConfig()
9091
{
9192
if ($this->config->getApplicationID() && $this->config->getAPIKey()) {
92-
$this->client = SearchClient::create(
93-
$this->config->getApplicationID(),
94-
$this->config->getAPIKey()
95-
);
93+
$config = SearchConfig::create($this->config->getApplicationID(), $this->config->getAPIKey());
94+
$config->setConnectTimeout($this->config->getConnectionTimeout());
95+
$config->setReadTimeout($this->config->getReadTimeout());
96+
$config->setWriteTimeout($this->config->getWriteTimeout());
97+
$this->client = SearchClient::createWithConfig($config);
9698
}
9799
}
98100

Helper/AnalyticsHelper.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ class AnalyticsHelper
5151
private $analyticsConfig;
5252

5353
/**
54-
* Can be changed through DI
54+
* Region can be modified via the Magento configuration
5555
*
5656
* @var string
5757
*/
58-
private $region;
58+
protected $region;
5959

6060
/**
6161
* @param AlgoliaHelper $algoliaHelper
@@ -77,7 +77,7 @@ public function __construct(
7777
$this->entityHelper = $entityHelper;
7878

7979
$this->logger = $logger;
80-
$this->region = $region;
80+
$this->region = $this->configHelper->getAnalyticsRegion();
8181
}
8282

8383
private function setupAnalyticsClient()
@@ -86,6 +86,7 @@ private function setupAnalyticsClient()
8686
return;
8787
}
8888

89+
8990
$this->analyticsClient = AnalyticsClient::create(
9091
$this->configHelper->getApplicationID(),
9192
$this->configHelper->getAPIKey(),

Helper/ConfigHelper.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ class ConfigHelper
100100
'algoliasearch_advanced/advanced/backend_rendering_allowed_user_agents';
101101
public const NON_CASTABLE_ATTRIBUTES = 'algoliasearch_advanced/advanced/non_castable_attributes';
102102
public const MAX_RECORD_SIZE_LIMIT = 'algoliasearch_advanced/advanced/max_record_size_limit';
103+
public const ANALYTICS_REGION = 'algoliasearch_advanced/advanced/analytics_region';
104+
public const CONNECTION_TIMEOUT = 'algoliasearch_advanced/advanced/connection_timeout';
105+
public const READ_TIMEOUT = 'algoliasearch_advanced/advanced/read_timeout';
106+
public const WRITE_TIMEOUT = 'algoliasearch_advanced/advanced/write_timeout';
103107

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

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

1181+
/**
1182+
* @param $storeId
1183+
* @return mixed'
1184+
*/
1185+
public function getConnectionTimeout($storeId = null)
1186+
{
1187+
return $this->configInterface->getValue(self::CONNECTION_TIMEOUT, ScopeInterface::SCOPE_STORE, $storeId);
1188+
}
1189+
1190+
/**
1191+
* @param $storeId
1192+
* @return mixed'
1193+
*/
1194+
public function getReadTimeout($storeId = null)
1195+
{
1196+
return $this->configInterface->getValue(self::READ_TIMEOUT, ScopeInterface::SCOPE_STORE, $storeId);
1197+
}
1198+
1199+
/**
1200+
* @param $storeId
1201+
* @return mixed'
1202+
*/
1203+
public function getWriteTimeout($storeId = null)
1204+
{
1205+
return $this->configInterface->getValue(self::WRITE_TIMEOUT, ScopeInterface::SCOPE_STORE, $storeId);
1206+
}
1207+
11771208
/**
11781209
* @param $storeId
11791210
* @return array|bool|float|int|mixed|string
@@ -1685,6 +1716,19 @@ public function getMaxRecordSizeLimit($storeId = null)
16851716
);
16861717
}
16871718

1719+
/**
1720+
* @param $storeId
1721+
* @return string
1722+
*/
1723+
public function getAnalyticsRegion($storeId = null)
1724+
{
1725+
return $this->configInterface->getValue(
1726+
self::ANALYTICS_REGION,
1727+
ScopeInterface::SCOPE_STORE,
1728+
$storeId
1729+
);
1730+
}
1731+
16881732
/**
16891733
* @param $storeId
16901734
* @return bool

Model/Source/AnalyticsRegion.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Algolia\AlgoliaSearch\Model\Source;
4+
5+
use Magento\Framework\Option\ArrayInterface;
6+
7+
class AnalyticsRegion implements ArrayInterface
8+
{
9+
public function toOptionArray()
10+
{
11+
return [
12+
['value' => 'us', 'label' => __('United States')],
13+
['value' => 'de', 'label' => __('Europe (Germany)')],
14+
];
15+
}
16+
}

Observer/Insights/CustomerLogout.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
class CustomerLogout implements ObserverInterface
1111
{
12+
public const UNSET_AUTHENTICATION_USER_TOKEN_COOKIE_NAME = "unset_authentication_token";
1213
/**
1314
* @var PhpCookieManager
1415
*/
@@ -42,9 +43,15 @@ public function __construct(
4243
public function execute(\Magento\Framework\Event\Observer $observer)
4344
{
4445
if ($this->cookieManager->getCookie(InsightsHelper::ALGOLIA_CUSTOMER_USER_TOKEN_COOKIE_NAME)) {
46+
$metaDataUnset = $this->cookieMetadataFactory->createPublicCookieMetadata()
47+
->setDurationOneYear()
48+
->setPath('/')
49+
->setHttpOnly(false)
50+
->setSecure(false);
51+
$this->cookieManager->setPublicCookie(self::UNSET_AUTHENTICATION_USER_TOKEN_COOKIE_NAME, 1, $metaDataUnset);
4552
$metadata = $this->cookieMetadataFactory->createCookieMetadata();
4653
$metadata->setPath('/');
4754
$this->cookieManager->deleteCookie(InsightsHelper::ALGOLIA_CUSTOMER_USER_TOKEN_COOKIE_NAME, $metadata);
4855
}
4956
}
50-
}
57+
}

README.md

Lines changed: 3 additions & 2 deletions
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.12.0-green)
4+
![Latest version](https://img.shields.io/badge/latest-3.12.1-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)
@@ -81,7 +81,8 @@ Knowing the version of the library will help you understand what is available in
8181
| 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 |
8282
| 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) |
8383
| 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) |
84-
| >=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) |
84+
| 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) |
85+
| >=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) |
8586

8687
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:
8788

ViewModel/Recommend/Cart.php

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
namespace Algolia\AlgoliaSearch\ViewModel\Recommend;
44

55
use Algolia\AlgoliaSearch\Helper\ConfigHelper;
6+
use Algolia\AlgoliaSearch\Helper\Entity\ProductHelper;
67
use Magento\Checkout\Model\Session;
8+
use Magento\Framework\Exception\LocalizedException;
9+
use Magento\Framework\Exception\NoSuchEntityException;
710
use Magento\Framework\View\Element\Block\ArgumentInterface;
8-
use Magento\Framework\View\Element\Template\Context;
11+
use Magento\Store\Model\StoreManagerInterface;
912

1013
class Cart implements ArgumentInterface
1114
{
@@ -20,34 +23,49 @@ class Cart implements ArgumentInterface
2023
protected $configHelper;
2124

2225
/**
23-
* @param Context $context
26+
* @var ProductHelper
27+
*/
28+
protected $productHelper;
29+
30+
/**
31+
* @param StoreManagerInterface $storeManager
2432
* @param Session $checkoutSession
2533
* @param ConfigHelper $configHelper
26-
* @param array $data
34+
* @param ProductHelper $productHelper
2735
*/
2836
public function __construct(
29-
Context $context,
37+
StoreManagerInterface $storeManager,
3038
Session $checkoutSession,
3139
ConfigHelper $configHelper,
32-
array $data = []
40+
ProductHelper $productHelper
3341
) {
42+
$this->storeManager = $storeManager;
3443
$this->checkoutSession = $checkoutSession;
3544
$this->configHelper = $configHelper;
45+
$this->productHelper = $productHelper;
3646
}
3747

3848
/**
3949
* @return array
40-
* @throws \Magento\Framework\Exception\LocalizedException
41-
* @throws \Magento\Framework\Exception\NoSuchEntityException
50+
* @throws LocalizedException
51+
* @throws NoSuchEntityException
4252
*/
4353
public function getAllCartItems()
4454
{
4555
$cartItems = [];
56+
$visibleCartItem = [];
4657
$itemCollection = $this->checkoutSession->getQuote()->getAllVisibleItems();
4758
foreach ($itemCollection as $item) {
4859
$cartItems[] = $item->getProductId();
4960
}
50-
return array_unique($cartItems);
61+
$storeId = $this->storeManager->getStore()->getId();
62+
$cartProductCollection = $this->productHelper->getProductCollectionQuery($storeId, array_unique($cartItems));
63+
if ($cartProductCollection->getSize() > 0 ){
64+
foreach ($cartProductCollection as $product) {
65+
$visibleCartItem[] = $product->getId();
66+
}
67+
}
68+
return $visibleCartItem;
5169
}
5270

5371
/**

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.12.0",
6+
"version": "3.12.1",
77
"require": {
88
"magento/framework": "~102.0|~103.0",
99
"algolia/algoliasearch-client-php": "3.3.2",

etc/adminhtml/system.xml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,13 @@
111111
</field>
112112
</group>
113113
<group id="algolia_cookie_configuration" translate="label" type="text" sortOrder="70" showInDefault="1" showInWebsite="1" showInStore="1">
114-
<label>Algolia Cookie Configuration</label>
114+
<label>Algolia Cookie Configuration</label>
115115
<attribute type="expanded">1</attribute>
116116
<comment>
117117
<![CDATA[
118118
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.
119119
]]>
120-
</comment>
120+
</comment>
121121
<field id="default_consent_cookie_name" translate="label comment" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
122122
<label>Consent Cookie Name</label>
123123
<comment>
@@ -1170,7 +1170,7 @@
11701170
<field id="customer_groups_enable" translate="label comment" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
11711171
<label>Enable Customer Groups</label>
11721172
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
1173-
<backend_model>Algolia\AlgoliaSearch\Model\Backend\Replica</backend_model>
1173+
<backend_model>Algolia\AlgoliaSearch\Model\Backend\Replica</backend_model>
11741174
<comment>
11751175
<![CDATA[
11761176
Do you want to take into account customer groups and display the price of the logged-in group instead of the default price?
@@ -1259,6 +1259,19 @@
12591259
If your Algolia plan allows a higher record size limit, you can customize the record size limit.]]>
12601260
</comment>
12611261
</field>
1262+
<field id="analytics_region" translate="label comment" type="select" sortOrder="96" showInDefault="1">
1263+
<label>Analytics Region</label>
1264+
<source_model>Algolia\AlgoliaSearch\Model\Source\AnalyticsRegion</source_model>
1265+
</field>
1266+
<field id="connection_timeout" translate="label comment" type="text" sortOrder="100" showInDefault="1">
1267+
<label>Connection Timeout (In Seconds)</label>
1268+
</field>
1269+
<field id="read_timeout" translate="label comment" type="text" sortOrder="105" showInDefault="1">
1270+
<label>Read Timeout (In Seconds)</label>
1271+
</field>
1272+
<field id="write_timeout" translate="label comment" type="text" sortOrder="110" showInDefault="1">
1273+
<label>Write Timeout (In Seconds)</label>
1274+
</field>
12621275
</group>
12631276
<group id="queue" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
12641277
<label>Indexing Queue</label>

0 commit comments

Comments
 (0)