Skip to content

Commit 00f0683

Browse files
authored
Merge branch 'develop' into feature/MAGE-721
2 parents 2e2b41b + df6bd9a commit 00f0683

26 files changed

+400
-99
lines changed

Block/Algolia.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Algolia\AlgoliaSearch\Helper\Entity\ProductHelper;
1111
use Algolia\AlgoliaSearch\Helper\Entity\SuggestionHelper;
1212
use Algolia\AlgoliaSearch\Helper\LandingPageHelper;
13+
use Algolia\AlgoliaSearch\Registry\CurrentCategory;
1314
use Magento\Catalog\Model\Product;
1415
use Magento\Checkout\Model\Session as CheckoutSession;
1516
use Magento\Customer\Model\Context as CustomerContext;
@@ -97,6 +98,9 @@ class Algolia extends Template implements CollectionDataSourceInterface
9798
*/
9899
protected $date;
99100

101+
/** @var CurrentCategory */
102+
protected CurrentCategory $currentCategory;
103+
100104
protected $priceKey;
101105

102106
/**
@@ -139,6 +143,7 @@ public function __construct(
139143
PersonalizationHelper $personalizationHelper,
140144
CheckoutSession $checkoutSession,
141145
DateTime $date,
146+
CurrentCategory $currentCategory,
142147
array $data = []
143148
) {
144149
$this->config = $config;
@@ -158,6 +163,7 @@ public function __construct(
158163
$this->personalizationHelper = $personalizationHelper;
159164
$this->checkoutSession = $checkoutSession;
160165
$this->date = $date;
166+
$this->currentCategory = $currentCategory;
161167

162168
parent::__construct($context, $data);
163169
}
@@ -255,7 +261,7 @@ public function getStoreId()
255261

256262
public function getCurrentCategory()
257263
{
258-
return $this->registry->registry('current_category');
264+
return $this->currentCategory->get();
259265
}
260266

261267
/** @return Product */

