/** * 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; }
public function testFindOneByDataIfFound() { $data = [['field1' => 'value1']]; $row = ['row1']; $urlRewrite = ['urlRewrite1']; $this->storage->expects($this->once())->method('doFindOneByData')->with($data)->will($this->returnValue($row)); $this->dataObjectHelper->expects($this->once())->method('populateWithArray')->with($urlRewrite, $row, '\\Magento\\UrlRewrite\\Service\\V1\\Data\\UrlRewrite')->will($this->returnSelf()); $this->urlRewriteFactory->expects($this->any())->method('create')->will($this->returnValue($urlRewrite)); $this->assertEquals($urlRewrite, $this->storage->findOneByData($data)); }
public function testFindOneByData() { $data = ['col1' => 'val1', 'col2' => 'val2']; $this->select->expects($this->at(1))->method('where')->with('col1 IN (?)', 'val1'); $this->select->expects($this->at(2))->method('where')->with('col2 IN (?)', 'val2'); $this->adapter->expects($this->any())->method('quoteIdentifier')->will($this->returnArgument(0)); $this->adapter->expects($this->once())->method('fetchRow')->with($this->select)->will($this->returnValue(['row1'])); $this->dataObjectHelper->expects($this->at(0))->method('populateWithArray')->with(['urlRewrite1'], ['row1'], '\\Magento\\UrlRewrite\\Service\\V1\\Data\\UrlRewrite')->will($this->returnSelf()); $this->urlRewriteFactory->expects($this->at(0))->method('create')->will($this->returnValue(['urlRewrite1'])); $this->assertEquals(['urlRewrite1'], $this->storage->findOneByData($data)); }
/** * @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 []; }
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)); }
/** * @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)); }
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 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()); }
/** * 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)]; }