Skip to content

Commit

Permalink
Merge pull request #620 from magento-troll/M2BetaBugfixes
Browse files Browse the repository at this point in the history
[Merchant Beta] Bugfixes
  • Loading branch information
slopukhov committed Sep 22, 2015
2 parents ca40259 + 4b149ca commit f45f957
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,14 @@ protected function canonicalUrlRewriteGenerate()
$urls = [];
foreach ($this->products as $productId => $productsByStores) {
foreach ($productsByStores as $storeId => $product) {
$urls[] = $this->urlRewriteFactory->create()
->setEntityType(ProductUrlRewriteGenerator::ENTITY_TYPE)
->setEntityId($productId)
->setRequestPath($this->productUrlPathGenerator->getUrlPathWithSuffix($product, $storeId))
->setTargetPath($this->productUrlPathGenerator->getCanonicalUrlPath($product))
->setStoreId($storeId);
if ($this->productUrlPathGenerator->getUrlPath($product)) {
$urls[] = $this->urlRewriteFactory->create()
->setEntityType(ProductUrlRewriteGenerator::ENTITY_TYPE)
->setEntityId($productId)
->setRequestPath($this->productUrlPathGenerator->getUrlPathWithSuffix($product, $storeId))
->setTargetPath($this->productUrlPathGenerator->getCanonicalUrlPath($product))
->setStoreId($storeId);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ public function testClearProductUrls()
/**
* Cover canonicalUrlRewriteGenerate().
*/
public function testCanonicalUrlRewriteGenerate()
public function testCanonicalUrlRewriteGenerateWithUrlPath()
{
$productId = 'product_id';
$requestPath = 'simple-product.html';
Expand All @@ -704,6 +704,10 @@ public function testCanonicalUrlRewriteGenerate()
->expects($this->once())
->method('getUrlPathWithSuffix')
->will($this->returnValue($requestPath));
$this->productUrlPathGenerator
->expects($this->once())
->method('getUrlPath')
->will($this->returnValue('urlPath'));
$this->productUrlPathGenerator
->expects($this->once())
->method('getCanonicalUrlPath')
Expand Down Expand Up @@ -747,6 +751,36 @@ public function testCanonicalUrlRewriteGenerate()
);
}

/**
* Cover canonicalUrlRewriteGenerate().
*/
public function testCanonicalUrlRewriteGenerateWithEmptyUrlPath()
{
$productId = 'product_id';
$storeId = 10;
$product = $this
->getMockBuilder('Magento\Catalog\Model\Product')
->disableOriginalConstructor()
->getMock();
$productsByStores = [$storeId => $product];
$products = [
$productId => $productsByStores,
];

$this->setPropertyValue($this->import, 'products', $products);

$this->productUrlPathGenerator
->expects($this->once())
->method('getUrlPath')
->will($this->returnValue(''));
$this->urlRewriteFactory
->expects($this->never())
->method('create');

$actualResult = $this->invokeMethod($this->import, 'canonicalUrlRewriteGenerate');
$this->assertEquals([], $actualResult);
}

/**
* Cover categoriesUrlRewriteGenerate().
*/
Expand Down

0 comments on commit f45f957

Please sign in to comment.