Block/Configuration.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,12 @@ public function getConfiguration()
288288
'urls' => [
289289
'logo' => $this->getViewFileUrl('Algolia_AlgoliaSearch::images/algolia-logo-blue.svg'),
290290
],
291+
'cookieConfiguration' => [
292+
'consentCookieName' => $config->getDefaultConsentCookieName(),
293+
'cookieAllowButtonSelector' => $config->getAllowCookieButtonSelector(),
294+
'cookieRestrictionModeEnabled' => $config->isCookieRestrictionModeEnabled(),
295+
'cookieDuration' =>$config->getAlgoliaCookieDuration()
296+
],
291297
'ccAnalytics' => [
292298
'enabled' => $config->isClickConversionAnalyticsEnabled(),
293299
'ISSelector' => $config->getClickConversionAnalyticsISSelector(),

CHANGELOG.md

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

3+
## 3.12.0
4+
5+
### Updates
6+
- Updated code to consider user’s cookie consent to send events to Algolia by using ‘useCookie’ parameter
7+
- Updated references to [email protected] to new ticket link
8+
- Updated code to refactor the deprecated registry for categories
9+
- Updated code to ensure compatibility with NeuralSearch
10+
- Updated AlgoliaBundle by eliminating the unnecessary jQuery library
11+
- Included the promotion class in autocomplete menu when a product has any promotions
12+
13+
### Bug Fixes
14+
- Fixed formatting issue in product object related to CategoryPageId attribute
15+
- Fixed issue with Clear Refinements button in InstantSearch page
16+
- Fixed issue with custom banner functionality via merchandising dashboard in admin
17+
- Fixed issue with hierarchicalMenu widget when utilizing transformItems when the number of categories exceeded the limit
18+
- Fixed issue with indexing text field attributes with a value of 0
19+
- Fixed issue with user cookies not clearing upon customer logout
20+
- Fixed back button issue with pagination in instant search page and category pages
21+
322
## 3.11.0
423

524
### Updates

Helper/ConfigHelper.php

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Framework\Serialize\SerializerInterface;
1212
use Magento\Store\Model\ScopeInterface;
1313
use Magento\Store\Model\StoreManagerInterface;
14+
use Magento\Cookie\Helper\Cookie as CookieHelper;
1415

1516
class ConfigHelper
1617
{
@@ -23,6 +24,10 @@ class ConfigHelper
2324
public const API_KEY = 'algoliasearch_credentials/credentials/api_key';
2425
public const SEARCH_ONLY_API_KEY = 'algoliasearch_credentials/credentials/search_only_api_key';
2526
public const INDEX_PREFIX = 'algoliasearch_credentials/credentials/index_prefix';
27+
public const COOKIE_DEFAULT_CONSENT_COOKIE_NAME = 'algoliasearch_credentials/algolia_cookie_configuration/default_consent_cookie_name';
28+
public const ALLOW_COOKIE_BUTTON_SELECTOR = 'algoliasearch_credentials/algolia_cookie_configuration/allow_cookie_button_selector';
29+
public const ALGOLIA_COOKIE_DURATION = 'algoliasearch_credentials/algolia_cookie_configuration/cookie_duration';
30+
2631

2732
public const IS_INSTANT_ENABLED = 'algoliasearch_instant/instant/is_instant_enabled';
2833
public const REPLACE_CATEGORIES = 'algoliasearch_instant/instant/replace_categories';
@@ -186,6 +191,11 @@ class ConfigHelper
186191
*/
187192
protected $groupCollection;
188193

194+
/**
195+
* @var CookieHelper
196+
*/
197+
protected $cookieHelper;
198+
189199
/**
190200
* @param Magento\Framework\App\Config\ScopeConfigInterface $configInterface
191201
* @param StoreManagerInterface $storeManager
@@ -197,6 +207,7 @@ class ConfigHelper
197207
* @param Magento\Framework\Event\ManagerInterface $eventManager
198208
* @param SerializerInterface $serializer
199209
* @param GroupCollection $groupCollection
210+
* @param CookieHelper $cookieHelper
200211
*/
201212
public function __construct(
202213
Magento\Framework\App\Config\ScopeConfigInterface $configInterface,
@@ -208,7 +219,8 @@ public function __construct(
208219
Magento\Framework\App\ProductMetadataInterface $productMetadata,
209220
Magento\Framework\Event\ManagerInterface $eventManager,
210221
SerializerInterface $serializer,
211-
GroupCollection $groupCollection
222+
GroupCollection $groupCollection,
223+
CookieHelper $cookieHelper
212224
) {
213225
$this->configInterface = $configInterface;
214226
$this->currency = $currency;
@@ -220,6 +232,7 @@ public function __construct(
220232
$this->eventManager = $eventManager;
221233
$this->serializer = $serializer;
222234
$this->groupCollection = $groupCollection;
235+
$this->cookieHelper = $cookieHelper;
223236
}
224237

225238

@@ -1579,6 +1592,45 @@ public function getConversionAnalyticsAddToCartSelector($storeId = null)
15791592
return $this->configInterface->getValue(self::CC_ADD_TO_CART_SELECTOR, ScopeInterface::SCOPE_STORE, $storeId);
15801593
}
15811594

1595+
/**
1596+
* @param $storeId
1597+
* @return mixed
1598+
*/
1599+
public function getDefaultConsentCookieName($storeId = null)
1600+
{
1601+
return $this->configInterface->getValue(
1602+
self::COOKIE_DEFAULT_CONSENT_COOKIE_NAME,
1603+
ScopeInterface::SCOPE_STORE,
1604+
$storeId
1605+
);
1606+
}
1607+
1608+
/**
1609+
* @param $storeId
1610+
* @return mixed
1611+
*/
1612+
public function getAllowCookieButtonSelector($storeId = null)
1613+
{
1614+
return $this->configInterface->getValue(
1615+
self::ALLOW_COOKIE_BUTTON_SELECTOR,
1616+
ScopeInterface::SCOPE_STORE,
1617+
$storeId
1618+
);
1619+
}
1620+
1621+
/**
1622+
* @param $storeId
1623+
* @return mixed
1624+
*/
1625+
public function getAlgoliaCookieDuration($storeId = null)
1626+
{
1627+
return $this->configInterface->getValue(
1628+
self::ALGOLIA_COOKIE_DURATION,
1629+
ScopeInterface::SCOPE_STORE,
1630+
$storeId
1631+
);
1632+
}
1633+
15821634
/**
15831635
* @param $storeId
15841636
* @return array
@@ -1711,4 +1763,12 @@ public function isAutocompleteNavigatorEnabled($storeId = null)
17111763
$storeId
17121764
);
17131765
}
1766+
1767+
/**
1768+
* @return bool
1769+
*/
1770+
public function isCookieRestrictionModeEnabled()
1771+
{
1772+
return (bool)$this->cookieHelper->isCookieRestrictionModeEnabled();
1773+
}
17141774
}

Helper/Configuration/NoticeHelper.php

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

4950
/** @var array[] */
@@ -207,6 +208,27 @@ protected function getClickAnalyticsNotice()
207208
'message' => $noticeContent,
208209
];
209210
}
211+
212+
protected function getCookieConfigurationNotice()
213+
{
214+
$noticeContent = '';
215+
$selector = '';
216+
$method = 'after';
217+
218+
// If the feature is enabled in the Algolia dashboard but not activated on the Magento Admin
219+
$noticeContent = '
220+
<div class="algolia_block_cookie">
221+
Find out more about Algolia Cookie Configuration in <a href="https://www.algolia.com/doc/integration/magento-2/how-it-works/analytics-overview/?client=php#algolia-cookie-configuration?utm_source=magento&utm_medium=extension&utm_campaign=magento_2&utm_term=shop-owner&utm_content=doc-link" target="_blank">documentation</a>.
222+
</div>';
223+
$selector = '#algoliasearch_credentials_algolia_cookie_configuration';
224+
$method = 'after';
225+
226+
$this->notices[] = [
227+
'selector' => $selector,
228+
'method' => $method,
229+
'message' => $noticeContent,
230+
];
231+
}
210232

