diff --git a/app/code/Magento/Catalog/Model/Product/Gallery/CreateHandler.php b/app/code/Magento/Catalog/Model/Product/Gallery/CreateHandler.php index 03d418f3ba0d9..3be10de96ec12 100644 --- a/app/code/Magento/Catalog/Model/Product/Gallery/CreateHandler.php +++ b/app/code/Magento/Catalog/Model/Product/Gallery/CreateHandler.php @@ -167,8 +167,11 @@ public function execute($product, $arguments = []) if (empty($attrData) && empty($clearImages) && empty($newImages) && empty($existImages)) { continue; } + $resetLabel = false; if (in_array($attrData, $clearImages)) { $product->setData($mediaAttrCode, 'no_selection'); + $product->setData($mediaAttrCode . '_label', null); + $resetLabel = true; } if (in_array($attrData, array_keys($newImages))) { @@ -179,6 +182,11 @@ public function execute($product, $arguments = []) if (in_array($attrData, array_keys($existImages)) && isset($existImages[$attrData]['label'])) { $product->setData($mediaAttrCode . '_label', $existImages[$attrData]['label']); } + + if ($attrData === 'no_selection' && !empty($product->getData($mediaAttrCode . '_label'))) { + $product->setData($mediaAttrCode . '_label', null); + $resetLabel = true; + } if (!empty($product->getData($mediaAttrCode))) { $product->addAttributeUpdate( $mediaAttrCode, @@ -186,6 +194,19 @@ public function execute($product, $arguments = []) $product->getStoreId() ); } + if ( + in_array($mediaAttrCode, ['image', 'small_image', 'thumbnail']) + && ( + !empty($product->getData($mediaAttrCode . '_label')) + || $resetLabel === true + ) + ) { + $product->addAttributeUpdate( + $mediaAttrCode . '_label', + $product->getData($mediaAttrCode . '_label'), + $product->getStoreId() + ); + } } $product->setData($attrCode, $value);