@@ -489,16 +489,17 @@ private function processLinks(\Magento\Catalog\Api\Data\ProductInterface $produc
489
489
* @throws InputException
490
490
* @throws StateException
491
491
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
492
+ * @throws LocalizedException
492
493
*/
493
- protected function processMediaGallery (ProductInterface $ product , $ mediaGalleryEntries )
494
+ protected function processMediaGallery (ProductInterface $ product , array $ mediaGalleryEntries )
494
495
{
495
496
$ existingMediaGallery = $ product ->getMediaGallery ('images ' );
496
497
$ newEntries = [];
497
498
$ entriesById = [];
498
499
if (!empty ($ existingMediaGallery )) {
499
500
foreach ($ mediaGalleryEntries as $ entry ) {
500
- if (isset ($ entry ['value_id ' ])) {
501
- $ entriesById [$ entry ['value_id ' ]] = $ entry ;
501
+ if (isset ($ entry ['id ' ])) {
502
+ $ entriesById [$ entry ['id ' ]] = $ entry ;
502
503
} else {
503
504
$ newEntries [] = $ entry ;
504
505
}
@@ -515,6 +516,7 @@ protected function processMediaGallery(ProductInterface $product, $mediaGalleryE
515
516
$ existingEntry ['removed ' ] = true ;
516
517
}
517
518
}
519
+ unset($ existingEntry );
518
520
$ product ->setData ('media_gallery ' , ["images " => $ existingMediaGallery ]);
519
521
} else {
520
522
$ newEntries = $ mediaGalleryEntries ;
@@ -536,9 +538,9 @@ protected function processMediaGallery(ProductInterface $product, $mediaGalleryE
536
538
}
537
539
/** @var ImageContentInterface $contentDataObject */
538
540
$ contentDataObject = $ this ->contentFactory ->create ()
539
- ->setName ($ newEntry ['content ' ][' data ' ][ ImageContentInterface::NAME ])
540
- ->setBase64EncodedData ($ newEntry ['content ' ][' data ' ][ ImageContentInterface::BASE64_ENCODED_DATA ])
541
- ->setType ($ newEntry ['content ' ][' data ' ][ ImageContentInterface::TYPE ]);
541
+ ->setName ($ newEntry ['content ' ][ImageContentInterface::NAME ])
542
+ ->setBase64EncodedData ($ newEntry ['content ' ][ImageContentInterface::BASE64_ENCODED_DATA ])
543
+ ->setType ($ newEntry ['content ' ][ImageContentInterface::TYPE ]);
542
544
$ newEntry ['content ' ] = $ contentDataObject ;
543
545
$ this ->processNewMediaGalleryEntry ($ product , $ newEntry );
544
546
@@ -587,8 +589,8 @@ public function save(\Magento\Catalog\Api\Data\ProductInterface $product, $saveO
587
589
$ product = $ this ->initializeProductData ($ productDataArray , empty ($ existingProduct ));
588
590
589
591
$ this ->processLinks ($ product , $ productLinks );
590
- if (isset ($ productDataArray ['media_gallery ' ])) {
591
- $ this ->processMediaGallery ($ product , $ productDataArray ['media_gallery ' ][ ' images ' ]);
592
+ if (isset ($ productDataArray ['media_gallery_entries ' ])) {
593
+ $ this ->processMediaGallery ($ product , $ productDataArray ['media_gallery_entries ' ]);
592
594
}
593
595
594
596
if (!$ product ->getOptionsReadonly ()) {
0 commit comments