OpenMage / magento-lts

Official OpenMage LTS codebase | Migrate easily from Magento Community Edition in minutes! Download the source code for free or contribute to OpenMage LTS | Security vulnerability patches, bug fixes, performance improvements and more.
https://www.openmage.org
Open Software License 3.0
865 stars 436 forks source link

Fixed undefined array index label_use_default in Mage_Catalog_Model_Product_Attribute_Backend_Media #4024

Closed fballiano closed 3 months ago

fballiano commented 4 months ago

Fixes https://github.com/OpenMage/magento-lts/issues/4023

There could be other ways to fix this problem but I would initialize those 2 array elements

kiatng commented 3 months ago

Why not use empty() to check:

// from
$data['label']    = ($image['label'] === null || $image["label_use_default"]) ? null : $image['label'];
// to
$data['label']    = ($image['label'] === null || empty($image["label_use_default"])) ? null : $image['label'];
fballiano commented 3 months ago

@kiatng if i'm not mistaken that wouldn't cover the "store id = 0" situation and, when the conditions are in || but not all positive they automatically become hard to read to me :-)

kiatng commented 3 months ago

@fballiano You are right. I got confused with if ($storeId === 0) $image["label_use_default"] = false;. We want store 0 to have the default label, but in order to make sure of that, $image["label_use_default"] needs to be set to false, regardless of its prior value. It's counter intuitive.

when the conditions are in || but not all positive

It's hard as hell for me too.