/** * @param \Magento\Framework\App\RequestInterface $request * @param UrlRewrite $rewrite * @return \Magento\Framework\App\ActionInterface|null */ protected function processRedirect($request, $rewrite) { $target = $rewrite->getTargetPath(); if ($rewrite->getEntityType() !== Rewrite::ENTITY_TYPE_CUSTOM || ($prefix = substr($target, 0, 6)) !== 'http:/' && $prefix !== 'https:') { $target = $this->url->getUrl('', ['_direct' => $target]); } return $this->redirect($request, $target, $rewrite->getRedirectType()); }
/** * @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 mixed $storeId * @param mixed $categoryId * @param mixed $requestPath * @param mixed $targetPath * @param mixed $redirectType */ protected function prepareUrlRewriteMock($storeId, $categoryId, $requestPath, $targetPath, $redirectType) { $this->urlRewrite->expects($this->any())->method('setStoreId')->with($storeId)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setEntityId')->with($categoryId)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setEntityType')->with(CategoryUrlRewriteGenerator::ENTITY_TYPE)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setRequestPath')->with($requestPath)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setTargetPath')->with($targetPath)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setIsAutogenerated')->with(0)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setRedirectType')->with($redirectType)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setMetadata')->with([])->will($this->returnSelf()); $this->urlRewriteFactory->expects($this->any())->method('create')->will($this->returnValue($this->urlRewrite)); }
/** * @param mixed $storeId * @param mixed $productId * @param mixed $requestPath * @param mixed $targetPath * @param mixed $redirectType * @param mixed $metadata * @param mixed $description */ protected function prepareUrlRewriteMock($storeId, $productId, $requestPath, $targetPath, $redirectType, $metadata, $description) { $this->urlRewrite->expects($this->any())->method('setStoreId')->with($storeId)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setEntityId')->with($productId)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setEntityType')->with(ProductUrlRewriteGenerator::ENTITY_TYPE)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setRequestPath')->with($requestPath)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setTargetPath')->with($targetPath)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setIsAutogenerated')->with(0)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setRedirectType')->with($redirectType)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setMetadata')->with($metadata)->will($this->returnSelf()); $this->urlRewriteFactory->expects($this->any())->method('create')->will($this->returnValue($this->urlRewrite)); $this->urlRewrite->expects($this->once())->method('setDescription')->with($description)->will($this->returnSelf()); }
public function testGenerate() { $requestPath = 'category.html'; $targetPath = 'target-path'; $storeId = 'store_id'; $categoryId = 'category_id'; $this->category->expects($this->any())->method('getId')->will($this->returnValue($categoryId)); $this->categoryUrlPathGenerator->expects($this->any())->method('getUrlPathWithSuffix')->will($this->returnValue($requestPath)); $this->categoryUrlPathGenerator->expects($this->any())->method('getCanonicalUrlPath')->will($this->returnValue($targetPath)); $this->urlRewrite->expects($this->any())->method('setStoreId')->with($storeId)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setEntityId')->with($categoryId)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setEntityType')->with(CategoryUrlRewriteGenerator::ENTITY_TYPE)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setRequestPath')->with($requestPath)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setTargetPath')->with($targetPath)->will($this->returnSelf()); $this->urlRewriteFactory->expects($this->any())->method('create')->will($this->returnValue($this->urlRewrite)); $this->assertEquals(['category.html_store_id' => $this->urlRewrite], $this->canonicalUrlRewriteGenerator->generate($storeId, $this->category)); }
public function testGenerate() { $requestPath = 'simple-product.html'; $storeId = 10; $productId = 'product_id'; $targetPath = 'catalog/product/view/id/' . $productId; $this->product->expects($this->any())->method('getId')->will($this->returnValue($productId)); $this->productUrlPathGenerator->expects($this->any())->method('getUrlPathWithSuffix')->will($this->returnValue($requestPath)); $this->productUrlPathGenerator->expects($this->any())->method('getCanonicalUrlPath')->will($this->returnValue($targetPath)); $this->categoryRegistry->expects($this->any())->method('getList')->will($this->returnValue([])); $this->urlRewrite->expects($this->any())->method('setStoreId')->with($storeId)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setEntityId')->with($productId)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setEntityType')->with(ProductUrlRewriteGenerator::ENTITY_TYPE)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setRequestPath')->with($requestPath)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setTargetPath')->with($targetPath)->will($this->returnSelf()); $this->urlRewriteFactory->expects($this->any())->method('create')->will($this->returnValue($this->urlRewrite)); $this->assertEquals([$this->urlRewrite], $this->canonicalUrlRewriteGenerator->generate($storeId, $this->product)); }
public function testGenerateCategories() { $urlPathWithCategory = 'category/simple-product.html'; $storeId = 10; $productId = 'product_id'; $canonicalUrlPathWithCategory = 'canonical-path-with-category'; $categoryId = 'category_id'; $this->product->expects($this->any())->method('getId')->will($this->returnValue($productId)); $this->productUrlPathGenerator->expects($this->any())->method('getUrlPathWithSuffix')->will($this->returnValue($urlPathWithCategory)); $this->productUrlPathGenerator->expects($this->any())->method('getCanonicalUrlPath')->will($this->returnValue($canonicalUrlPathWithCategory)); $category = $this->getMock('Magento\\Catalog\\Model\\Category', [], [], '', false); $category->expects($this->any())->method('getId')->will($this->returnValue($categoryId)); $this->categoryRegistry->expects($this->any())->method('getList')->will($this->returnValue([$category])); $this->urlRewrite->expects($this->any())->method('setStoreId')->with($storeId)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setEntityId')->with($productId)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setEntityType')->with(ProductUrlRewriteGenerator::ENTITY_TYPE)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setRequestPath')->with($urlPathWithCategory)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setTargetPath')->with($canonicalUrlPathWithCategory)->will($this->returnSelf()); $this->urlRewrite->expects($this->any())->method('setMetadata')->with(['category_id' => $categoryId])->will($this->returnSelf()); $this->urlRewriteFactory->expects($this->any())->method('create')->will($this->returnValue($this->urlRewrite)); $this->assertEquals([$this->urlRewrite], $this->categoriesUrlRewriteGenerator->generate($storeId, $this->product, $this->categoryRegistry)); }
/** * @param UrlRewrite $url * @return bool */ protected function isCorrectUrl(UrlRewrite $url) { $metadata = $url->getMetadata(); return $url->getEntityType() == ProductUrlRewriteGenerator::ENTITY_TYPE && !empty($metadata['category_id']) && $url->getIsAutogenerated(); }
/** * @param UrlRewrite $url * @return Category|null|bool */ protected function retrieveCategoryFromMetadata($url) { $metadata = $url->getMetadata(); if (isset($metadata['category_id'])) { $category = $this->import->getCategoryProcessor()->getCategoryById($metadata['category_id']); return $category === null ? false : $category; } return null; }
/** * @param UrlRewrite $url * @return Category|null|bool */ protected function retrieveCategoryFromMetadata($url) { $metadata = $url->getMetadata(); if (isset($metadata['category_id'])) { $category = $this->productCategories->get($metadata['category_id']); return $category === null ? false : $category; } return null; }