Skip to content

Commit f45f957

Browse files
committed
Merge pull request #620 from magento-troll/M2BetaBugfixes
[Merchant Beta] Bugfixes
2 parents ca40259 + 4b149ca commit f45f957

File tree

2 files changed

+43
-7
lines changed

2 files changed

+43
-7
lines changed

app/code/Magento/CatalogUrlRewrite/Model/Product/Plugin/Import.php

+8-6
Original file line numberDiff line numberDiff line change
@@ -320,12 +320,14 @@ protected function canonicalUrlRewriteGenerate()
320320
$urls = [];
321321
foreach ($this->products as $productId => $productsByStores) {
322322
foreach ($productsByStores as $storeId => $product) {
323-
$urls[] = $this->urlRewriteFactory->create()
324-
->setEntityType(ProductUrlRewriteGenerator::ENTITY_TYPE)
325-
->setEntityId($productId)
326-
->setRequestPath($this->productUrlPathGenerator->getUrlPathWithSuffix($product, $storeId))
327-
->setTargetPath($this->productUrlPathGenerator->getCanonicalUrlPath($product))
328-
->setStoreId($storeId);
323+
if ($this->productUrlPathGenerator->getUrlPath($product)) {
324+
$urls[] = $this->urlRewriteFactory->create()
325+
->setEntityType(ProductUrlRewriteGenerator::ENTITY_TYPE)
326+
->setEntityId($productId)
327+
->setRequestPath($this->productUrlPathGenerator->getUrlPathWithSuffix($product, $storeId))
328+
->setTargetPath($this->productUrlPathGenerator->getCanonicalUrlPath($product))
329+
->setStoreId($storeId);
330+
}
329331
}
330332
}
331333

app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Product/Plugin/ImportTest.php

+35-1
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ public function testClearProductUrls()
683683
/**
684684
* Cover canonicalUrlRewriteGenerate().
685685
*/
686-
public function testCanonicalUrlRewriteGenerate()
686+
public function testCanonicalUrlRewriteGenerateWithUrlPath()
687687
{
688688
$productId = 'product_id';
689689
$requestPath = 'simple-product.html';
@@ -704,6 +704,10 @@ public function testCanonicalUrlRewriteGenerate()
704704
->expects($this->once())
705705
->method('getUrlPathWithSuffix')
706706
->will($this->returnValue($requestPath));
707+
$this->productUrlPathGenerator
708+
->expects($this->once())
709+
->method('getUrlPath')
710+
->will($this->returnValue('urlPath'));
707711
$this->productUrlPathGenerator
708712
->expects($this->once())
709713
->method('getCanonicalUrlPath')
@@ -747,6 +751,36 @@ public function testCanonicalUrlRewriteGenerate()
747751
);
748752
}
749753

754+
/**
755+
* Cover canonicalUrlRewriteGenerate().
756+
*/
757+
public function testCanonicalUrlRewriteGenerateWithEmptyUrlPath()
758+
{
759+
$productId = 'product_id';
760+
$storeId = 10;
761+
$product = $this
762+
->getMockBuilder('Magento\Catalog\Model\Product')
763+
->disableOriginalConstructor()
764+
->getMock();
765+
$productsByStores = [$storeId => $product];
766+
$products = [
767+
$productId => $productsByStores,
768+
];
769+
770+
$this->setPropertyValue($this->import, 'products', $products);
771+
772+
$this->productUrlPathGenerator
773+
->expects($this->once())
774+
->method('getUrlPath')
775+
->will($this->returnValue(''));
776+
$this->urlRewriteFactory
777+
->expects($this->never())
778+
->method('create');
779+
780+
$actualResult = $this->invokeMethod($this->import, 'canonicalUrlRewriteGenerate');
781+
$this->assertEquals([], $actualResult);
782+
}
783+
750784
/**
751785
* Cover categoriesUrlRewriteGenerate().
752786
*/

0 commit comments

Comments
 (0)