211233
protected function getPersonalizationNotice()
212234
{

Helper/Entity/ProductHelper.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ public function getObject(Product $product)
569569
);
570570

571571
$defaultData = $transport->getData();
572+
572573
$visibility = $product->getVisibility();
573574

574575
$visibleInCatalog = $this->visibility->getVisibleInCatalogIds();
@@ -767,9 +768,11 @@ protected function getValidCategoryName($category, $rootCat, $storeId): ?string
767768
*/
768769
protected function dedupePaths($paths): array
769770
{
770-
return array_intersect_key(
771-
$paths,
772-
array_unique(array_map('serialize', $paths))
771+
return array_values(
772+
array_intersect_key(
773+
$paths,
774+
array_unique(array_map('serialize', $paths))
775+
)
773776
);
774777
}
775778

@@ -1048,6 +1051,7 @@ protected function addAdditionalAttributes($customData, $additionalAttributes, P
10481051
}
10491052

10501053
$attributeResource = $attributeResource->setData('store_id', $product->getStoreId());
1054+
10511055
$value = $product->getData($attributeName);
10521056

10531057
if ($value !== null) {
@@ -1222,7 +1226,7 @@ protected function addNonNullValue(
12221226
$value = $attributeResource->getFrontend()->getValue($product);
12231227
}
12241228

1225-
if ($value) {
1229+
if ($value !== null) {
12261230
$customData[$attribute['attribute']] = $value;
12271231
}
12281232

Helper/InsightsHelper.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
use Algolia\AlgoliaSearch\Helper\Configuration\PersonalizationHelper;
66
use Algolia\AlgoliaSearch\Insights\UserInsightsClient;
77
use Algolia\AlgoliaSearch\InsightsClient;
8+
use Magento\Customer\Model\Customer;
89
use Magento\Customer\Model\Session as CustomerSession;
10+
use Magento\Framework\Session\SessionManagerInterface;
911
use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory;
1012
use Magento\Framework\Stdlib\CookieManagerInterface;
1113

@@ -48,12 +50,14 @@ class InsightsHelper
4850
public function __construct(
4951
ConfigHelper $configHelper,
5052
PersonalizationHelper $personalizationHelper,
53+
SessionManagerInterface $sessionManager,
5154
CookieManagerInterface $cookieManager,
5255
CookieMetadataFactory $cookieMetadataFactory,
5356
CustomerSession $customerSession
5457
) {
5558
$this->configHelper = $configHelper;
5659
$this->personalizationHelper = $personalizationHelper;
60+
$this->sessionManager = $sessionManager;
5761
$this->cookieManager = $cookieManager;
5862
$this->cookieMetadataFactory = $cookieMetadataFactory;
5963
$this->customerSession = $customerSession;
@@ -142,11 +146,11 @@ private function getUserToken()
142146
}
143147

144148
/**
145-
* @param \Magento\Customer\Model\Customer $customer
149+
* @param Customer $customer
146150
*
147151
* @return string
148152
*/
149-
public function setUserToken(\Magento\Customer\Model\Customer $customer)
153+
public function setUserToken(Customer $customer)
150154
{
151155
$userToken = base64_encode('customer-' . $customer->getEmail() . '-' . $customer->getId());
152156
$userToken = 'aa-' . preg_replace('/[^A-Za-z0-9\-]/', '', $userToken);
@@ -166,4 +170,11 @@ public function setUserToken(\Magento\Customer\Model\Customer $customer)
166170

167171
return $userToken;
168172
}
173+
174+
/**
175+
* @return string|null
176+
*/
177+
public function getUserAllowedSavedCookie() {
178+
return $this->configHelper->isCookieRestrictionModeEnabled() ? !!$this->cookieManager->getCookie($this->configHelper->getDefaultConsentCookieName()) : true;
179+
}
169180
}

Model/Indexer/CategoryObserver.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ public function afterSave(
5454
CategoryResourceModel $result,
5555
CategoryModel $category
5656
) {
57+
if (!$this->configHelper->getApplicationID()
58+
|| !$this->configHelper->getAPIKey()
59+
|| !$this->configHelper->getSearchOnlyAPIKey()) {
60+
return $result;
61+
}
5762
$categoryResource->addCommitCallback(function () use ($category) {
5863
$collectionIds = [];
5964
// To reduce the indexing operation for products, only update if these values have changed

Model/Observer/Merchandising.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function execute(Observer $observer)
6767
The category cannot be merchandised with Algolia
6868
as you hit your <a href="https://www.algolia.com/pricing/" target="_blank">query rules quota</a>.
6969
If you need an extended quota,
70-
please contact us on <a href="mailto:support@algolia.com">support@algolia.com</a>.';
70+
please reach out to the [Algolia Support team](https://support.algolia.com/hc/en-us/requests/new).';
7171
}
7272

7373
$phrase = new Phrase($message);

Observer/Insights/CheckoutCartProductAddAfter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function execute(Observer $observer)
6767
$product = $observer->getEvent()->getProduct();
6868
$storeId = $quoteItem->getStoreId();
6969

70-
if (!$this->insightsHelper->isAddedToCartTracked($storeId) && !$this->insightsHelper->isOrderPlacedTracked($storeId)) {
70+
if (!$this->insightsHelper->isAddedToCartTracked($storeId) && !$this->insightsHelper->isOrderPlacedTracked($storeId) || !$this->insightsHelper->getUserAllowedSavedCookie()) {
7171
return;
7272
}
7373

0 commit comments

Comments
 (0)