Skip to content

Commit 90b8b3a

Browse files
committed
MC-21811: Canonical_url displays the backend domain instead of relative
- add config
1 parent 9735ea8 commit 90b8b3a

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

app/code/Magento/CatalogGraphQl/Model/Resolver/Product/CanonicalUrl.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,25 @@
1212
use Magento\Framework\GraphQl\Config\Element\Field;
1313
use Magento\Framework\GraphQl\Query\ResolverInterface;
1414
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
15+
use Magento\Catalog\Helper\Product as ProductHelper;
16+
use Magento\Store\Api\Data\StoreInterface;
1517

1618
/**
1719
* Resolve data for product canonical URL
1820
*/
1921
class CanonicalUrl implements ResolverInterface
2022
{
23+
/** @var ProductHelper */
24+
private $productHelper;
25+
26+
/**
27+
* @param Product $productHelper
28+
*/
29+
public function __construct(ProductHelper $productHelper)
30+
{
31+
$this->productHelper = $productHelper;
32+
}
33+
2134
/**
2235
* @inheritdoc
2336
*/
@@ -34,8 +47,11 @@ public function resolve(
3447

3548
/* @var $product Product */
3649
$product = $value['model'];
37-
$product->getUrlModel()->getUrl($product, ['_ignore_category' => true]);
38-
39-
return $product->getRequestPath();
50+
/** @var StoreInterface $store */
51+
$store = $context->getExtensionAttributes()->getStore();
52+
if ($this->productHelper->canUseCanonicalTag($store)) {
53+
$product->getUrlModel()->getUrl($product, ['_ignore_category' => true]);
54+
return $product->getRequestPath();
55+
}
4056
}
4157
}

0 commit comments

Comments
 (0)