Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CanonicalUrlRewriteGenerator.php
Go to the documentation of this file.
1 <?php
7 
11 use Magento\UrlRewrite\Service\V1\Data\UrlRewriteFactory;
12 
14 {
19 
23  protected $urlRewriteFactory;
24 
29  public function __construct(
31  UrlRewriteFactory $urlRewriteFactory
32  ) {
33  $this->categoryUrlPathGenerator = $categoryUrlPathGenerator;
34  $this->urlRewriteFactory = $urlRewriteFactory;
35  }
36 
44  public function generate($storeId, Category $category)
45  {
46  $urlPath = $this->categoryUrlPathGenerator->getUrlPathWithSuffix($category, $storeId);
47  $result = [
48  $urlPath . '_' . $storeId => $this->urlRewriteFactory->create()->setStoreId($storeId)
50  ->setEntityId($category->getId())
51  ->setRequestPath($urlPath)
52  ->setTargetPath($this->categoryUrlPathGenerator->getCanonicalUrlPath($category))
53  ];
54  return $result;
55  }
56 }
__construct(CategoryUrlPathGenerator $categoryUrlPathGenerator, UrlRewriteFactory $urlRewriteFactory)