Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed faulty media gallery label/description management for mutistore projects #2481

Merged
merged 12 commits into from
Apr 19, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -66,19 +65,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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,9 +579,6 @@ protected function _initProductSave()
$this->_filterStockData($productData['stock_data']);
}

/**
* Websites
*/
if (!isset($productData['website_ids'])) {
$productData['website_ids'] = [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -169,9 +172,7 @@ public function beforeSave($object)
}

Mage::dispatchEvent('catalog_product_media_save_before', ['product' => $object, 'images' => $value]);

$object->setData($attrCode, $value);

return $this;
}

Expand Down Expand Up @@ -204,7 +205,6 @@ public function afterSave($object)
}

$storeId = $object->getStoreId();

$storeIds = $object->getStoreIds();
$storeIds[] = Mage_Core_Model_App::ADMIN_STORE_ID;

Expand Down Expand Up @@ -243,8 +243,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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,101 +13,136 @@
* @license https://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/
?>
<?php
/**
* Template for block Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Gallery_Content
*/
?>
<?php
$_block = $this;
/* @var $_block Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Gallery_Content */
?>
<div id="<?php echo $_block->getHtmlId() ?>" >
<ul class="messages">
<li class="notice-msg">
<ul>
<li>
<?php echo Mage::helper('catalog')->__('Image type and information need to be specified for each store view.'); ?>
</li>
</ul>
</li>
</ul>
<div class="grid">
<table cellspacing="0" class="data border" id="<?php echo $_block->getHtmlId() ?>_grid" width="100%">
<col width="1" />
<col />
<col width="70" />
<?php foreach ($_block->getImageTypes() as $typeId=>$type): ?>
<col />
<?php endforeach ?>
<col width="70" />
<col width="70" />
<thead>
<tr class="headings">
<th><?php echo Mage::helper('catalog')->__('Image') ?></th>
<th><?php echo Mage::helper('catalog')->__('Label') ?></th>
<th><?php echo Mage::helper('catalog')->__('Sort Order') ?></th>
<?php foreach ($_block->getImageTypes() as $typeId => $type): ?>
<th><?php echo $this->escapeHtml($type['label'], ['br']); ?></th>
<div id="<?php echo $this->getHtmlId() ?>">
<ul class="messages">
<li class="notice-msg">
<ul>
<li>
<?php echo Mage::helper('catalog')->__('Image type and information need to be specified for each store view.'); ?>
</li>
</ul>
</li>
</ul>
<div class="grid">
<table cellspacing="0" class="data border" id="<?php echo $this->getHtmlId() ?>_grid" width="100%">
<col width="1"/>
<col/>
<col width="70"/>
<?php foreach ($this->getImageTypes() as $typeId => $type): ?>
<col/>
<?php endforeach ?>
<th><?php echo Mage::helper('catalog')->__('Exclude') ?></th>
<th class="last"><?php echo Mage::helper('catalog')->__('Remove') ?></th>
</tr>
</thead>
<tbody id="<?php echo $_block->getHtmlId() ?>_list">
<tr id="<?php echo $_block->getHtmlId() ?>_template" class="template no-display">
<td class="cell-image"><div class="place-holder" onmouseover="<?php echo $_block->getJsObjectName(); ?>.loadImage('__file__')"><span><?php echo Mage::helper('catalog')->__('Roll Over for preview') ?></span></div><img src="<?php echo $this->getSkinUrl('images/spacer.gif')?>" width="100" style="display:none;" alt="" /></td>
<td class="cell-label"><input type="text" <?php if($_block->getElement()->getReadonly()):?> disabled="disabled"<?php endif ?> class="input-text" onkeyup="<?php echo $_block->getJsObjectName(); ?>.updateImage('__file__')" onchange="<?php echo $_block->getJsObjectName(); ?>.updateImage('__file__')" /></td>
<td class="cell-position"><input type="text" <?php if($_block->getElement()->getReadonly()):?> disabled="disabled"<?php endif ?> class="input-text validate-number" onkeyup="<?php echo $_block->getJsObjectName(); ?>.updateImage('__file__')" onchange="<?php echo $_block->getJsObjectName(); ?>.updateImage('__file__')" /></td>
<?php foreach ($_block->getImageTypes() as $typeId=>$type): ?>
<td class="cell-<?php echo $typeId ?> a-center"><input <?php if($_block->getElement()->getAttributeReadonly($typeId)) :?> disabled="disabled" <?php endif ?> type="radio" name="<?php echo $type['field'] ?>" onclick="<?php echo $_block->getJsObjectName(); ?>.setProductImages('__file__')" value="__file__" /></td>
<col width="70"/>
<col width="70"/>
<thead>
<tr class="headings">
<th><?php echo Mage::helper('catalog')->__('Image') ?></th>
<th><?php echo Mage::helper('catalog')->__('Label') ?></th>
<th><?php echo Mage::helper('catalog')->__('Sort Order') ?></th>
<?php foreach ($this->getImageTypes() as $typeId => $type): ?>
<th><?php echo $this->escapeHtml($type['label'], array('br')); ?></th>
<?php endforeach ?>
<td class="cell-disable a-center"><input type="checkbox" <?php if($_block->getElement()->getReadonly()):?> disabled="disabled"<?php endif ?> onclick="<?php echo $_block->getJsObjectName(); ?>.updateImage('__file__')" /></td>
<td class="cell-remove a-center last"><input type="checkbox" <?php if($_block->getElement()->getReadonly()):?> disabled="disabled"<?php endif ?> onclick="<?php echo $_block->getJsObjectName(); ?>.updateImage('__file__')" /></td>
</tr>
<?php if($_block->hasUseDefault()): ?>
<tr id="<?php echo $_block->getHtmlId() ?>_default">
<td><?php echo Mage::helper('catalog')->__('Use Default Value') ?></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<?php foreach ($_block->getMediaAttributes() as $_attribute): ?>
<td class="a-center">
<?php if($_block->getElement()->canDisplayUseDefault($_attribute)): ?>
<input class="default-checkbox" name="use_default[]" type="checkbox" <?php if($_block->getElement()->getAttributeReadonly($_attribute->getAttributeCode())):?> disabled="disabled" <?php endif ?> onclick="<?php echo $_block->getJsObjectName(); ?>.updateUseDefault()"
<?php if($_block->getElement()->usedDefault($_attribute)): ?>checked<?php endif ?> value="<?php echo $_attribute->getAttributeCode() ?>" />
<?php endif ?>
</td>
<th><?php echo Mage::helper('catalog')->__('Exclude') ?></th>
<th class="last"><?php echo Mage::helper('catalog')->__('Remove') ?></th>
</tr>
</thead>
<tbody id="<?php echo $this->getHtmlId() ?>_list">
<tr id="<?php echo $this->getHtmlId() ?>_template" class="template no-display">
<td class="cell-image">
<div class="place-holder"
onmouseover="<?php echo $this->getJsObjectName(); ?>.loadImage('__file__')">
<span><?php echo Mage::helper('catalog')->__('Roll Over for preview') ?></span></div>
<img src="<?php echo $this->getSkinUrl('images/spacer.gif') ?>" width="100" style="display:none;"
alt=""/></td>
<td class="cell-label"><input
type="text" <?php if ($this->getElement()->getReadonly()): ?> disabled="disabled"<?php endif ?>
class="input-text"
onkeyup="<?php echo $this->getJsObjectName(); ?>.updateImage('__file__')"
onchange="<?php echo $this->getJsObjectName(); ?>.updateImage('__file__')"/></td>
<td class="cell-position"><input
type="text" <?php if ($this->getElement()->getReadonly()): ?> disabled="disabled"<?php endif ?>
class="input-text validate-number"
onkeyup="<?php echo $this->getJsObjectName(); ?>.updateImage('__file__')"
onchange="<?php echo $this->getJsObjectName(); ?>.updateImage('__file__')"/></td>
<?php foreach ($this->getImageTypes() as $typeId => $type): ?>
<td class="cell-<?php echo $typeId ?> a-center">
<input <?php if ($this->getElement()->getAttributeReadonly($typeId)) : ?> disabled="disabled" <?php endif ?>
type="radio" name="<?php echo $type['field'] ?>"
onclick="<?php echo $this->getJsObjectName(); ?>.setProductImages('__file__')"
value="__file__"/></td>
<?php endforeach ?>
<td>&nbsp;</td>
<td class="last">&nbsp;</td>
</tr>
<?php endif ?>
<tr id="<?php echo $_block->getHtmlId() ?>-image-0">
<td class="cell-disable a-center"><input
type="checkbox" <?php if ($this->getElement()->getReadonly()): ?> disabled="disabled"<?php endif ?>
onclick="<?php echo $this->getJsObjectName(); ?>.updateImage('__file__')"/></td>
<td class="cell-remove a-center last"><input
type="checkbox" <?php if ($this->getElement()->getReadonly()): ?> disabled="disabled"<?php endif ?>
onclick="<?php echo $this->getJsObjectName(); ?>.updateImage('__file__')"/></td>
</tr>
<?php if ($this->hasUseDefault()): ?>
<tr id="<?php echo $this->getHtmlId() ?>_default">
<td><?php echo Mage::helper('catalog')->__('Use Default Value') ?></td>
<td class="a-center">
<input id="use_default_label" class="default-checkbox" name="use_default[]" type="checkbox"
<?php if ($this->getElement()->getAttributeReadonly("label")): ?> disabled="disabled" <?php endif ?>
onclick="<?php echo $this->getJsObjectName(); ?>.updateUseDefault(this)"
<?php if ($this->getElement()->usedDefault("label")): ?>checked<?php endif ?>
value="label"/>
</td>
<td>
<input id="use_default_position" class="default-checkbox" name="use_default[]" type="checkbox"
<?php if ($this->getElement()->getAttributeReadonly("position")): ?> disabled="disabled" <?php endif ?>
onclick="<?php echo $this->getJsObjectName(); ?>.updateUseDefault(this)"
<?php if ($this->getElement()->usedDefault("position")): ?>checked<?php endif ?>
value="position"/>
</td>
<?php foreach ($this->getMediaAttributes() as $_attribute): ?>
<td class="a-center">
<?php if ($this->getElement()->canDisplayUseDefault($_attribute)): ?>
<input class="default-checkbox" name="use_default[]"
type="checkbox" <?php if ($this->getElement()->getAttributeReadonly($_attribute->getAttributeCode())): ?> disabled="disabled" <?php endif ?>
onclick="<?php echo $this->getJsObjectName(); ?>.updateUseDefault()"
<?php if ($this->getElement()->usedDefault($_attribute)): ?>checked<?php endif ?>
value="<?php echo $_attribute->getAttributeCode() ?>"/>
<?php endif ?>
</td>
<?php endforeach ?>
<td>&nbsp;</td>
<td class="last">&nbsp;</td>
</tr>
<?php endif ?>
<tr id="<?php echo $this->getHtmlId() ?>-image-0">
<td class="cell-image"><?php echo Mage::helper('catalog')->__('No image') ?></td>
<td class="cell-label"><input type="hidden" />&nbsp;</td>
<td class="cell-position"><input type="hidden" />&nbsp;</td>
<?php foreach ($_block->getImageTypes() as $typeId=>$type): ?>
<td class="cell-<?php echo $typeId ?> a-center"><input type="radio" <?php if($_block->getElement()->getAttributeReadonly($typeId)) :?> disabled="disabled" <?php endif ?> name="<?php echo $type['field'] ?>" onclick="<?php echo $_block->getJsObjectName(); ?>.setProductImages('no_selection')" value="no_selection" /></td>
<td class="cell-label"><input type="hidden"/>&nbsp;</td>
<td class="cell-position"><input type="hidden"/>&nbsp;</td>
<?php foreach ($this->getImageTypes() as $typeId => $type): ?>
<td class="cell-<?php echo $typeId ?> a-center"><input
type="radio" <?php if ($this->getElement()->getAttributeReadonly($typeId)) : ?> disabled="disabled" <?php endif ?>
name="<?php echo $type['field'] ?>"
onclick="<?php echo $this->getJsObjectName(); ?>.setProductImages('no_selection')"
value="no_selection"/></td>
<?php endforeach ?>
<td class="cell-disable"><input type="hidden" />&nbsp;</td>
<td class="cell-remove last"><input type="hidden" />&nbsp;</td>
</tr>
</tbody>
<?php if (!$_block->getElement()->getReadonly()):?>
<tfoot>
<tr>
<td colspan="100" class="last" style="padding:8px">
<?php echo Mage::helper('catalog')->__('Maximum width and height dimension for upload image is %s.', Mage::getStoreConfig(Mage_Catalog_Helper_Image::XML_NODE_PRODUCT_MAX_DIMENSION)); ?>
<?php echo $_block->getUploaderHtml() ?>
</td>
</tr>
</tfoot>
<?php endif ?>
</table>
</div>
<td class="cell-disable"><input type="hidden"/>&nbsp;</td>
<td class="cell-remove last"><input type="hidden"/>&nbsp;</td>
</tr>
</tbody>
<?php if (!$this->getElement()->getReadonly()): ?>
<tfoot>
<tr>
<td colspan="100" class="last" style="padding:8px">
<?php echo Mage::helper('catalog')->__('Maximum width and height dimension for upload image is %s.', Mage::getStoreConfig(Mage_Catalog_Helper_Image::XML_NODE_PRODUCT_MAX_DIMENSION)); ?>
<?php echo $this->getUploaderHtml() ?>
</td>
</tr>
</tfoot>
<?php endif ?>
</table>
</div>
</div>
<input type="hidden" id="<?php echo $_block->getHtmlId() ?>_save" name="<?php echo $_block->getElement()->getName() ?>[images]" value="<?php echo $_block->escapeHtml($_block->getImagesJson()) ?>" />
<input type="hidden" id="<?php echo $_block->getHtmlId() ?>_save_image" name="<?php echo $_block->getElement()->getName() ?>[values]" value="<?php echo $_block->escapeHtml($_block->getImagesValuesJson()) ?>" />
<input type="hidden" id="<?php echo $this->getHtmlId() ?>_save"
name="<?php echo $this->getElement()->getName() ?>[images]"
value="<?php echo $this->escapeHtml($this->getImagesJson()) ?>"/>
<input type="hidden" id="<?php echo $this->getHtmlId() ?>_save_image"
name="<?php echo $this->getElement()->getName() ?>[values]"
value="<?php echo $this->escapeHtml($this->getImagesValuesJson()) ?>"/>
<script type="text/javascript">
//<![CDATA[
var <?php echo $_block->getJsObjectName(); ?> = new Product.Gallery('<?php echo $_block->getHtmlId() ?>', <?php echo $_block->getImageTypesJson() ?>);
fballiano marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Loading
Loading