Product Images force default sort value
This question has been asked before, but the answer to it which was updating a UAV attribute did not help. Product images use default value
Is there a way to make all store views always use the default sort order values for it's images ? There is no checkbox, I tried implementing something similar to the other default values, but got lost because there is quite a lot of code for it.
magento-1.9 product-images eav
add a comment |
This question has been asked before, but the answer to it which was updating a UAV attribute did not help. Product images use default value
Is there a way to make all store views always use the default sort order values for it's images ? There is no checkbox, I tried implementing something similar to the other default values, but got lost because there is quite a lot of code for it.
magento-1.9 product-images eav
Do you find a solution? I'm trying to do the same thing with sort order, label and checkbox exclude. Thanks
– Walid
Dec 6 '18 at 8:43
This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. You can also add a bounty to draw more attention to this question once you have enough reputation. - From Review
– Rama Chandran M
Dec 6 '18 at 9:01
add a comment |
This question has been asked before, but the answer to it which was updating a UAV attribute did not help. Product images use default value
Is there a way to make all store views always use the default sort order values for it's images ? There is no checkbox, I tried implementing something similar to the other default values, but got lost because there is quite a lot of code for it.
magento-1.9 product-images eav
This question has been asked before, but the answer to it which was updating a UAV attribute did not help. Product images use default value
Is there a way to make all store views always use the default sort order values for it's images ? There is no checkbox, I tried implementing something similar to the other default values, but got lost because there is quite a lot of code for it.
magento-1.9 product-images eav
magento-1.9 product-images eav
asked Sep 4 '18 at 11:09
Igor Ivanov
11
11
Do you find a solution? I'm trying to do the same thing with sort order, label and checkbox exclude. Thanks
– Walid
Dec 6 '18 at 8:43
This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. You can also add a bounty to draw more attention to this question once you have enough reputation. - From Review
– Rama Chandran M
Dec 6 '18 at 9:01
add a comment |
Do you find a solution? I'm trying to do the same thing with sort order, label and checkbox exclude. Thanks
– Walid
Dec 6 '18 at 8:43
This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. You can also add a bounty to draw more attention to this question once you have enough reputation. - From Review
– Rama Chandran M
Dec 6 '18 at 9:01
Do you find a solution? I'm trying to do the same thing with sort order, label and checkbox exclude. Thanks
– Walid
Dec 6 '18 at 8:43
Do you find a solution? I'm trying to do the same thing with sort order, label and checkbox exclude. Thanks
– Walid
Dec 6 '18 at 8:43
This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. You can also add a bounty to draw more attention to this question once you have enough reputation. - From Review
– Rama Chandran M
Dec 6 '18 at 9:01
This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. You can also add a bounty to draw more attention to this question once you have enough reputation. - From Review
– Rama Chandran M
Dec 6 '18 at 9:01
add a comment |
1 Answer
1
active
oldest
votes
By default magento doesn't care about resetting rows from catalog_product_entity_media_gallery_value table. So, I managed to solve this problem by adding an observer after product is saved and by adding a patch in order to add a button or checkbox to gallery.phtml file.
app/code/local/Namespace/Name/etc/config.xml
<catalog_product_save_commit_after>
<observers>
<catalog_product_save_commit_after_check_media_use_default>
<type>singleton</type>
<class>namespace_name/observer_resetMediaSortOrder</class>
<method>execute</method>
</catalog_product_save_commit_after_check_media_use_default>
</observers>
</catalog_product_save_commit_after>
app/code/local/Namespace/Name/Model/Observer/ResetMediaSortOrder.php
<?php
class Namespace_Name_Model_Observer_ResetMediaSortOrder
{
/**
* Execute observer on 'catalog_product_prepare_save' event.
*
* @param Varien_Event_Observer $observer
* @return Namespace_Name_Model_Observer_CheckMediaSortOrder
*/
public function execute(Varien_Event_Observer $observer): self
{
$params = Mage::app()->getRequest()->getParams();
$productId = $params['id'];
$storeId = $params['store'];
$useDefault = $params['use_default'];
if (!in_array('sort_order', $useDefault)) {
return $this;
}
$resource = Mage::getSingleton('core/resource');
$readConnection = $resource->getConnection('core_read');
$writeConnection = $resource->getConnection('core_write');
// get ids values for media gallery
$select = $readConnection->select()->from(
$resource->getTableName('catalog_product_entity_media_gallery'),
'value_id'
);
$select->where('entity_id = ?', $productId);
$valueIds = $readConnection->fetchCol($select);
if (empty($valueIds)) {
return $this;
}
// delete media gallery values by conditions
$writeConnection->delete(
$resource->getTableName('catalog_product_entity_media_gallery_value'),
['value_id IN (?)' => $valueIds, 'store_id = ?' => $storeId]
);
return $this;
}
}
app/design/adminhtml/default/default/template/catalog/product/helper/gallery.phtml
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE_AFL.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magento.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magento.com for more information.
*
* @category design
* @package default_default
* @copyright Copyright (c) 2006-2018 Magento, Inc. (http://www.magento.com)
* @license http://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']); ?></th>
<?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>
<?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> </td>
<td class="a-center">
<button id="button_use_default_sort_order" title="If is checked, the global values for sort order will be used." type="button" onclick="toggleCheckboxSortOrder()">
<span><span><span>Use default</span></span></span>
</button>
<input id="use_default_sort_order" class="default-checkbox" name="use_default" type="checkbox" value="sort_order" style="display: none;"/>
</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>
<?php endforeach; ?>
<td> </td>
<td class="last"> </td>
</tr>
<?php endif ?>
<tr id="<?php echo $_block->getHtmlId() ?>-image-0">
<td class="cell-image"><?php echo Mage::helper('catalog')->__('No image') ?></td>
<td class="cell-label"><input type="hidden" /> </td>
<td class="cell-position"><input type="hidden" /> </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>
<?php endforeach; ?>
<td class="cell-disable"><input type="hidden" /> </td>
<td class="cell-remove last"><input type="hidden" /> </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>
</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()) ?>" />
<script type="text/javascript">
//<![CDATA[
var <?php echo $_block->getJsObjectName(); ?> = new Product.Gallery('<?php echo $_block->getHtmlId() ?>', <?php echo $_block->getImageTypesJson() ?>);
function toggleCheckboxSortOrder()
{
var checkUseDefault = document.getElementById('use_default_sort_order');
var buttonUseDefault = document.getElementById('button_use_default_sort_order');
if (buttonUseDefault.classList.contains('ok_button')) {
checkUseDefault.checked = false;
buttonUseDefault.className = '';
} else {
checkUseDefault.checked = true;
buttonUseDefault.className = 'ok_button';
}
}
//]]>
</script>
I put the gallery.phtml(with the applied changes) file instead of a patch due to it's size, but is better to make a patch instead on changing this file.
With the above code every time when you save a product on a store you can click the new button to reset the 'sort order' in order to apply the global values(from Default Values store view).
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f240745%2fproduct-images-force-default-sort-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
By default magento doesn't care about resetting rows from catalog_product_entity_media_gallery_value table. So, I managed to solve this problem by adding an observer after product is saved and by adding a patch in order to add a button or checkbox to gallery.phtml file.
app/code/local/Namespace/Name/etc/config.xml
<catalog_product_save_commit_after>
<observers>
<catalog_product_save_commit_after_check_media_use_default>
<type>singleton</type>
<class>namespace_name/observer_resetMediaSortOrder</class>
<method>execute</method>
</catalog_product_save_commit_after_check_media_use_default>
</observers>
</catalog_product_save_commit_after>
app/code/local/Namespace/Name/Model/Observer/ResetMediaSortOrder.php
<?php
class Namespace_Name_Model_Observer_ResetMediaSortOrder
{
/**
* Execute observer on 'catalog_product_prepare_save' event.
*
* @param Varien_Event_Observer $observer
* @return Namespace_Name_Model_Observer_CheckMediaSortOrder
*/
public function execute(Varien_Event_Observer $observer): self
{
$params = Mage::app()->getRequest()->getParams();
$productId = $params['id'];
$storeId = $params['store'];
$useDefault = $params['use_default'];
if (!in_array('sort_order', $useDefault)) {
return $this;
}
$resource = Mage::getSingleton('core/resource');
$readConnection = $resource->getConnection('core_read');
$writeConnection = $resource->getConnection('core_write');
// get ids values for media gallery
$select = $readConnection->select()->from(
$resource->getTableName('catalog_product_entity_media_gallery'),
'value_id'
);
$select->where('entity_id = ?', $productId);
$valueIds = $readConnection->fetchCol($select);
if (empty($valueIds)) {
return $this;
}
// delete media gallery values by conditions
$writeConnection->delete(
$resource->getTableName('catalog_product_entity_media_gallery_value'),
['value_id IN (?)' => $valueIds, 'store_id = ?' => $storeId]
);
return $this;
}
}
app/design/adminhtml/default/default/template/catalog/product/helper/gallery.phtml
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE_AFL.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magento.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magento.com for more information.
*
* @category design
* @package default_default
* @copyright Copyright (c) 2006-2018 Magento, Inc. (http://www.magento.com)
* @license http://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']); ?></th>
<?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>
<?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> </td>
<td class="a-center">
<button id="button_use_default_sort_order" title="If is checked, the global values for sort order will be used." type="button" onclick="toggleCheckboxSortOrder()">
<span><span><span>Use default</span></span></span>
</button>
<input id="use_default_sort_order" class="default-checkbox" name="use_default" type="checkbox" value="sort_order" style="display: none;"/>
</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>
<?php endforeach; ?>
<td> </td>
<td class="last"> </td>
</tr>
<?php endif ?>
<tr id="<?php echo $_block->getHtmlId() ?>-image-0">
<td class="cell-image"><?php echo Mage::helper('catalog')->__('No image') ?></td>
<td class="cell-label"><input type="hidden" /> </td>
<td class="cell-position"><input type="hidden" /> </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>
<?php endforeach; ?>
<td class="cell-disable"><input type="hidden" /> </td>
<td class="cell-remove last"><input type="hidden" /> </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>
</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()) ?>" />
<script type="text/javascript">
//<![CDATA[
var <?php echo $_block->getJsObjectName(); ?> = new Product.Gallery('<?php echo $_block->getHtmlId() ?>', <?php echo $_block->getImageTypesJson() ?>);
function toggleCheckboxSortOrder()
{
var checkUseDefault = document.getElementById('use_default_sort_order');
var buttonUseDefault = document.getElementById('button_use_default_sort_order');
if (buttonUseDefault.classList.contains('ok_button')) {
checkUseDefault.checked = false;
buttonUseDefault.className = '';
} else {
checkUseDefault.checked = true;
buttonUseDefault.className = 'ok_button';
}
}
//]]>
</script>
I put the gallery.phtml(with the applied changes) file instead of a patch due to it's size, but is better to make a patch instead on changing this file.
With the above code every time when you save a product on a store you can click the new button to reset the 'sort order' in order to apply the global values(from Default Values store view).
add a comment |
By default magento doesn't care about resetting rows from catalog_product_entity_media_gallery_value table. So, I managed to solve this problem by adding an observer after product is saved and by adding a patch in order to add a button or checkbox to gallery.phtml file.
app/code/local/Namespace/Name/etc/config.xml
<catalog_product_save_commit_after>
<observers>
<catalog_product_save_commit_after_check_media_use_default>
<type>singleton</type>
<class>namespace_name/observer_resetMediaSortOrder</class>
<method>execute</method>
</catalog_product_save_commit_after_check_media_use_default>
</observers>
</catalog_product_save_commit_after>
app/code/local/Namespace/Name/Model/Observer/ResetMediaSortOrder.php
<?php
class Namespace_Name_Model_Observer_ResetMediaSortOrder
{
/**
* Execute observer on 'catalog_product_prepare_save' event.
*
* @param Varien_Event_Observer $observer
* @return Namespace_Name_Model_Observer_CheckMediaSortOrder
*/
public function execute(Varien_Event_Observer $observer): self
{
$params = Mage::app()->getRequest()->getParams();
$productId = $params['id'];
$storeId = $params['store'];
$useDefault = $params['use_default'];
if (!in_array('sort_order', $useDefault)) {
return $this;
}
$resource = Mage::getSingleton('core/resource');
$readConnection = $resource->getConnection('core_read');
$writeConnection = $resource->getConnection('core_write');
// get ids values for media gallery
$select = $readConnection->select()->from(
$resource->getTableName('catalog_product_entity_media_gallery'),
'value_id'
);
$select->where('entity_id = ?', $productId);
$valueIds = $readConnection->fetchCol($select);
if (empty($valueIds)) {
return $this;
}
// delete media gallery values by conditions
$writeConnection->delete(
$resource->getTableName('catalog_product_entity_media_gallery_value'),
['value_id IN (?)' => $valueIds, 'store_id = ?' => $storeId]
);
return $this;
}
}
app/design/adminhtml/default/default/template/catalog/product/helper/gallery.phtml
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE_AFL.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magento.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magento.com for more information.
*
* @category design
* @package default_default
* @copyright Copyright (c) 2006-2018 Magento, Inc. (http://www.magento.com)
* @license http://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']); ?></th>
<?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>
<?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> </td>
<td class="a-center">
<button id="button_use_default_sort_order" title="If is checked, the global values for sort order will be used." type="button" onclick="toggleCheckboxSortOrder()">
<span><span><span>Use default</span></span></span>
</button>
<input id="use_default_sort_order" class="default-checkbox" name="use_default" type="checkbox" value="sort_order" style="display: none;"/>
</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>
<?php endforeach; ?>
<td> </td>
<td class="last"> </td>
</tr>
<?php endif ?>
<tr id="<?php echo $_block->getHtmlId() ?>-image-0">
<td class="cell-image"><?php echo Mage::helper('catalog')->__('No image') ?></td>
<td class="cell-label"><input type="hidden" /> </td>
<td class="cell-position"><input type="hidden" /> </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>
<?php endforeach; ?>
<td class="cell-disable"><input type="hidden" /> </td>
<td class="cell-remove last"><input type="hidden" /> </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>
</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()) ?>" />
<script type="text/javascript">
//<![CDATA[
var <?php echo $_block->getJsObjectName(); ?> = new Product.Gallery('<?php echo $_block->getHtmlId() ?>', <?php echo $_block->getImageTypesJson() ?>);
function toggleCheckboxSortOrder()
{
var checkUseDefault = document.getElementById('use_default_sort_order');
var buttonUseDefault = document.getElementById('button_use_default_sort_order');
if (buttonUseDefault.classList.contains('ok_button')) {
checkUseDefault.checked = false;
buttonUseDefault.className = '';
} else {
checkUseDefault.checked = true;
buttonUseDefault.className = 'ok_button';
}
}
//]]>
</script>
I put the gallery.phtml(with the applied changes) file instead of a patch due to it's size, but is better to make a patch instead on changing this file.
With the above code every time when you save a product on a store you can click the new button to reset the 'sort order' in order to apply the global values(from Default Values store view).
add a comment |
By default magento doesn't care about resetting rows from catalog_product_entity_media_gallery_value table. So, I managed to solve this problem by adding an observer after product is saved and by adding a patch in order to add a button or checkbox to gallery.phtml file.
app/code/local/Namespace/Name/etc/config.xml
<catalog_product_save_commit_after>
<observers>
<catalog_product_save_commit_after_check_media_use_default>
<type>singleton</type>
<class>namespace_name/observer_resetMediaSortOrder</class>
<method>execute</method>
</catalog_product_save_commit_after_check_media_use_default>
</observers>
</catalog_product_save_commit_after>
app/code/local/Namespace/Name/Model/Observer/ResetMediaSortOrder.php
<?php
class Namespace_Name_Model_Observer_ResetMediaSortOrder
{
/**
* Execute observer on 'catalog_product_prepare_save' event.
*
* @param Varien_Event_Observer $observer
* @return Namespace_Name_Model_Observer_CheckMediaSortOrder
*/
public function execute(Varien_Event_Observer $observer): self
{
$params = Mage::app()->getRequest()->getParams();
$productId = $params['id'];
$storeId = $params['store'];
$useDefault = $params['use_default'];
if (!in_array('sort_order', $useDefault)) {
return $this;
}
$resource = Mage::getSingleton('core/resource');
$readConnection = $resource->getConnection('core_read');
$writeConnection = $resource->getConnection('core_write');
// get ids values for media gallery
$select = $readConnection->select()->from(
$resource->getTableName('catalog_product_entity_media_gallery'),
'value_id'
);
$select->where('entity_id = ?', $productId);
$valueIds = $readConnection->fetchCol($select);
if (empty($valueIds)) {
return $this;
}
// delete media gallery values by conditions
$writeConnection->delete(
$resource->getTableName('catalog_product_entity_media_gallery_value'),
['value_id IN (?)' => $valueIds, 'store_id = ?' => $storeId]
);
return $this;
}
}
app/design/adminhtml/default/default/template/catalog/product/helper/gallery.phtml
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE_AFL.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magento.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magento.com for more information.
*
* @category design
* @package default_default
* @copyright Copyright (c) 2006-2018 Magento, Inc. (http://www.magento.com)
* @license http://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']); ?></th>
<?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>
<?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> </td>
<td class="a-center">
<button id="button_use_default_sort_order" title="If is checked, the global values for sort order will be used." type="button" onclick="toggleCheckboxSortOrder()">
<span><span><span>Use default</span></span></span>
</button>
<input id="use_default_sort_order" class="default-checkbox" name="use_default" type="checkbox" value="sort_order" style="display: none;"/>
</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>
<?php endforeach; ?>
<td> </td>
<td class="last"> </td>
</tr>
<?php endif ?>
<tr id="<?php echo $_block->getHtmlId() ?>-image-0">
<td class="cell-image"><?php echo Mage::helper('catalog')->__('No image') ?></td>
<td class="cell-label"><input type="hidden" /> </td>
<td class="cell-position"><input type="hidden" /> </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>
<?php endforeach; ?>
<td class="cell-disable"><input type="hidden" /> </td>
<td class="cell-remove last"><input type="hidden" /> </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>
</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()) ?>" />
<script type="text/javascript">
//<![CDATA[
var <?php echo $_block->getJsObjectName(); ?> = new Product.Gallery('<?php echo $_block->getHtmlId() ?>', <?php echo $_block->getImageTypesJson() ?>);
function toggleCheckboxSortOrder()
{
var checkUseDefault = document.getElementById('use_default_sort_order');
var buttonUseDefault = document.getElementById('button_use_default_sort_order');
if (buttonUseDefault.classList.contains('ok_button')) {
checkUseDefault.checked = false;
buttonUseDefault.className = '';
} else {
checkUseDefault.checked = true;
buttonUseDefault.className = 'ok_button';
}
}
//]]>
</script>
I put the gallery.phtml(with the applied changes) file instead of a patch due to it's size, but is better to make a patch instead on changing this file.
With the above code every time when you save a product on a store you can click the new button to reset the 'sort order' in order to apply the global values(from Default Values store view).
By default magento doesn't care about resetting rows from catalog_product_entity_media_gallery_value table. So, I managed to solve this problem by adding an observer after product is saved and by adding a patch in order to add a button or checkbox to gallery.phtml file.
app/code/local/Namespace/Name/etc/config.xml
<catalog_product_save_commit_after>
<observers>
<catalog_product_save_commit_after_check_media_use_default>
<type>singleton</type>
<class>namespace_name/observer_resetMediaSortOrder</class>
<method>execute</method>
</catalog_product_save_commit_after_check_media_use_default>
</observers>
</catalog_product_save_commit_after>
app/code/local/Namespace/Name/Model/Observer/ResetMediaSortOrder.php
<?php
class Namespace_Name_Model_Observer_ResetMediaSortOrder
{
/**
* Execute observer on 'catalog_product_prepare_save' event.
*
* @param Varien_Event_Observer $observer
* @return Namespace_Name_Model_Observer_CheckMediaSortOrder
*/
public function execute(Varien_Event_Observer $observer): self
{
$params = Mage::app()->getRequest()->getParams();
$productId = $params['id'];
$storeId = $params['store'];
$useDefault = $params['use_default'];
if (!in_array('sort_order', $useDefault)) {
return $this;
}
$resource = Mage::getSingleton('core/resource');
$readConnection = $resource->getConnection('core_read');
$writeConnection = $resource->getConnection('core_write');
// get ids values for media gallery
$select = $readConnection->select()->from(
$resource->getTableName('catalog_product_entity_media_gallery'),
'value_id'
);
$select->where('entity_id = ?', $productId);
$valueIds = $readConnection->fetchCol($select);
if (empty($valueIds)) {
return $this;
}
// delete media gallery values by conditions
$writeConnection->delete(
$resource->getTableName('catalog_product_entity_media_gallery_value'),
['value_id IN (?)' => $valueIds, 'store_id = ?' => $storeId]
);
return $this;
}
}
app/design/adminhtml/default/default/template/catalog/product/helper/gallery.phtml
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE_AFL.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magento.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magento.com for more information.
*
* @category design
* @package default_default
* @copyright Copyright (c) 2006-2018 Magento, Inc. (http://www.magento.com)
* @license http://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']); ?></th>
<?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>
<?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> </td>
<td class="a-center">
<button id="button_use_default_sort_order" title="If is checked, the global values for sort order will be used." type="button" onclick="toggleCheckboxSortOrder()">
<span><span><span>Use default</span></span></span>
</button>
<input id="use_default_sort_order" class="default-checkbox" name="use_default" type="checkbox" value="sort_order" style="display: none;"/>
</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>
<?php endforeach; ?>
<td> </td>
<td class="last"> </td>
</tr>
<?php endif ?>
<tr id="<?php echo $_block->getHtmlId() ?>-image-0">
<td class="cell-image"><?php echo Mage::helper('catalog')->__('No image') ?></td>
<td class="cell-label"><input type="hidden" /> </td>
<td class="cell-position"><input type="hidden" /> </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>
<?php endforeach; ?>
<td class="cell-disable"><input type="hidden" /> </td>
<td class="cell-remove last"><input type="hidden" /> </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>
</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()) ?>" />
<script type="text/javascript">
//<![CDATA[
var <?php echo $_block->getJsObjectName(); ?> = new Product.Gallery('<?php echo $_block->getHtmlId() ?>', <?php echo $_block->getImageTypesJson() ?>);
function toggleCheckboxSortOrder()
{
var checkUseDefault = document.getElementById('use_default_sort_order');
var buttonUseDefault = document.getElementById('button_use_default_sort_order');
if (buttonUseDefault.classList.contains('ok_button')) {
checkUseDefault.checked = false;
buttonUseDefault.className = '';
} else {
checkUseDefault.checked = true;
buttonUseDefault.className = 'ok_button';
}
}
//]]>
</script>
I put the gallery.phtml(with the applied changes) file instead of a patch due to it's size, but is better to make a patch instead on changing this file.
With the above code every time when you save a product on a store you can click the new button to reset the 'sort order' in order to apply the global values(from Default Values store view).
answered yesterday
Pavel Adrian
125118
125118
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f240745%2fproduct-images-force-default-sort-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Do you find a solution? I'm trying to do the same thing with sort order, label and checkbox exclude. Thanks
– Walid
Dec 6 '18 at 8:43
This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. You can also add a bounty to draw more attention to this question once you have enough reputation. - From Review
– Rama Chandran M
Dec 6 '18 at 9:01