/**
  * Generate list based on categories
  *
  * @param int $storeId
  * @param Product $product
  * @param ObjectRegistry $productCategories
  * @return UrlRewrite[]
  */
 public function generate($storeId, Product $product, ObjectRegistry $productCategories)
 {
     $urls = [];
     foreach ($productCategories->getList() as $category) {
         $urls[] = $this->urlRewriteFactory->create()->setEntityType(ProductUrlRewriteGenerator::ENTITY_TYPE)->setEntityId($product->getId())->setRequestPath($this->productUrlPathGenerator->getUrlPathWithSuffix($product, $storeId, $category))->setTargetPath($this->productUrlPathGenerator->getCanonicalUrlPath($product, $category))->setStoreId($storeId)->setMetadata(['category_id' => $category->getId()]);
     }
     return $urls;
 }
Example #2
0
 /**
  * @return string
  */
 protected function getCanonicalTargetPath()
 {
     $product = $this->_getProduct()->getId() ? $this->_getProduct() : null;
     $category = $this->_getCategory()->getId() ? $this->_getCategory() : null;
     return $product
         ? $this->productUrlPathGenerator->getCanonicalUrlPath($product, $category)
         : $this->categoryUrlPathGenerator->getCanonicalUrlPath($category);
 }
 /**
  * Generate list based on categories
  *
  * @return UrlRewrite[]
  */
 protected function categoriesUrlRewriteGenerate()
 {
     $urls = [];
     foreach ($this->products as $productId => $productsByStores) {
         foreach ($productsByStores as $storeId => $product) {
             foreach ($this->categoryCache[$productId] as $categoryId) {
                 $category = $this->import->getCategoryProcessor()->getCategoryById($categoryId);
                 $requestPath = $this->productUrlPathGenerator->getUrlPathWithSuffix($product, $storeId, $category);
                 $urls[] = $this->urlRewriteFactory->create()->setEntityType(ProductUrlRewriteGenerator::ENTITY_TYPE)->setEntityId($productId)->setRequestPath($requestPath)->setTargetPath($this->productUrlPathGenerator->getCanonicalUrlPath($product, $category))->setStoreId($storeId)->setMetadata(['category_id' => $category->getId()]);
             }
         }
     }
     return $urls;
 }
 public function testGetCanonicalUrlPathWithCategory()
 {
     $this->product->expects($this->once())->method('getId')->will($this->returnValue(1));
     $this->category->expects($this->once())->method('getId')->will($this->returnValue(1));
     $this->assertEquals('catalog/product/view/id/1/category/1', $this->productUrlPathGenerator->getCanonicalUrlPath($this->product, $this->category));
 }
Example #5
0
 /**
  * @param \Magento\Catalog\Model\Product|null $product
  * @param \Magento\Catalog\Model\Category|null $category
  * @return string
  */
 protected function getTargetPath($product = null, $category = null)
 {
     return $product ? $this->productUrlPathGenerator->getCanonicalUrlPath($product, $category) : $this->categoryUrlPathGenerator->getCanonicalUrlPath($category);
 }
 /**
  * Generate list based on store view
  *
  * @param int $storeId
  * @param Product $product
  * @return UrlRewrite[]
  */
 public function generate($storeId, Product $product)
 {
     return [$this->urlRewriteFactory->create()->setEntityType(ProductUrlRewriteGenerator::ENTITY_TYPE)->setEntityId($product->getId())->setRequestPath($this->productUrlPathGenerator->getUrlPathWithSuffix($product, $storeId))->setTargetPath($this->productUrlPathGenerator->getCanonicalUrlPath($product))->setStoreId($storeId)];
 }