Skip to content

Commit 8c692e6

Browse files
author
Michail Slabko
committed
MAGETWO-44274: SQL error appears if Save & Duplicate product with images
1 parent 35bbb0a commit 8c692e6

File tree

2 files changed

+5
-2
lines changed
  • app/code/Magento/Catalog/Model

2 files changed

+5
-2
lines changed

app/code/Magento/Catalog/Model/Product/Attribute/Backend/Media.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function beforeSave($object)
8585
// For duplicating we need copy original images.
8686
$duplicate = [];
8787
foreach ($value['images'] as &$image) {
88-
if (empty($image['value_id'])) {
88+
if (empty($image['value_id']) || !empty($image['removed'])) {
8989
continue;
9090
}
9191
$duplicate[$image['value_id']] = $this->copyImage($image['file']);

app/code/Magento/Catalog/Model/ResourceModel/Product/Attribute/Backend/Media.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,12 @@ public function duplicate($attributeId, $newFiles, $originalProductId, $newProdu
324324
foreach ($this->getConnection()->fetchAll($select) as $row) {
325325
$data = [
326326
'attribute_id' => $attributeId,
327-
'entity_id' => $newProductId,
328327
'value' => isset($newFiles[$row['value_id']]) ? $newFiles[$row['value_id']] : $row['value'],
329328
];
330329

331330
$valueIdMap[$row['value_id']] = $this->insertGallery($data);
331+
$this->bindValueToEntity($valueIdMap[$row['value_id']], $newProductId);
332+
332333
}
333334

334335
if (count($valueIdMap) == 0) {
@@ -344,6 +345,8 @@ public function duplicate($attributeId, $newFiles, $originalProductId, $newProdu
344345
);
345346

346347
foreach ($this->getConnection()->fetchAll($select) as $row) {
348+
unset($row['record_id']);
349+
$row['entity_id'] = $newProductId;
347350
$row['value_id'] = $valueIdMap[$row['value_id']];
348351
$this->insertGalleryValueInStore($row);
349352
}

0 commit comments

Comments
 (0)