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 276c690 commit c45ec2a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
18 changes: 10 additions & 8 deletions app/code/Magento/Catalog/Model/ProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,16 +489,17 @@ private function processLinks(\Magento\Catalog\Api\Data\ProductInterface $produc
* @throws InputException
* @throws StateException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @throws LocalizedException
*/
protected function processMediaGallery(ProductInterface $product, $mediaGalleryEntries)
protected function processMediaGallery(ProductInterface $product, array $mediaGalleryEntries)
{
$existingMediaGallery = $product->getMediaGallery('images');
$newEntries = [];
$entriesById = [];
if (!empty($existingMediaGallery)) {
foreach ($mediaGalleryEntries as $entry) {
if (isset($entry['value_id'])) {
$entriesById[$entry['value_id']] = $entry;
if (isset($entry['id'])) {
$entriesById[$entry['id']] = $entry;
} else {
$newEntries[] = $entry;
}
Expand All @@ -515,6 +516,7 @@ protected function processMediaGallery(ProductInterface $product, $mediaGalleryE
$existingEntry['removed'] = true;
}
}
unset($existingEntry);
$product->setData('media_gallery', ["images" => $existingMediaGallery]);
} else {
$newEntries = $mediaGalleryEntries;
Expand All @@ -536,9 +538,9 @@ protected function processMediaGallery(ProductInterface $product, $mediaGalleryE
}
/** @var ImageContentInterface $contentDataObject */
$contentDataObject = $this->contentFactory->create()
->setName($newEntry['content']['data'][ImageContentInterface::NAME])
->setBase64EncodedData($newEntry['content']['data'][ImageContentInterface::BASE64_ENCODED_DATA])
->setType($newEntry['content']['data'][ImageContentInterface::TYPE]);
->setName($newEntry['content'][ImageContentInterface::NAME])
->setBase64EncodedData($newEntry['content'][ImageContentInterface::BASE64_ENCODED_DATA])
->setType($newEntry['content'][ImageContentInterface::TYPE]);
$newEntry['content'] = $contentDataObject;
$this->processNewMediaGalleryEntry($product, $newEntry);

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

$this->processLinks($product, $productLinks);
if (isset($productDataArray['media_gallery'])) {
$this->processMediaGallery($product, $productDataArray['media_gallery']['images']);
if (isset($productDataArray['media_gallery_entries'])) {
$this->processMediaGallery($product, $productDataArray['media_gallery_entries']);
}

if (!$product->getOptionsReadonly()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,17 @@ public function getListDataProvider()
/**
* @param string|int $customerGroupId
* @param int $qty
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
* @magentoApiDataFixture Magento/Catalog/_files/product_with_image.php
* @dataProvider deleteDataProvider
*/
public function testDelete($customerGroupId, $qty)
{
$productSku = 'simple';
$objectManager = \Magento\TestFramework\ObjectManager::getInstance();
$productBefore = $objectManager->get(ProductRepositoryInterface::class)->get($productSku, false, null, true);
$serviceInfo = [
'rest' => [
'resourcePath' => self::RESOURCE_PATH
'resourcePath' => self::RESOURCE_PATH
. $productSku . "/group-prices/" . $customerGroupId . "/tiers/" . $qty,
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_DELETE,
],
Expand All @@ -80,6 +82,10 @@ public function testDelete($customerGroupId, $qty)
];
$requestData = ['sku' => $productSku, 'customerGroupId' => $customerGroupId, 'qty' => $qty];
$this->assertTrue($this->_webApiCall($serviceInfo, $requestData));
$productAfter = $objectManager->get(ProductRepositoryInterface::class)->get($productSku, false, null, true);
$this->assertSame($productBefore->getImage(), $productAfter->getImage());
$this->assertSame($productBefore->getSmallImage(), $productAfter->getSmallImage());
$this->assertSame($productBefore->getThumbnail(), $productAfter->getThumbnail());
}

public function deleteDataProvider()
Expand Down

0 comments on commit c45ec2a

Please sign in to comment.