Skip to content

Commit 8aeb71b

Browse files
committed
Update image label values on product entity on admin product save
1 parent 7f44e66 commit 8aeb71b

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

app/code/Magento/Catalog/Model/Product/Gallery/CreateHandler.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,11 @@ public function execute($product, $arguments = [])
167167
if (empty($attrData) && empty($clearImages) && empty($newImages) && empty($existImages)) {
168168
continue;
169169
}
170+
$resetLabel = false;
170171
if (in_array($attrData, $clearImages)) {
171172
$product->setData($mediaAttrCode, 'no_selection');
173+
$product->setData($mediaAttrCode . '_label', null);
174+
$resetLabel = true;
172175
}
173176

174177
if (in_array($attrData, array_keys($newImages))) {
@@ -179,13 +182,31 @@ public function execute($product, $arguments = [])
179182
if (in_array($attrData, array_keys($existImages)) && isset($existImages[$attrData]['label'])) {
180183
$product->setData($mediaAttrCode . '_label', $existImages[$attrData]['label']);
181184
}
185+
186+
if ($attrData === 'no_selection' && !empty($product->getData($mediaAttrCode . '_label'))) {
187+
$product->setData($mediaAttrCode . '_label', null);
188+
$resetLabel = true;
189+
}
182190
if (!empty($product->getData($mediaAttrCode))) {
183191
$product->addAttributeUpdate(
184192
$mediaAttrCode,
185193
$product->getData($mediaAttrCode),
186194
$product->getStoreId()
187195
);
188196
}
197+
if (
198+
in_array($mediaAttrCode, ['image', 'small_image', 'thumbnail'])
199+
&& (
200+
!empty($product->getData($mediaAttrCode . '_label'))
201+
|| $resetLabel === true
202+
)
203+
) {
204+
$product->addAttributeUpdate(
205+
$mediaAttrCode . '_label',
206+
$product->getData($mediaAttrCode . '_label'),
207+
$product->getStoreId()
208+
);
209+
}
189210
}
190211

191212
$product->setData($attrCode, $value);

0 commit comments

Comments
 (0)