|
10 | 10 | use Magento\Framework\Exception\CouldNotSaveException;
|
11 | 11 | use Magento\Framework\Exception\NoSuchEntityException;
|
12 | 12 | use Magento\Framework\EntityManager\MetadataPool;
|
| 13 | +use Magento\Framework\EntityManager\HydratorPool; |
13 | 14 |
|
14 | 15 | /**
|
15 | 16 | * Class Repository
|
@@ -42,6 +43,11 @@ class Repository implements \Magento\Catalog\Api\ProductCustomOptionRepositoryIn
|
42 | 43 | */
|
43 | 44 | protected $metadataPool;
|
44 | 45 |
|
| 46 | + /** |
| 47 | + * @var HydratorPool |
| 48 | + */ |
| 49 | + protected $hydratorPool; |
| 50 | + |
45 | 51 | /**
|
46 | 52 | * @var Converter
|
47 | 53 | */
|
@@ -113,11 +119,12 @@ public function duplicate(
|
113 | 119 | \Magento\Catalog\Api\Data\ProductInterface $product,
|
114 | 120 | \Magento\Catalog\Api\Data\ProductInterface $duplicate
|
115 | 121 | ) {
|
| 122 | + $hydrator = $this->getHydratorPool()->getHydrator(ProductInterface::class); |
116 | 123 | $metadata = $this->getMetadataPool()->getMetadata(ProductInterface::class);
|
117 | 124 | return $this->optionResource->duplicate(
|
118 | 125 | $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()] |
121 | 128 | );
|
122 | 129 | }
|
123 | 130 |
|
@@ -226,4 +233,17 @@ private function getMetadataPool()
|
226 | 233 | }
|
227 | 234 | return $this->metadataPool;
|
228 | 235 | }
|
| 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 | + } |
229 | 249 | }
|
0 commit comments