Skip to content

Commit 1b714e4

Browse files
author
Yaroslav Onischenko
committed
Merge remote-tracking branch 'origin/MAGETWO-51948' into develop
2 parents 1af1f48 + c1e27df commit 1b714e4

File tree

1 file changed

+26
-2
lines changed
  • app/code/Magento/CatalogSampleData/Model/Product

1 file changed

+26
-2
lines changed

app/code/Magento/CatalogSampleData/Model/Product/Gallery.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Magento\Catalog\Model\ProductFactory;
99
use Magento\Catalog\Model\ResourceModel\Product\Gallery as GalleryResource;
1010
use Magento\Framework\Setup\SampleData\Context as SampleDataContext;
11+
use Magento\Framework\App\ObjectManager;
12+
use Magento\Catalog\Api\Data\ProductInterface;
1113

1214
/**
1315
* Class Gallery
@@ -44,6 +46,11 @@ class Gallery
4446
*/
4547
protected $eavConfig;
4648

49+
/**
50+
* @var \Magento\Framework\EntityManager\MetadataPool
51+
*/
52+
private $metadataPool;
53+
4754
/**
4855
* @param SampleDataContext $sampleDataContext
4956
* @param ProductFactory $productFactory
@@ -122,15 +129,16 @@ protected function storeImage($product, $images)
122129
if (strpos($image, '_main') !== false) {
123130
$baseImage = $image;
124131
}
132+
$linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
125133
$id = $this->galleryResource->insertGallery([
126134
'attribute_id' => $mediaAttribute->getAttributeId(),
127-
'entity_id' => $product->getId(),
135+
$linkField => $product->getId(),
128136
'value' => $image,
129137
]);
130138
$this->galleryResource->insertGalleryValueInStore([
131139
'value_id' => $id,
132140
'store_id' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
133-
'entity_id' => $product->getId(),
141+
$linkField => $product->getId(),
134142
'label' => 'Image',
135143
'position' => $i,
136144
'disables' => 0,
@@ -160,4 +168,20 @@ protected function storeImage($product, $images)
160168
}
161169
}
162170
}
171+
172+
/**
173+
* @deprecated
174+
*
175+
* @return \Magento\Framework\EntityManager\MetadataPool|mixed
176+
*/
177+
private function getMetadataPool()
178+
{
179+
if (!($this->metadataPool)) {
180+
return ObjectManager::getInstance()->get(
181+
'\Magento\Framework\EntityManager\MetadataPool'
182+
);
183+
} else {
184+
return $this->metadataPool;
185+
}
186+
}
163187
}

0 commit comments

Comments
 (0)