diff --git a/src/Model/Resolver/EntityUrl.php b/src/Model/Resolver/EntityUrl.php index 0d963ac..34b5bb8 100644 --- a/src/Model/Resolver/EntityUrl.php +++ b/src/Model/Resolver/EntityUrl.php @@ -28,6 +28,8 @@ */ class EntityUrl implements ResolverInterface { + const PRODUCT_TARGET_PATH = 'catalog/product/view/id/'; + /** * @var UrlFinderInterface */ @@ -96,7 +98,18 @@ public function resolve( } $customUrl = $this->customUrlLocator->locateUrl($url); - $url = $customUrl ?: $url; + + /* + * Check if it is product target path and remove everything + * after id from url since we don't get specific categories for products + */ + if (str_contains($url, self::PRODUCT_TARGET_PATH)) { + $urlArray = explode('/', $url); + $url = implode('/', array_slice($urlArray, 0, 5)); + } else { + $url = $customUrl ?: $url; + } + $urlRewrite = $this->findCanonicalUrl($url); if ($urlRewrite) { @@ -115,6 +128,7 @@ public function resolve( ->addAttributeToFilter('status', ['eq' => Status::STATUS_ENABLED]) ->addWebsiteFilter($this->storeManager->getWebsite()); $product = $collection->addIdFilter($id)->getFirstItem(); + if (!$product->hasData()) { return null; }