Skip to content

[BUGFIX] Unset Image Data if store is not the Admin Storeview #15014

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions app/code/Magento/Catalog/Model/ProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,9 @@ public function save(\Magento\Catalog\Api\Data\ProductInterface $product, $saveO
if ($tierPrices !== null) {
$product->setData('tier_price', $tierPrices);
}

$this->filterImageData($product);

unset($this->instances[$product->getSku()]);
unset($this->instancesById[$product->getId()]);
$this->resourceModel->save($product);
Expand Down Expand Up @@ -534,6 +537,28 @@ public function save(\Magento\Catalog\Api\Data\ProductInterface $product, $saveO
return $this->get($product->getSku(), false, $product->getStoreId());
}

/**
* @param $product
*/
protected function filterImageData($product)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change protected to private due to Magento Technical Guidelines

{
if ($product->getStoreId() != 0) {
if ($mediaGallery = $product->getData('media_gallery')) {
if (isset($mediaGallery['images'])) {
foreach (array_keys($mediaGallery['images']) as $key) {
unset($mediaGallery['images'][$key]['position']);
unset($mediaGallery['images'][$key]['position_default']);
}
}
}
$product->setData('media_gallery', $mediaGallery);
$product->unsetData('image');
$product->unsetData('small_image');
$product->unsetData('swatch_image');
$product->unsetData('thumbnail');
}
}

/**
* {@inheritdoc}
*/
Expand Down