Skip to content

Commit

Permalink
Update image label values on product entity on admin product save
Browse files Browse the repository at this point in the history
  • Loading branch information
dmanners committed Nov 27, 2017
1 parent 7f44e66 commit 8aeb71b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions app/code/Magento/Catalog/Model/Product/Gallery/CreateHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))) {
Expand All @@ -179,13 +182,31 @@ 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,
$product->getData($mediaAttrCode),
$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);
Expand Down

0 comments on commit 8aeb71b

Please sign in to comment.