Skip to content

Commit 78469c8

Browse files
authored
Merge pull request #1388 from algolia/release/3.11.0-beta
Release/3.11.0 beta
2 parents a55bade + fdef984 commit 78469c8

File tree

20 files changed

+1011
-755
lines changed

20 files changed

+1011
-755
lines changed

Block/Algolia.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,12 @@ public function getLastOrder()
270270
return $this->checkoutSession->getLastRealOrder();
271271
}
272272

273-
public function getAddToCartParams()
273+
public function getAddToCartParams() : array
274274
{
275-
$url = $this->getAddToCartUrl();
276-
277275
return [
278-
'action' => $url,
276+
'action' => $this->_urlBuilder->getUrl('checkout/cart/add', []),
279277
'formKey' => $this->formKey->getFormKey(),
278+
'redirectUrlParam' => ActionInterface::PARAM_NAME_URL_ENCODED
280279
];
281280
}
282281

@@ -285,6 +284,9 @@ public function getTimestamp()
285284
return $this->date->gmtTimestamp('today midnight');
286285
}
287286

287+
/**
288+
* @deprecated This function is deprecated as redirect routes must be derived on the frontend not backend
289+
*/
288290
protected function getAddToCartUrl($additional = [])
289291
{
290292
$continueUrl = $this->urlHelper->getEncodedUrl($this->_urlBuilder->getCurrentUrl());

Block/Configuration.php

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
class Configuration extends Algolia implements CollectionDataSourceInterface
1111
{
12+
//Placeholder for future implementation (requires customer renderer for hierarchicalMenu widget)
13+
private const IS_CATEGORY_NAVIGATION_ENABLED = false;
14+
1215
public function isSearchPage()
1316
{
1417
if ($this->getConfigHelper()->isInstantEnabled()) {
@@ -30,6 +33,40 @@ public function isSearchPage()
3033
return false;
3134
}
3235

36+
/**
37+
* @param \Magento\Catalog\Model\Category $cat
38+
* @return string
39+
*/
40+
protected function initCategoryParentPath(\Magento\Catalog\Model\Category $cat): string {
41+
$path = '';
42+
foreach ($cat->getPathIds() as $treeCategoryId) {
43+
if ($path) {
44+
$path .= $this->getConfigHelper()->getCategorySeparator($this->getStoreId());
45+
}
46+
$path .= $this->getCategoryHelper()->getCategoryName($treeCategoryId, $this->getStoreId());
47+
}
48+
return $path;
49+
}
50+
51+
/**
52+
* @param \Magento\Catalog\Model\Category $cat
53+
* @param string $parent
54+
* @param array $arr
55+
* @return array
56+
*/
57+
protected function getChildCategoryUrls(\Magento\Catalog\Model\Category $cat, string $parent = '', array $arr = array()): array {
58+
if (!$parent) {
59+
$parent = $this->initCategoryParentPath($cat);
60+
}
61+
62+
foreach ($cat->getChildrenCategories() as $child) {
63+
$key = $parent ? $parent . $this->getConfigHelper()->getCategorySeparator($this->getStoreId()) . $child->getName() : $child ->getName();
64+
$arr[$key]['url'] = $child->getUrl();
65+
$arr = array_merge($arr, $this->getChildCategoryUrls($child, $key, $arr));
66+
}
67+
return $arr;
68+
}
69+
3370
public function getConfiguration()
3471
{
3572
$config = $this->getConfigHelper();
@@ -70,6 +107,7 @@ public function getConfiguration()
70107
$level = '';
71108
$categoryId = '';
72109
$parentCategoryName = '';
110+
$childCategories = [];
73111

74112
$addToCartParams = $this->getAddToCartParams();
75113

@@ -88,14 +126,17 @@ public function getConfiguration()
88126

89127
if ($category && $category->getDisplayMode() !== 'PAGE') {
90128
$category->getUrlInstance()->setStore($this->getStoreId());
129+
if (self::IS_CATEGORY_NAVIGATION_ENABLED) {
130+
$childCategories = $this->getChildCategoryUrls($category);
131+
}
91132

92133
$categoryId = $category->getId();
93134

94135
$level = -1;
95136
foreach ($category->getPathIds() as $treeCategoryId) {
96137
if ($path !== '') {
97-
$path .= ' /// ';
98-
}else{
138+
$path .= $config->getCategorySeparator();
139+
} else {
99140
$parentCategoryName = $categoryHelper->getCategoryName($treeCategoryId, $this->getStoreId());
100141
}
101142

@@ -144,7 +185,6 @@ public function getConfiguration()
144185
}
145186

146187
$attributesToFilter = $config->getAttributesToFilter($customerGroupId);
147-
148188
$algoliaJsConfig = [
149189
'instant' => [
150190
'enabled' => $config->isInstantEnabled(),
@@ -154,6 +194,10 @@ public function getConfiguration()
154194
'infiniteScrollEnabled' => $config->isInfiniteScrollEnabled(),
155195
'urlTrackedParameters' => $this->getUrlTrackedParameters(),
156196
'isSearchBoxEnabled' => $config->isInstantSearchBoxEnabled(),
197+
'isVisualMerchEnabled' => $config->isVisualMerchEnabled(),
198+
'categorySeparator' => $config->getCategorySeparator(),
199+
'categoryPageIdAttribute' => $config->getCategoryPageIdAttributeName(),
200+
'isCategoryNavigationEnabled' => self::IS_CATEGORY_NAVIGATION_ENABLED,
157201
'hidePagination' => $config->hidePaginationInInstantSearchPage()
158202
],
159203
'autocomplete' => [
@@ -196,10 +240,7 @@ public function getConfiguration()
196240
'indexName' => $coreHelper->getBaseIndexName(),
197241
'apiKey' => $algoliaHelper->generateSearchSecuredApiKey(
198242
$config->getSearchOnlyAPIKey(),
199-
array_merge(
200-
$config->getAttributesToRetrieve($customerGroupId),
201-
$attributesToFilter
202-
)
243+
$attributesToFilter
203244
),
204245
'attributeFilter' => $attributesToFilter,
205246
'facets' => $facets,
@@ -234,6 +275,8 @@ public function getConfiguration()
234275
'path' => $path,
235276
'level' => $level,
236277
'parentCategory' => $parentCategoryName,
278+
'childCategories' => $childCategories,
279+
'url' => $this->getUrl('*/*/*', ['_use_rewrite' => true, '_forced_secure' => true])
237280
],
238281
'showCatsNotIncludedInNavigation' => $config->showCatsNotIncludedInNavigation(),
239282
'showSuggestionsOnNoResultsPage' => $config->showSuggestionsOnNoResultsPage(),

CHANGELOG.md

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

3+
## 3.11.0-beta
4+
5+
### Bug Fixes
6+
- Support for Merch Studio and the Visual Merchandiser.
7+
- Upgraded the Algolia PHP client to version 3.3.2
8+
- Upgraded the Algolia insight 2.6.0
9+
- Preserve facet selections after adding an item to the cart from the PLP
10+
- Fixes related to Neural Search compatibility
11+
312
## 3.10.5
413

514
### Bug Fixes

Helper/Adapter/FiltersHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public function getFacetFilters($storeId, $parameters = null)
166166

167167
if ($facet['attribute'] == 'categories') {
168168
$level = '.level' . (count($facetValues) - 1);
169-
$facetFilters[] = $facet['attribute'] . $level . ':' . implode(' /// ', $facetValues);
169+
$facetFilters[] = $facet['attribute'] . $level . ':' . implode($this->config->getCategorySeparator($storeId), $facetValues);
170170

171171
continue;
172172
}

Helper/AlgoliaHelper.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,13 @@ public function generateSearchSecuredApiKey($key, $params = [])
193193

194194
public function getSettings($indexName)
195195
{
196-
return $this->getIndex($indexName)->getSettings();
196+
try {
197+
return $this->getIndex($indexName)->getSettings();
198+
}catch (\Exception $e) {
199+
if ($e->getCode() !== 404) {
200+
throw $e;
201+
}
202+
}
197203
}
198204

199205
public function mergeSettings($indexName, $settings, $mergeSettingsFrom = '')

Helper/ConfigHelper.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,14 @@ class ConfigHelper
4949
public const PRODUCT_ATTRIBUTES = 'algoliasearch_products/products/product_additional_attributes';
5050
public const PRODUCT_CUSTOM_RANKING = 'algoliasearch_products/products/custom_ranking_product_attributes';
5151
public const USE_ADAPTIVE_IMAGE = 'algoliasearch_products/products/use_adaptive_image';
52+
public const ENABLE_VISUAL_MERCHANDISING = 'algoliasearch_products/products/enable_visual_merchandising';
53+
public const CATEGORY_PAGE_ID_ATTRIBUTE_NAME = 'algoliasearch_products/products/category_page_id_attribute_name';
5254

5355
public const CATEGORY_ATTRIBUTES = 'algoliasearch_categories/categories/category_additional_attributes';
5456
public const CATEGORY_CUSTOM_RANKING = 'algoliasearch_categories/categories/custom_ranking_category_attributes';
5557
public const SHOW_CATS_NOT_INCLUDED_IN_NAV = 'algoliasearch_categories/categories/show_cats_not_included_in_navigation';
5658
public const INDEX_EMPTY_CATEGORIES = 'algoliasearch_categories/categories/index_empty_categories';
59+
public const CATEGORY_SEPARATOR = 'algoliasearch_categories/categories/category_separator';
5760

5861
public const IS_ACTIVE = 'algoliasearch_queue/queue/active';
5962
public const NUMBER_OF_JOB_TO_RUN = 'algoliasearch_queue/queue/number_of_job_to_run';
@@ -885,6 +888,24 @@ public function useAdaptiveImage($storeId = null)
885888
return $this->configInterface->isSetFlag(self::USE_ADAPTIVE_IMAGE, ScopeInterface::SCOPE_STORE, $storeId);
886889
}
887890

891+
/**
892+
* @param $storeId
893+
* @return bool
894+
*/
895+
public function isVisualMerchEnabled($storeId = null): bool
896+
{
897+
return $this->configInterface->isSetFlag(self::ENABLE_VISUAL_MERCHANDISING, ScopeInterface::SCOPE_STORE, $storeId);
898+
}
899+
900+
/**
901+
* @param $storeId
902+
* @return string
903+
*/
904+
public function getCategoryPageIdAttributeName($storeId = null): string
905+
{
906+
return (string) $this->configInterface->getValue(self::CATEGORY_PAGE_ID_ATTRIBUTE_NAME, ScopeInterface::SCOPE_STORE, $storeId);
907+
}
908+
888909
/**
889910
* @param $storeId
890911
* @return mixed
@@ -1454,6 +1475,15 @@ public function getCategoryAdditionalAttributes($storeId = null)
14541475
return [];
14551476
}
14561477

1478+
/**
1479+
* @param $storeId
1480+
* @return string
1481+
*/
1482+
public function getCategorySeparator($storeId = null): string
1483+
{
1484+
return (string) $this->configInterface->getValue(self::CATEGORY_SEPARATOR, ScopeInterface::SCOPE_STORE, $storeId);
1485+
}
1486+
14571487
/**
14581488
* @param $groupId
14591489
* @return array

0 commit comments

Comments
 (0)