Skip to content

Commit

Permalink
Merge branch '#21737_Duplicating_product_url_keys' of github.com:yvec…
Browse files Browse the repository at this point in the history
…hirko/magento2 into #21737_Duplicating_product_url_keys
  • Loading branch information
yvechirko committed Apr 23, 2019
2 parents 5c384be + a45d519 commit 9721c67
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
17 changes: 10 additions & 7 deletions app/code/Magento/Catalog/Model/Product/Copier.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php
/**
* Catalog product copier. Creates product duplicate
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
Expand All @@ -11,7 +9,11 @@
use Magento\Catalog\Model\Product;

/**
* The copier creates product duplicates.
* Catalog product copier.
*
* Creates product duplicate.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Copier
{
Expand Down Expand Up @@ -120,10 +122,10 @@ private function setStoresUrl(Product $product, Product $duplicate) : void
$productId = $product->getId();
$productResource = $product->getResource();
$defaultUrlKey = $productResource->getAttributeRawValue(
$productId,
'url_key',
\Magento\Store\Model\Store::DEFAULT_STORE_ID
);
$productId,
'url_key',
\Magento\Store\Model\Store::DEFAULT_STORE_ID
);
$duplicate->setData('save_rewrites_history', false);
foreach ($storeIds as $storeId) {
$isDuplicateSaved = false;
Expand All @@ -139,6 +141,7 @@ private function setStoresUrl(Product $product, Product $duplicate) : void
try {
$duplicate->save();
$isDuplicateSaved = true;
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock
} catch (\Magento\Framework\Exception\AlreadyExistsException $e) {
}
} while (!$isDuplicateSaved);
Expand Down
39 changes: 22 additions & 17 deletions app/code/Magento/Catalog/Test/Unit/Model/Product/CopierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
namespace Magento\Catalog\Test\Unit\Model\Product;

use Magento\Catalog\Api\Data\ProductInterface;
use \Magento\Catalog\Model\Product\Copier;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\Product\Copier;

/**
* Test for Magento\Catalog\Model\Product\Copier class.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class CopierTest extends \PHPUnit\Framework\TestCase
Expand Down Expand Up @@ -76,6 +78,9 @@ protected function setUp()
]);
}

/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testCopy()
{
$stockItem = $this->getMockBuilder(\Magento\CatalogInventory\Api\Data\StockItemInterface::class)
Expand Down Expand Up @@ -104,27 +109,27 @@ public function testCopy()
]);

$entityMock = $this->getMockForAbstractClass(
\Magento\Eav\Model\Entity\AbstractEntity::class,
[],
'',
false,
true,
true,
['checkAttributeUniqueValue']
);
\Magento\Eav\Model\Entity\AbstractEntity::class,
[],
'',
false,
true,
true,
['checkAttributeUniqueValue']
);
$entityMock->expects($this->any())
->method('checkAttributeUniqueValue')
->willReturn(true);

$attributeMock = $this->getMockForAbstractClass(
\Magento\Eav\Model\Entity\Attribute\AbstractAttribute::class,
[],
'',
false,
true,
true,
['getEntity']
);
\Magento\Eav\Model\Entity\Attribute\AbstractAttribute::class,
[],
'',
false,
true,
true,
['getEntity']
);
$attributeMock->expects($this->any())
->method('getEntity')
->willReturn($entityMock);
Expand Down

0 comments on commit 9721c67

Please sign in to comment.