Skip to content

Commit 5aef35b

Browse files
committed
10797: catalogProductTierPriceManagementV1 DELETE and POST operation wipes out media gallery selections when used on store code "all".
1 parent 7959af7 commit 5aef35b

File tree

1 file changed

+39
-23
lines changed

1 file changed

+39
-23
lines changed

app/code/Magento/Catalog/Model/ProductRepository.php

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,8 @@ private function processLinks(\Magento\Catalog\Api\Data\ProductInterface $produc
488488
* @return $this
489489
* @throws InputException
490490
* @throws StateException
491-
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
492491
* @throws LocalizedException
492+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
493493
*/
494494
protected function processMediaGallery(ProductInterface $product, array $mediaGalleryEntries)
495495
{
@@ -531,29 +531,8 @@ protected function processMediaGallery(ProductInterface $product, array $mediaGa
531531
}
532532
}
533533
}
534+
$this->processEntries($product, $newEntries, $entriesById);
534535

535-
foreach ($newEntries as $newEntry) {
536-
if (!isset($newEntry['content'])) {
537-
throw new InputException(__('The image content is not valid.'));
538-
}
539-
/** @var ImageContentInterface $contentDataObject */
540-
$contentDataObject = $this->contentFactory->create()
541-
->setName($newEntry['content'][ImageContentInterface::NAME])
542-
->setBase64EncodedData($newEntry['content'][ImageContentInterface::BASE64_ENCODED_DATA])
543-
->setType($newEntry['content'][ImageContentInterface::TYPE]);
544-
$newEntry['content'] = $contentDataObject;
545-
$this->processNewMediaGalleryEntry($product, $newEntry);
546-
547-
$finalGallery = $product->getData('media_gallery');
548-
$newEntryId = key(array_diff_key($product->getData('media_gallery')['images'], $entriesById));
549-
if (isset($newEntry['extension_attributes'])) {
550-
$this->processExtensionAttributes($newEntry, $newEntry['extension_attributes']);
551-
}
552-
$newEntry = array_replace_recursive($newEntry, $finalGallery['images'][$newEntryId]);
553-
$entriesById[$newEntryId] = $newEntry;
554-
$finalGallery['images'][$newEntryId] = $newEntry;
555-
$product->setData('media_gallery', $finalGallery);
556-
}
557536
return $this;
558537
}
559538

@@ -810,4 +789,41 @@ private function processExtensionAttributes(array &$newEntry, array $extensionAt
810789
}
811790
unset($newEntry['extension_attributes']);
812791
}
792+
793+
/**
794+
* Convert entries into product media gallery data and set to product.
795+
*
796+
* @param ProductInterface $product
797+
* @param array $newEntries
798+
* @param array $entriesById
799+
* @throws InputException
800+
* @throws LocalizedException
801+
* @throws StateException
802+
* @return void
803+
*/
804+
private function processEntries(ProductInterface $product, array $newEntries, array $entriesById)
805+
{
806+
foreach ($newEntries as $newEntry) {
807+
if (!isset($newEntry['content'])) {
808+
throw new InputException(__('The image content is not valid.'));
809+
}
810+
/** @var ImageContentInterface $contentDataObject */
811+
$contentDataObject = $this->contentFactory->create()
812+
->setName($newEntry['content'][ImageContentInterface::NAME])
813+
->setBase64EncodedData($newEntry['content'][ImageContentInterface::BASE64_ENCODED_DATA])
814+
->setType($newEntry['content'][ImageContentInterface::TYPE]);
815+
$newEntry['content'] = $contentDataObject;
816+
$this->processNewMediaGalleryEntry($product, $newEntry);
817+
818+
$finalGallery = $product->getData('media_gallery');
819+
$newEntryId = key(array_diff_key($product->getData('media_gallery')['images'], $entriesById));
820+
if (isset($newEntry['extension_attributes'])) {
821+
$this->processExtensionAttributes($newEntry, $newEntry['extension_attributes']);
822+
}
823+
$newEntry = array_replace_recursive($newEntry, $finalGallery['images'][$newEntryId]);
824+
$entriesById[$newEntryId] = $newEntry;
825+
$finalGallery['images'][$newEntryId] = $newEntry;
826+
$product->setData('media_gallery', $finalGallery);
827+
}
828+
}
813829
}

0 commit comments

Comments
 (0)