Skip to content

Commit

Permalink
10797: catalogProductTierPriceManagementV1 DELETE and POST operation …
Browse files Browse the repository at this point in the history
…wipes out media gallery selections when used on store code "all".
  • Loading branch information
nmalevanec committed Dec 7, 2017
1 parent 7959af7 commit 5aef35b
Showing 1 changed file with 39 additions and 23 deletions.
62 changes: 39 additions & 23 deletions app/code/Magento/Catalog/Model/ProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,8 @@ private function processLinks(\Magento\Catalog\Api\Data\ProductInterface $produc
* @return $this
* @throws InputException
* @throws StateException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @throws LocalizedException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
protected function processMediaGallery(ProductInterface $product, array $mediaGalleryEntries)
{
Expand Down Expand Up @@ -531,29 +531,8 @@ protected function processMediaGallery(ProductInterface $product, array $mediaGa
}
}
}
$this->processEntries($product, $newEntries, $entriesById);

foreach ($newEntries as $newEntry) {
if (!isset($newEntry['content'])) {
throw new InputException(__('The image content is not valid.'));
}
/** @var ImageContentInterface $contentDataObject */
$contentDataObject = $this->contentFactory->create()
->setName($newEntry['content'][ImageContentInterface::NAME])
->setBase64EncodedData($newEntry['content'][ImageContentInterface::BASE64_ENCODED_DATA])
->setType($newEntry['content'][ImageContentInterface::TYPE]);
$newEntry['content'] = $contentDataObject;
$this->processNewMediaGalleryEntry($product, $newEntry);

$finalGallery = $product->getData('media_gallery');
$newEntryId = key(array_diff_key($product->getData('media_gallery')['images'], $entriesById));
if (isset($newEntry['extension_attributes'])) {
$this->processExtensionAttributes($newEntry, $newEntry['extension_attributes']);
}
$newEntry = array_replace_recursive($newEntry, $finalGallery['images'][$newEntryId]);
$entriesById[$newEntryId] = $newEntry;
$finalGallery['images'][$newEntryId] = $newEntry;
$product->setData('media_gallery', $finalGallery);
}
return $this;
}

Expand Down Expand Up @@ -810,4 +789,41 @@ private function processExtensionAttributes(array &$newEntry, array $extensionAt
}
unset($newEntry['extension_attributes']);
}

/**
* Convert entries into product media gallery data and set to product.
*
* @param ProductInterface $product
* @param array $newEntries
* @param array $entriesById
* @throws InputException
* @throws LocalizedException
* @throws StateException
* @return void
*/
private function processEntries(ProductInterface $product, array $newEntries, array $entriesById)
{
foreach ($newEntries as $newEntry) {
if (!isset($newEntry['content'])) {
throw new InputException(__('The image content is not valid.'));
}
/** @var ImageContentInterface $contentDataObject */
$contentDataObject = $this->contentFactory->create()
->setName($newEntry['content'][ImageContentInterface::NAME])
->setBase64EncodedData($newEntry['content'][ImageContentInterface::BASE64_ENCODED_DATA])
->setType($newEntry['content'][ImageContentInterface::TYPE]);
$newEntry['content'] = $contentDataObject;
$this->processNewMediaGalleryEntry($product, $newEntry);

$finalGallery = $product->getData('media_gallery');
$newEntryId = key(array_diff_key($product->getData('media_gallery')['images'], $entriesById));
if (isset($newEntry['extension_attributes'])) {
$this->processExtensionAttributes($newEntry, $newEntry['extension_attributes']);
}
$newEntry = array_replace_recursive($newEntry, $finalGallery['images'][$newEntryId]);
$entriesById[$newEntryId] = $newEntry;
$finalGallery['images'][$newEntryId] = $newEntry;
$product->setData('media_gallery', $finalGallery);
}
}
}

0 comments on commit 5aef35b

Please sign in to comment.