Skip to content

Commit c45ec2a

Browse files
committed
10797: catalogProductTierPriceManagementV1 DELETE and POST operation wipes out media gallery selections when used on store code "all".
1 parent 276c690 commit c45ec2a

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -489,16 +489,17 @@ private function processLinks(\Magento\Catalog\Api\Data\ProductInterface $produc
489489
* @throws InputException
490490
* @throws StateException
491491
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
492+
* @throws LocalizedException
492493
*/
493-
protected function processMediaGallery(ProductInterface $product, $mediaGalleryEntries)
494+
protected function processMediaGallery(ProductInterface $product, array $mediaGalleryEntries)
494495
{
495496
$existingMediaGallery = $product->getMediaGallery('images');
496497
$newEntries = [];
497498
$entriesById = [];
498499
if (!empty($existingMediaGallery)) {
499500
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;
502503
} else {
503504
$newEntries[] = $entry;
504505
}
@@ -515,6 +516,7 @@ protected function processMediaGallery(ProductInterface $product, $mediaGalleryE
515516
$existingEntry['removed'] = true;
516517
}
517518
}
519+
unset($existingEntry);
518520
$product->setData('media_gallery', ["images" => $existingMediaGallery]);
519521
} else {
520522
$newEntries = $mediaGalleryEntries;
@@ -536,9 +538,9 @@ protected function processMediaGallery(ProductInterface $product, $mediaGalleryE
536538
}
537539
/** @var ImageContentInterface $contentDataObject */
538540
$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]);
542544
$newEntry['content'] = $contentDataObject;
543545
$this->processNewMediaGalleryEntry($product, $newEntry);
544546

@@ -587,8 +589,8 @@ public function save(\Magento\Catalog\Api\Data\ProductInterface $product, $saveO
587589
$product = $this->initializeProductData($productDataArray, empty($existingProduct));
588590

589591
$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']);
592594
}
593595

594596
if (!$product->getOptionsReadonly()) {

dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductTierPriceManagementTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,17 @@ public function getListDataProvider()
6060
/**
6161
* @param string|int $customerGroupId
6262
* @param int $qty
63-
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
63+
* @magentoApiDataFixture Magento/Catalog/_files/product_with_image.php
6464
* @dataProvider deleteDataProvider
6565
*/
6666
public function testDelete($customerGroupId, $qty)
6767
{
6868
$productSku = 'simple';
69+
$objectManager = \Magento\TestFramework\ObjectManager::getInstance();
70+
$productBefore = $objectManager->get(ProductRepositoryInterface::class)->get($productSku, false, null, true);
6971
$serviceInfo = [
7072
'rest' => [
71-
'resourcePath' => self::RESOURCE_PATH
73+
'resourcePath' => self::RESOURCE_PATH
7274
. $productSku . "/group-prices/" . $customerGroupId . "/tiers/" . $qty,
7375
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_DELETE,
7476
],
@@ -80,6 +82,10 @@ public function testDelete($customerGroupId, $qty)
8082
];
8183
$requestData = ['sku' => $productSku, 'customerGroupId' => $customerGroupId, 'qty' => $qty];
8284
$this->assertTrue($this->_webApiCall($serviceInfo, $requestData));
85+
$productAfter = $objectManager->get(ProductRepositoryInterface::class)->get($productSku, false, null, true);
86+
$this->assertSame($productBefore->getImage(), $productAfter->getImage());
87+
$this->assertSame($productBefore->getSmallImage(), $productAfter->getSmallImage());
88+
$this->assertSame($productBefore->getThumbnail(), $productAfter->getThumbnail());
8389
}
8490

8591
public function deleteDataProvider()

0 commit comments

Comments
 (0)