/** * @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; }
public function testGetUrlPathWithSuffixWithoutStore() { $urlPath = 'url-path'; $storeId = null; $currentStoreId = 1; $suffix = '.html'; $result = 'url-path.html'; $this->category->expects($this->any())->method('getStoreId')->will($this->returnValue($storeId)); $this->category->expects($this->once())->method('getParentId')->will($this->returnValue('parent_id')); $this->category->expects($this->once())->method('getUrlPath')->will($this->returnValue($urlPath)); $this->category->expects($this->exactly(2))->method('dataHasChangedFor') ->will($this->returnValueMap([['url_key', false], ['path_ids', false]])); $store = $this->getMock('Magento\Store\Model\Store', [], [], '', false); $store->expects($this->once())->method('getId')->will($this->returnValue($currentStoreId)); $this->storeManager->expects($this->once())->method('getStore')->will($this->returnValue($store)); $this->scopeConfig->expects($this->once())->method('getValue') ->with(CategoryUrlPathGenerator::XML_PATH_CATEGORY_URL_SUFFIX, ScopeInterface::SCOPE_STORE, $currentStoreId) ->will($this->returnValue($suffix)); $this->assertEquals( $result, $this->categoryUrlPathGenerator->getUrlPathWithSuffix($this->category, $storeId) ); }
/** * 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; }
/** * @param \Magento\Catalog\Model\Product|null $product * @param \Magento\Catalog\Model\Category|null $category * @return string */ protected function getRequestPath($product = null, $category = null) { return $product ? $this->productUrlPathGenerator->getUrlPathWithSuffix($product, $product->getStoreId(), $category) : $this->categoryUrlPathGenerator->getUrlPathWithSuffix($category); }