Skip to content

Commit

Permalink
Merge pull request #8 from AleksandrsKondratjevs/issue-2688
Browse files Browse the repository at this point in the history
Check if targetPath for products
  • Loading branch information
carinadues authored Jun 14, 2021
2 parents 0d45cb2 + 5899c7b commit 1978daf
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Model/Resolver/EntityUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
*/
class EntityUrl implements ResolverInterface
{
const PRODUCT_TARGET_PATH = 'catalog/product/view/id/';

/**
* @var UrlFinderInterface
*/
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down

0 comments on commit 1978daf

Please sign in to comment.