From 614229f34870a452e3d4a4ab859e95c7707ab4a7 Mon Sep 17 00:00:00 2001 From: Tony Date: Thu, 1 Aug 2024 09:22:56 +0200 Subject: [PATCH 1/2] fix issues 4134 --- .../Model/Product/Attribute/Backend/Media.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Media.php b/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Media.php index 7e5b29466a2..bf9966b8ed9 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Media.php +++ b/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Media.php @@ -167,11 +167,19 @@ public function beforeSave($object) foreach ($value['values'] as $mediaAttrCode => $attrData) { if (array_key_exists($attrData, $newImages)) { $object->setData($mediaAttrCode, $newImages[$attrData]['new_file']); - $object->setData($mediaAttrCode . '_label', ($newImages[$attrData]['label'] === null || $newImages[$attrData]['label_use_default']) ? $newImages[$attrData]['label_default'] : $newImages[$attrData]['label']); + if ($object->isObjectNew()) { + $object->setData($mediaAttrCode . '_label', $newImages[$attrData]['label']); + } else { + $object->setData($mediaAttrCode . '_label', ($newImages[$attrData]['label'] === null || $newImages[$attrData]['label_use_default']) ? $newImages[$attrData]['label_default'] : $newImages[$attrData]['label']); + } } if (array_key_exists($attrData, $existImages)) { - $object->setData($mediaAttrCode . '_label', ($existImages[$attrData]['label'] === null || $existImages[$attrData]['label_use_default']) ? $existImages[$attrData]['label_default'] : $existImages[$attrData]['label']); + if ($object->isObjectNew()) { + $object->setData($mediaAttrCode . '_label', $existImages[$attrData]['label']); + } else { + $object->setData($mediaAttrCode . '_label', ($existImages[$attrData]['label'] === null || $existImages[$attrData]['label_use_default']) ? $existImages[$attrData]['label_default'] : $existImages[$attrData]['label']); + } } } From 0d001b44db1a10df683e3646a062d7ecf6ffa1e0 Mon Sep 17 00:00:00 2001 From: Tony Date: Tue, 20 Aug 2024 11:33:37 +0200 Subject: [PATCH 2/2] better code Co-authored-by: kiatng --- .../Model/Product/Attribute/Backend/Media.php | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Media.php b/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Media.php index bf9966b8ed9..b6f7105fdf2 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Media.php +++ b/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Media.php @@ -167,19 +167,13 @@ public function beforeSave($object) foreach ($value['values'] as $mediaAttrCode => $attrData) { if (array_key_exists($attrData, $newImages)) { $object->setData($mediaAttrCode, $newImages[$attrData]['new_file']); - if ($object->isObjectNew()) { - $object->setData($mediaAttrCode . '_label', $newImages[$attrData]['label']); - } else { - $object->setData($mediaAttrCode . '_label', ($newImages[$attrData]['label'] === null || $newImages[$attrData]['label_use_default']) ? $newImages[$attrData]['label_default'] : $newImages[$attrData]['label']); - } + $label = $newImages[$attrData]['label'] === null || !empty($newImages[$attrData]['label_use_default']) ? $newImages[$attrData]['label_default'] : $newImages[$attrData]['label']; + $object->setData($mediaAttrCode . '_label', $label); } if (array_key_exists($attrData, $existImages)) { - if ($object->isObjectNew()) { - $object->setData($mediaAttrCode . '_label', $existImages[$attrData]['label']); - } else { - $object->setData($mediaAttrCode . '_label', ($existImages[$attrData]['label'] === null || $existImages[$attrData]['label_use_default']) ? $existImages[$attrData]['label_default'] : $existImages[$attrData]['label']); - } + $label = $existImages[$attrData]['label'] === null || !empty($existImages[$attrData]['label_use_default']) ? $existImages[$attrData]['label_default'] : $existImages[$attrData]['label']; + $object->setData($mediaAttrCode . '_label', $label); } }