/** * 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; }
/** * @param \Magento\UrlRewrite\Service\V1\Data\UrlRewrite $url * @param int $storeId * @return array */ protected function generateForCustom($url, $storeId) { $urls = []; $targetPath = !$url->getRedirectType() ? $url->getTargetPath() : $this->categoryUrlPathGenerator->getUrlPathWithSuffix($this->category, $storeId); if ($url->getRequestPath() !== $targetPath) { $urls[$url->getRequestPath() . '_' . $storeId] = $this->urlRewriteFactory->create()->setEntityType(CategoryUrlRewriteGenerator::ENTITY_TYPE)->setEntityId($this->category->getId())->setRequestPath($url->getRequestPath())->setTargetPath($targetPath)->setRedirectType($url->getRedirectType())->setStoreId($storeId)->setDescription($url->getDescription())->setIsAutogenerated(0)->setMetadata($url->getMetadata()); } return $urls; }
/** * @param UrlRewrite $url * @param Category $category * @return array */ protected function generateForCustom($url, $category) { $storeId = $url->getStoreId(); $productId = $url->getEntityId(); if (isset($this->products[$productId][$storeId])) { $product = $this->products[$productId][$storeId]; $targetPath = $url->getRedirectType() ? $this->productUrlPathGenerator->getUrlPathWithSuffix($product, $storeId, $category) : $url->getTargetPath(); if ($url->getRequestPath() === $targetPath) { return []; } return [ $this->urlRewriteFactory->create() ->setEntityType(ProductUrlRewriteGenerator::ENTITY_TYPE) ->setEntityId($productId) ->setRequestPath($url->getRequestPath()) ->setTargetPath($targetPath) ->setRedirectType($url->getRedirectType()) ->setStoreId($storeId) ->setDescription($url->getDescription()) ->setIsAutogenerated(0) ->setMetadata($url->getMetadata()) ]; } return []; }
/** * Create url rewrite object * * @param array $data * @return \Magento\UrlRewrite\Service\V1\Data\UrlRewrite */ protected function createUrlRewrite($data) { $dataObject = $this->urlRewriteFactory->create(); $this->dataObjectHelper->populateWithArray($dataObject, $data, '\\Magento\\UrlRewrite\\Service\\V1\\Data\\UrlRewrite'); return $dataObject; }
/** * Create url rewrite object * * @param int $storeId * @param int $redirectType * @return \Magento\UrlRewrite\Service\V1\Data\UrlRewrite */ protected function createUrlRewrite($storeId, $redirectType = 0) { return $this->urlRewriteFactory->create()->setStoreId($storeId)->setEntityType(self::ENTITY_TYPE)->setEntityId($this->cmsPage->getId())->setRequestPath($this->cmsPage->getIdentifier())->setTargetPath($this->cmsPageUrlPathGenerator->getCanonicalUrlPath($this->cmsPage))->setIsAutogenerated(1)->setRedirectType($redirectType); }
/** * Generate list based on store view * * @param int $storeId * @param \Magento\Catalog\Model\Category $category * @return \Magento\UrlRewrite\Service\V1\Data\UrlRewrite[] */ public function generate($storeId, Category $category) { $urlPath = $this->categoryUrlPathGenerator->getUrlPathWithSuffix($category, $storeId); $result = [$urlPath . '_' . $storeId => $this->urlRewriteFactory->create()->setStoreId($storeId)->setEntityType(CategoryUrlRewriteGenerator::ENTITY_TYPE)->setEntityId($category->getId())->setRequestPath($urlPath)->setTargetPath($this->categoryUrlPathGenerator->getCanonicalUrlPath($category))]; return $result; }
/** * 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)]; }