Skip to content

Commit

Permalink
#12259: Save and Duplicated product not working
Browse files Browse the repository at this point in the history
  • Loading branch information
ishakhsuvarov authored Dec 13, 2017
1 parent 0d3d70c commit 8e3348b
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions app/code/Magento/Catalog/Model/Product/Copier.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
<?php
/**
* Catalog product copier. Creates product duplicate
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Model\Product;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Model\Product;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\Catalog\Model\ProductFactory;
use Magento\Catalog\Model\Product\Option\Repository as OptionRepository;

/**
* Catalog product copier. Creates product duplicate
*/
class Copier
{
/**
* @var Option\Repository
* @var OptionRepository
*/
protected $optionRepository;

Expand All @@ -22,22 +28,22 @@ class Copier
protected $copyConstructor;

/**
* @var \Magento\Catalog\Model\ProductFactory
* @var ProductFactory
*/
protected $productFactory;

/**
* @var \Magento\Framework\EntityManager\MetadataPool
* @var MetadataPool
*/
protected $metadataPool;

/**
* @param CopyConstructorInterface $copyConstructor
* @param \Magento\Catalog\Model\ProductFactory $productFactory
* @param ProductFactory $productFactory
*/
public function __construct(
CopyConstructorInterface $copyConstructor,
\Magento\Catalog\Model\ProductFactory $productFactory
ProductFactory $productFactory
) {
$this->productFactory = $productFactory;
$this->copyConstructor = $copyConstructor;
Expand All @@ -46,16 +52,16 @@ public function __construct(
/**
* Create product duplicate
*
* @param \Magento\Catalog\Model\Product $product
* @return \Magento\Catalog\Model\Product
* @param Product $product
* @return Product
*/
public function copy(\Magento\Catalog\Model\Product $product)
public function copy(Product $product)
{
$product->getWebsiteIds();
$product->getCategoryIds();

$metadata = $this->getMetadataPool()->getMetadata(ProductInterface::class);

/** @var \Magento\Catalog\Model\Product $duplicate */
$duplicate = $this->productFactory->create();
$productData = $product->getData();
$productData = $this->removeStockItem($productData);
Expand Down Expand Up @@ -93,27 +99,25 @@ public function copy(\Magento\Catalog\Model\Product $product)
}

/**
* @return Option\Repository
* @return OptionRepository
* @deprecated 101.0.0
*/
private function getOptionRepository()
{
if (null === $this->optionRepository) {
$this->optionRepository = \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Catalog\Model\Product\Option\Repository::class);
$this->optionRepository = ObjectManager::getInstance()->get(OptionRepository::class);
}
return $this->optionRepository;
}

/**
* @return \Magento\Framework\EntityManager\MetadataPool
* @return MetadataPool
* @deprecated 101.0.0
*/
private function getMetadataPool()
{
if (null === $this->metadataPool) {
$this->metadataPool = \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Framework\EntityManager\MetadataPool::class);
$this->metadataPool = ObjectManager::getInstance()->get(MetadataPool::class);
}
return $this->metadataPool;
}
Expand Down

0 comments on commit 8e3348b

Please sign in to comment.