Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CategoriesUrlRewriteGenerator.php
Go to the documentation of this file.
1 <?php
7 
13 use Magento\UrlRewrite\Service\V1\Data\UrlRewriteFactory;
14 
16 {
21 
25  protected $urlRewriteFactory;
26 
32  {
33  $this->productUrlPathGenerator = $productUrlPathGenerator;
34  $this->urlRewriteFactory = $urlRewriteFactory;
35  }
36 
45  public function generate($storeId, Product $product, ObjectRegistry $productCategories)
46  {
47  $urls = [];
48  foreach ($productCategories->getList() as $category) {
49  $urls[] = $this->urlRewriteFactory->create()
51  ->setEntityId($product->getId())
52  ->setRequestPath($this->productUrlPathGenerator->getUrlPathWithSuffix($product, $storeId, $category))
53  ->setTargetPath($this->productUrlPathGenerator->getCanonicalUrlPath($product, $category))
55  ->setMetadata(['category_id' => $category->getId()]);
56  }
57  return $urls;
58  }
59 }
generate($storeId, Product $product, ObjectRegistry $productCategories)
__construct(ProductUrlPathGenerator $productUrlPathGenerator, UrlRewriteFactory $urlRewriteFactory)