Skip to content

Commit 15a8c1a

Browse files
committed
MAGETWO-51951: SQL Error when cloning product with custom option with CatalogStaging enabled
1 parent fbf848f commit 15a8c1a

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

app/code/Magento/Catalog/Model/Product/Option/Repository.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Framework\Exception\CouldNotSaveException;
1111
use Magento\Framework\Exception\NoSuchEntityException;
1212
use Magento\Framework\EntityManager\MetadataPool;
13+
use Magento\Framework\EntityManager\HydratorPool;
1314

1415
/**
1516
* Class Repository
@@ -42,6 +43,11 @@ class Repository implements \Magento\Catalog\Api\ProductCustomOptionRepositoryIn
4243
*/
4344
protected $metadataPool;
4445

46+
/**
47+
* @var HydratorPool
48+
*/
49+
protected $hydratorPool;
50+
4551
/**
4652
* @var Converter
4753
*/
@@ -113,11 +119,12 @@ public function duplicate(
113119
\Magento\Catalog\Api\Data\ProductInterface $product,
114120
\Magento\Catalog\Api\Data\ProductInterface $duplicate
115121
) {
122+
$hydrator = $this->getHydratorPool()->getHydrator(ProductInterface::class);
116123
$metadata = $this->getMetadataPool()->getMetadata(ProductInterface::class);
117124
return $this->optionResource->duplicate(
118125
$this->getOptionFactory()->create([]),
119-
$product->getData($metadata->getLinkField()),
120-
$duplicate->getData($metadata->getLinkField())
126+
$hydrator->extract($product)[$metadata->getLinkField()],
127+
$hydrator->extract($duplicate)[$metadata->getLinkField()]
121128
);
122129
}
123130

@@ -226,4 +233,17 @@ private function getMetadataPool()
226233
}
227234
return $this->metadataPool;
228235
}
236+
237+
/**
238+
* @return \Magento\Framework\EntityManager\HydratorPool
239+
* @deprecated
240+
*/
241+
private function getHydratorPool()
242+
{
243+
if (null === $this->hydratorPool) {
244+
$this->hydratorPool = \Magento\Framework\App\ObjectManager::getInstance()
245+
->get('Magento\Framework\EntityManager\HydratorPool');
246+
}
247+
return $this->hydratorPool;
248+
}
229249
}

0 commit comments

Comments
 (0)