Skip to content

Commit

Permalink
Merge pull request #1391 from algolia/release/3.11.0-beta
Browse files Browse the repository at this point in the history
Release/3.11.0 beta
  • Loading branch information
mohitalgolia authored Jul 31, 2023
2 parents c79dd30 + fdef984 commit 5841ac1
Show file tree
Hide file tree
Showing 20 changed files with 1,011 additions and 755 deletions.
10 changes: 6 additions & 4 deletions Block/Algolia.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,12 @@ public function getLastOrder()
return $this->checkoutSession->getLastRealOrder();
}

public function getAddToCartParams()
public function getAddToCartParams() : array
{
$url = $this->getAddToCartUrl();

return [
'action' => $url,
'action' => $this->_urlBuilder->getUrl('checkout/cart/add', []),
'formKey' => $this->formKey->getFormKey(),
'redirectUrlParam' => ActionInterface::PARAM_NAME_URL_ENCODED
];
}

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

/**
* @deprecated This function is deprecated as redirect routes must be derived on the frontend not backend
*/
protected function getAddToCartUrl($additional = [])
{
$continueUrl = $this->urlHelper->getEncodedUrl($this->_urlBuilder->getCurrentUrl());
Expand Down
57 changes: 50 additions & 7 deletions Block/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

class Configuration extends Algolia implements CollectionDataSourceInterface
{
//Placeholder for future implementation (requires customer renderer for hierarchicalMenu widget)
private const IS_CATEGORY_NAVIGATION_ENABLED = false;

public function isSearchPage()
{
if ($this->getConfigHelper()->isInstantEnabled()) {
Expand All @@ -30,6 +33,40 @@ public function isSearchPage()
return false;
}

/**
* @param \Magento\Catalog\Model\Category $cat
* @return string
*/
protected function initCategoryParentPath(\Magento\Catalog\Model\Category $cat): string {
$path = '';
foreach ($cat->getPathIds() as $treeCategoryId) {
if ($path) {
$path .= $this->getConfigHelper()->getCategorySeparator($this->getStoreId());
}
$path .= $this->getCategoryHelper()->getCategoryName($treeCategoryId, $this->getStoreId());
}
return $path;
}

/**
* @param \Magento\Catalog\Model\Category $cat
* @param string $parent
* @param array $arr
* @return array
*/
protected function getChildCategoryUrls(\Magento\Catalog\Model\Category $cat, string $parent = '', array $arr = array()): array {
if (!$parent) {
$parent = $this->initCategoryParentPath($cat);
}

foreach ($cat->getChildrenCategories() as $child) {
$key = $parent ? $parent . $this->getConfigHelper()->getCategorySeparator($this->getStoreId()) . $child->getName() : $child ->getName();
$arr[$key]['url'] = $child->getUrl();
$arr = array_merge($arr, $this->getChildCategoryUrls($child, $key, $arr));
}
return $arr;
}

public function getConfiguration()
{
$config = $this->getConfigHelper();
Expand Down Expand Up @@ -70,6 +107,7 @@ public function getConfiguration()
$level = '';
$categoryId = '';
$parentCategoryName = '';
$childCategories = [];

$addToCartParams = $this->getAddToCartParams();

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

if ($category && $category->getDisplayMode() !== 'PAGE') {
$category->getUrlInstance()->setStore($this->getStoreId());
if (self::IS_CATEGORY_NAVIGATION_ENABLED) {
$childCategories = $this->getChildCategoryUrls($category);
}

$categoryId = $category->getId();

$level = -1;
foreach ($category->getPathIds() as $treeCategoryId) {
if ($path !== '') {
$path .= ' /// ';
}else{
$path .= $config->getCategorySeparator();
} else {
$parentCategoryName = $categoryHelper->getCategoryName($treeCategoryId, $this->getStoreId());
}

Expand Down Expand Up @@ -144,7 +185,6 @@ public function getConfiguration()
}

$attributesToFilter = $config->getAttributesToFilter($customerGroupId);

$algoliaJsConfig = [
'instant' => [
'enabled' => $config->isInstantEnabled(),
Expand All @@ -154,6 +194,10 @@ public function getConfiguration()
'infiniteScrollEnabled' => $config->isInfiniteScrollEnabled(),
'urlTrackedParameters' => $this->getUrlTrackedParameters(),
'isSearchBoxEnabled' => $config->isInstantSearchBoxEnabled(),
'isVisualMerchEnabled' => $config->isVisualMerchEnabled(),
'categorySeparator' => $config->getCategorySeparator(),
'categoryPageIdAttribute' => $config->getCategoryPageIdAttributeName(),
'isCategoryNavigationEnabled' => self::IS_CATEGORY_NAVIGATION_ENABLED,
'hidePagination' => $config->hidePaginationInInstantSearchPage()
],
'autocomplete' => [
Expand Down Expand Up @@ -196,10 +240,7 @@ public function getConfiguration()
'indexName' => $coreHelper->getBaseIndexName(),
'apiKey' => $algoliaHelper->generateSearchSecuredApiKey(
$config->getSearchOnlyAPIKey(),
array_merge(
$config->getAttributesToRetrieve($customerGroupId),
$attributesToFilter
)
$attributesToFilter
),
'attributeFilter' => $attributesToFilter,
'facets' => $facets,
Expand Down Expand Up @@ -234,6 +275,8 @@ public function getConfiguration()
'path' => $path,
'level' => $level,
'parentCategory' => $parentCategoryName,
'childCategories' => $childCategories,
'url' => $this->getUrl('*/*/*', ['_use_rewrite' => true, '_forced_secure' => true])
],
'showCatsNotIncludedInNavigation' => $config->showCatsNotIncludedInNavigation(),
'showSuggestionsOnNoResultsPage' => $config->showSuggestionsOnNoResultsPage(),
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# CHANGE LOG

## 3.11.0-beta

### Bug Fixes
- Support for Merch Studio and the Visual Merchandiser.
- Upgraded the Algolia PHP client to version 3.3.2
- Upgraded the Algolia insight 2.6.0
- Preserve facet selections after adding an item to the cart from the PLP
- Fixes related to Neural Search compatibility

## 3.10.5

### Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion Helper/Adapter/FiltersHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function getFacetFilters($storeId, $parameters = null)

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

continue;
}
Expand Down
8 changes: 7 additions & 1 deletion Helper/AlgoliaHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,13 @@ public function generateSearchSecuredApiKey($key, $params = [])

public function getSettings($indexName)
{
return $this->getIndex($indexName)->getSettings();
try {
return $this->getIndex($indexName)->getSettings();
}catch (\Exception $e) {
if ($e->getCode() !== 404) {
throw $e;
}
}
}

public function mergeSettings($indexName, $settings, $mergeSettingsFrom = '')
Expand Down
30 changes: 30 additions & 0 deletions Helper/ConfigHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ class ConfigHelper
public const PRODUCT_ATTRIBUTES = 'algoliasearch_products/products/product_additional_attributes';
public const PRODUCT_CUSTOM_RANKING = 'algoliasearch_products/products/custom_ranking_product_attributes';
public const USE_ADAPTIVE_IMAGE = 'algoliasearch_products/products/use_adaptive_image';
public const ENABLE_VISUAL_MERCHANDISING = 'algoliasearch_products/products/enable_visual_merchandising';
public const CATEGORY_PAGE_ID_ATTRIBUTE_NAME = 'algoliasearch_products/products/category_page_id_attribute_name';

public const CATEGORY_ATTRIBUTES = 'algoliasearch_categories/categories/category_additional_attributes';
public const CATEGORY_CUSTOM_RANKING = 'algoliasearch_categories/categories/custom_ranking_category_attributes';
public const SHOW_CATS_NOT_INCLUDED_IN_NAV = 'algoliasearch_categories/categories/show_cats_not_included_in_navigation';
public const INDEX_EMPTY_CATEGORIES = 'algoliasearch_categories/categories/index_empty_categories';
public const CATEGORY_SEPARATOR = 'algoliasearch_categories/categories/category_separator';

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

/**
* @param $storeId
* @return bool
*/
public function isVisualMerchEnabled($storeId = null): bool
{
return $this->configInterface->isSetFlag(self::ENABLE_VISUAL_MERCHANDISING, ScopeInterface::SCOPE_STORE, $storeId);
}

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

/**
* @param $storeId
* @return mixed
Expand Down Expand Up @@ -1454,6 +1475,15 @@ public function getCategoryAdditionalAttributes($storeId = null)
return [];
}

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

/**
* @param $groupId
* @return array
Expand Down
Loading

0 comments on commit 5841ac1

Please sign in to comment.