Open MaximGns opened 1 year ago
@MaximGns
Thanks for sharing, I tested the patch and we didn't have success. But it did massively help.
The issue is down to the array_shift, this will work fine providing your Virtual Category is a top level category.
Maybe not the cleanest solution, but this works and solves the immediate problem. It has no noticeable impact on performance with categories a couple of levels deep.
diff --git a/vendor/smile/elasticsuite/src/module-elasticsuite-virtual-category/Controller/Router.php b/vendor/smile/elasticsuite/src/module-elasticsuite-virtual-category/Controller/Router.php
index c83fe462..461cacca 100644
--- a/vendor/smile/elasticsuite/src/module-elasticsuite-virtual-category/Controller/Router.php
+++ b/vendor/smile/elasticsuite/src/module-elasticsuite-virtual-category/Controller/Router.php
@@ -155,11 +155,24 @@ class Router implements RouterInterface
*/
private function getCategoryRewrite($identifier)
{
- $chunks = explode('/', $identifier);
- $categoryPath = array_pop($chunks);
- $storeId = $this->storeManager->getStore()->getId();
+ $chunks = explode('/', $identifier);
+ $chunk_count = count($chunks);
+ $storeId = $this->storeManager->getStore()->getId();
+ $url_rewrite = null;
+
+
+ while (1 < $chunk_count) {
+ array_shift($chunks);
+ $categoryPath = implode('/', $chunks);
+
+ $url_rewrite = $this->urlModel->getCategoryRewrite($categoryPath, $storeId);
+ if($url_rewrite != null) {
+ break;
+ }
+ $chunk_count = count($chunks);
+ }
- return $this->urlModel->getCategoryRewrite($categoryPath, $storeId);
+ return $url_rewrite;
}
/**
This has been applied along side:
diff --git a/vendor/smile/elasticsuite/src/module-elasticsuite-virtual-category/Model/Url.php b/vendor/smile/elasticsuite/src/module-elasticsuite-virtual-category/Model/Url.php
index be411501..e6112b3d 100644
--- a/vendor/smile/elasticsuite/src/module-elasticsuite-virtual-category/Model/Url.php
+++ b/vendor/smile/elasticsuite/src/module-elasticsuite-virtual-category/Model/Url.php
@@ -218,7 +218,9 @@ class Url
public function getCategoryRewrite($categoryPath, $storeId)
{
$categoryPath = str_replace($this->getCategoryUrlSuffix() ?? '', '', $categoryPath);
- $category = $this->loadCategoryByUrlKey($categoryPath);
+ //START PATCH
+ $category = $this->loadCategoryByUrlKey($categoryPath, 'url_path');
+ //END PATCH
$rewrite = null;
if ($category && $category->getId()) {
@@ -261,12 +263,12 @@ class Url
* @return \Magento\Framework\DataObject
* @throws \Magento\Framework\Exception\LocalizedException
*/
- private function loadCategoryByUrlKey($requestPath)
+ private function loadCategoryByUrlKey($requestPath, string $filter = 'url_key')
{
$collection = $this->categoryCollectionFactory->create();
$collection->setStoreId($this->storeManager->getStore()->getId())
- ->addAttributeToFilter('url_key', ['eq' => $requestPath]);
+ ->addAttributeToFilter($filter, ['eq' => $requestPath]);
return $collection->getFirstItem();
}
hi @nathanchick , indeed. We have only 1 virtual categorie and it is a top level category. Did not really further investigate or tested other use cases.
Hello, I confirm this issue is easily reproductible. I'm going to check the given patch, and if I've time to work on it open a PR with a proper solution.
BTW the first patch works fine for me!
Preconditions
Magento Version : 2.4.6-p1
ElasticSuite Version : 2.11.2
Environment : Both
Third party modules :
Steps to reproduce
Expected result
Actual result
dier/honden/droogvoer
the categorydier/katten/droogvoer
is shownApplied following patch locally