diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Gallery.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Gallery.php index 31734b83395..4f865355dc8 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Gallery.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Gallery.php @@ -23,7 +23,6 @@ class Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Gallery extends Varien_Da { public function getElementHtml() { - //$html.= $this->getAfterElementHtml(); return $this->getContentHtml(); } @@ -38,7 +37,8 @@ public function getContentHtml() $content = Mage::getSingleton('core/layout') ->createBlock('adminhtml/catalog_product_helper_form_gallery_content'); - $content->setId($this->getHtmlId() . '_content') + $content + ->setId($this->getHtmlId() . '_content') ->setElement($this); return $content->toHtml(); } @@ -66,19 +66,31 @@ public function canDisplayUseDefault($attribute) /** * Check default value usage fact * - * @param Mage_Eav_Model_Entity_Attribute $attribute + * @param Mage_Eav_Model_Entity_Attribute|string $attribute * @return bool */ public function usedDefault($attribute) { - $attributeCode = $attribute->getAttributeCode(); - $defaultValue = $this->getDataObject()->getAttributeDefaultValue($attributeCode); + if (is_string($attribute)) { + $attributeCode = $attribute; + } else { + $attributeCode = $attribute->getAttributeCode(); + } + // special management for "label" and "position" since they're columns of the + // catalog_product_entity_media_gallery_value database table + if ($attributeCode == "label" || $attributeCode == "position") { + $media_gallery = $this->getDataObject()->getMediaGallery(); + if (!count($media_gallery["images"])) { + return true; + } + return $media_gallery["images"][0]["{$attributeCode}_use_default"]; + } + + $defaultValue = $this->getDataObject()->getAttributeDefaultValue($attributeCode); if (!$this->getDataObject()->getExistsStoreValueFlag($attributeCode)) { return true; - } elseif ($this->getValue() == $defaultValue && - $this->getDataObject()->getStoreId() != $this->_getDefaultStoreId() - ) { + } elseif ($this->getValue() == $defaultValue && $this->getDataObject()->getStoreId() != $this->_getDefaultStoreId()) { return false; } if ($defaultValue === false && !$attribute->getIsRequired() && $this->getValue()) { diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php index a10f7e2e719..c5fc49a0e20 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php @@ -579,9 +579,6 @@ protected function _initProductSave() $this->_filterStockData($productData['stock_data']); } - /** - * Websites - */ if (!isset($productData['website_ids'])) { $productData['website_ids'] = []; } 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 8acf4472eb4..3b58e89d5a3 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 @@ -43,7 +43,10 @@ public function afterLoad($object) foreach ($this->_getResource()->loadGallery($object, $this) as $image) { foreach ($localAttributes as $localAttribute) { if (is_null($image[$localAttribute])) { + $image[$localAttribute . '_use_default'] = true; $image[$localAttribute] = $this->_getDefaultValue($localAttribute, $image); + } else { + $image[$localAttribute . '_use_default'] = false; } } $value['images'][] = $image; @@ -107,6 +110,10 @@ public function beforeSave($object) $value['images'] = Mage::helper('core')->jsonDecode($value['images']); } + if (!is_array($value['values']) && strlen($value['values']) > 0) { + $value['values'] = Mage::helper('core')->jsonDecode($value['values']); + } + if (!is_array($value['images'])) { $value['images'] = []; } @@ -119,11 +126,11 @@ public function beforeSave($object) if (!empty($image['removed'])) { $clearImages[] = $image['file']; } elseif (!isset($image['value_id'])) { - $newFile = $this->_moveImageFromTmp($image['file']); + $newFile = $this->_moveImageFromTmp($image['file']); $image['new_file'] = $newFile; $newImages[$image['file']] = $image; $this->_renamedImages[$image['file']] = $newFile; - $image['file'] = $newFile; + $image['file'] = $newFile; } else { $existImages[$image['file']] = $image; } @@ -142,8 +149,6 @@ public function beforeSave($object) ]; $duplicate[$image['value_id']] = $newFile; } - - $value['duplicate'] = $duplicate; } foreach ($object->getMediaAttributes() as $mediaAttribute) { @@ -157,21 +162,21 @@ public function beforeSave($object) if (in_array($attrData, $clearImages)) { $object->setData($mediaAttrCode, 'no_selection'); } + } + 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']); + $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']); + $object->setData($mediaAttrCode . '_label', ($existImages[$attrData]['label'] === null || $existImages[$attrData]['label_use_default']) ? $existImages[$attrData]['label_default'] : $existImages[$attrData]['label']); } } Mage::dispatchEvent('catalog_product_media_save_before', ['product' => $object, 'images' => $value]); - $object->setData($attrCode, $value); - return $this; } @@ -204,7 +209,6 @@ public function afterSave($object) } $storeId = $object->getStoreId(); - $storeIds = $object->getStoreIds(); $storeIds[] = Mage_Core_Model_App::ADMIN_STORE_ID; @@ -243,8 +247,8 @@ public function afterSave($object) // Add per store labels, position, disabled $data = []; $data['value_id'] = $image['value_id']; - $data['label'] = $image['label']; - $data['position'] = (int) $image['position']; + $data['label'] = ($image['label'] === null || $image["label_use_default"]) ? null : $image['label']; + $data['position'] = ($image['position'] === null || $image["position_use_default"]) ? null : (int) $image['position']; $data['disabled'] = (int) $image['disabled']; $data['store_id'] = (int) $object->getStoreId(); diff --git a/app/design/adminhtml/default/default/template/catalog/product/helper/gallery.phtml b/app/design/adminhtml/default/default/template/catalog/product/helper/gallery.phtml index d68c7467583..3b382e519cc 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/helper/gallery.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/helper/gallery.phtml @@ -13,103 +13,138 @@ * @license https://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> - - -
__('Image') ?> | -__('Label') ?> | -__('Sort Order') ?> | - getImageTypes() as $typeId => $type): ?> -escapeHtml($type['label'], ['br']); ?> | +
---|
__('Exclude') ?> | -__('Remove') ?> | - - - -||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
__('Roll Over for preview') ?> |
- getElement()->getReadonly()):?> disabled="disabled" class="input-text" onkeyup="getJsObjectName(); ?>.updateImage('__file__')" onchange="getJsObjectName(); ?>.updateImage('__file__')" /> | -getElement()->getReadonly()):?> disabled="disabled" class="input-text validate-number" onkeyup="getJsObjectName(); ?>.updateImage('__file__')" onchange="getJsObjectName(); ?>.updateImage('__file__')" /> | - getImageTypes() as $typeId=>$type): ?> -getElement()->getAttributeReadonly($typeId)) :?> disabled="disabled" type="radio" name="" onclick="getJsObjectName(); ?>.setProductImages('__file__')" value="__file__" /> | +||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
__('Image') ?> | +__('Label') ?> | +__('Sort Order') ?> | + getImageTypes() as $typeId => $type): ?> +escapeHtml($type['label'], array('br')); ?> | -getElement()->getReadonly()):?> disabled="disabled" onclick="getJsObjectName(); ?>.updateImage('__file__')" /> | -getElement()->getReadonly()):?> disabled="disabled" onclick="getJsObjectName(); ?>.updateImage('__file__')" /> | -||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
__('Use Default Value') ?> | -- | - getMediaAttributes() as $_attribute): ?> - | - getElement()->canDisplayUseDefault($_attribute)): ?> - getElement()->getAttributeReadonly($_attribute->getAttributeCode())):?> disabled="disabled" onclick="getJsObjectName(); ?>.updateUseDefault()" -getElement()->usedDefault($_attribute)): ?>checked value="getAttributeCode() ?>" /> - - | +__('Exclude') ?> | +__('Remove') ?> | +||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+
+ __('Roll Over for preview') ?>
+ |
+ getElement()->getReadonly()): ?> disabled="disabled" + class="input-text" + onkeyup="getJsObjectName(); ?>.updateImage('__file__')" + onchange="getJsObjectName(); ?>.updateImage('__file__')"/> | +getElement()->getReadonly()): ?> disabled="disabled" + class="input-text validate-number" + onkeyup="getJsObjectName(); ?>.updateImage('__file__')" + onchange="getJsObjectName(); ?>.updateImage('__file__')"/> | + getImageTypes() as $typeId => $type): ?> ++ getElement()->getAttributeReadonly($typeId)) : ?> disabled="disabled" + type="radio" name="" + onclick="getJsObjectName(); ?>.setProductImages('__file__')" + value="__file__"/> | -- | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
getElement()->getReadonly()): ?> disabled="disabled" + onclick="getJsObjectName(); ?>.updateImage('__file__')"/> | +getElement()->getReadonly()): ?> disabled="disabled" + onclick="getJsObjectName(); ?>.updateImage('__file__')"/> | +||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
__('Use Default Value') ?> | ++ getElement()->getAttributeReadonly("label")): ?> disabled="disabled" + onclick="getJsObjectName(); ?>.updateUseDefault(this)" + getElement()->usedDefault("label")): ?>checked + value="label"/> + | ++ getElement()->getAttributeReadonly("position")): ?> disabled="disabled" + onclick="getJsObjectName(); ?>.updateUseDefault(this)" + getElement()->usedDefault("position")): ?>checked + value="position"/> + | + getMediaAttributes() as $_attribute): ?> ++ getElement()->canDisplayUseDefault($_attribute)): ?> + getElement()->getAttributeReadonly($_attribute->getAttributeCode())): ?> disabled="disabled" + onclick="getJsObjectName(); ?>.updateUseDefault()" + getElement()->usedDefault($_attribute)): ?>checked + value="getAttributeCode() ?>"/> + + | + ++ | + | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
__('No image') ?> | -- | - getImageTypes() as $typeId=>$type): ?> - | getElement()->getAttributeReadonly($typeId)) :?> disabled="disabled" name="" onclick="getJsObjectName(); ?>.setProductImages('no_selection')" value="no_selection" /> | ++ | + getImageTypes() as $typeId => $type): ?> + | getElement()->getAttributeReadonly($typeId)) : ?> disabled="disabled" + name="" + onclick="getJsObjectName(); ?>.setProductImages('no_selection')" + value="no_selection"/> | -- | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- __('Maximum width and height dimension for upload image is %s.', Mage::getStoreConfig(Mage_Catalog_Helper_Image::XML_NODE_PRODUCT_MAX_DIMENSION)); ?> - getUploaderHtml() ?> - | -