在产品图片库中添加一个复选框(例如“禁用/排除") [英] Add a checkbox to product image gallery (like "Disable/Exclude")
问题描述
我正在尝试编写一个新复选框,以附加到禁用"旁边的图片库中的列.其行为将与在数据库中输入时的禁用/排除" =是/否相同.
I'm trying to code a new checkbox to be appended to the columns in the image gallery, beside "Disable". Its behavior would be the same as "Disable/Exclude" = Yes/No with entry in the database.
这个想法是为图片库中的每个图片添加一个用作页面"复选框.目标是制作一个JS轮播,将所有图片都选中为用作页面".
The idea is to add a "Use as page" checkbox for each image in the image gallery. The goal being to make a JS carousel with all pictures checked as "Use as page".
我已经完成了一些事情,但是我做不到:
I have a few things done but I cannot :
- 更新数据库中的数据=>将页面"字段设置为0或1(请参见下文)
- 从数据库中检索数据,然后根据页面"字段选中/取消选中该复选框.
->所以我的问题是:如何更新数据库中的数据并在复选框(0或1,取决于字段值)中进行检索?
--> So my question is : how to update data in the database and retrieve it in the checkbox (0 or 1 depending on the field value) ?
感谢大家的宝贵帮助.
这是我所做的(1.4.1.0):
Here is what I've done (1.4.1.0) :
1-更新表catalog_product_entity_media_gallery_value
添加了一个新字段(名称为页面"):
Added a new field (which name is "page") :
- 页面tinyint(4)未签名否0
2-对类Mage_Catalog_Model_Product_Attribute_Backend_Media进行了以下更改
第49行:
来自
$localAttributes = array('label', 'position', 'disabled');
到
$localAttributes = array('label', 'position', 'disabled', 'page');
第223行:
来自
$data['disabled'] = (int) $image['disabled'];
到
$data['disabled'] = (int) $image['disabled'];
$data['page'] = (int) $image['page'];
第301行
来自
$mediaGalleryData['images'][] = array(
'file' => $fileName,
'position' => $position,
'label' => '',
'disabled' => (int) $exclude
);
到
$mediaGalleryData['images'][] = array(
'file' => $fileName,
'position' => $position,
'label' => '',
'disabled' => (int) $exclude,
'page' => (int) $exclude,
);
第328行
来自
$fieldsMap = array(
'label' => 'label',
'position' => 'position',
'disabled' => 'disabled',
'exclude' => 'disabled',
);
到
$fieldsMap = array(
'label' => 'label',
'position' => 'position',
'disabled' => 'disabled',
'exclude' => 'disabled',
'page' => 'disabled',
);
3-对模板adminhtml/default/default/template/catalog/product/helper/gallery.phtml
第64行
来自
<th><?php echo Mage::helper('catalog')->__('Exclude') ?></th>
到
<th><?php echo Mage::helper('catalog')->__('Exclude') ?></th>
<th><?php echo Mage::helper('catalog')->__('Is Page') ?></th>
第77行
来自
<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-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-page a-center"><input type="checkbox" <?php if($_block->getElement()->getReadonly()):?> disabled="disabled"<?php endif;?> onclick="<?php echo $_block->getJsObjectName(); ?>.updateImage('__file__')" /></td>
第105行
来自
from
到
<td class="cell-disable"><input type="hidden" /> </td>
<td class="cell-page last"><input type="hidden" /> </td>
推荐答案
这是我解决问题的方式,并且运行正常.除了您所做的更改之外,也请进行这些更改.
This is how I solved the problem and is working perfectly. Beside your changes make these too.
1.在Mage_Catalog_Model_Product_Attribute_Backend_Media中
更改
public function addImage(Mage_Catalog_Model_Product $product, $file,
$mediaAttribute = null, $move = false, $exclude = true)
到
public function addImage(Mage_Catalog_Model_Product $product, $file,
$mediaAttribute = null, $move = false, $exclude = true, $page = false)
更改
public function addImagesWithDifferentMediaAttributes(Mage_Catalog_Model_Product $product,
$fileAndAttributesArray, $filePath = '', $move = false, $exclude = true)
到
public function addImagesWithDifferentMediaAttributes(Mage_Catalog_Model_Product $product,
$fileAndAttributesArray, $filePath = '', $move = false, $exclude = true, $page = true)
更改
$savedFileName = $this->addImage($product, $filePath . $value['file'], null, $move, $exclude);
到
$savedFileName = $this->addImage($product, $filePath . $value['file'], null, $move, $exclude, $page );
2.转到Mage_Catalog_Model_Resource_Product_Attribute_Backend_Media
更改
array('label','position','disabled')
到
array('label','position','disabled','page')
更改
array(
'label_default' => 'label',
'position_default' => 'position',
'disabled_default' => 'disabled',
)
到
array(
'label_default' => 'label',
'position_default' => 'position',
'disabled_default' => 'disabled',
'page_default' => 'page'
)
3.在js/mage/adminhtml/product.js
更改
this.getFileElement(file, 'cell-label input').value = image.label;
this.getFileElement(file, 'cell-position input').value = image.position;
this.getFileElement(file, 'cell-remove input').checked = (image.removed == 1);
this.getFileElement(file, 'cell-disable input').checked = (image.disabled == 1);
到
this.getFileElement(file, 'cell-label input').value = image.label;
this.getFileElement(file, 'cell-position input').value = image.position;
this.getFileElement(file, 'cell-remove input').checked = (image.removed == 1);
this.getFileElement(file, 'cell-disable input').checked = (image.disabled == 1);
this.getFileElement(file, 'cell-page input').checked = (image.page == 1);
更改
this.images[index].label = this
.getFileElement(file, 'cell-label input').value;
this.images[index].position = this.getFileElement(file,
'cell-position input').value;
this.images[index].removed = (this.getFileElement(file,
'cell-remove input').checked ? 1 : 0);
this.images[index].disabled = (this.getFileElement(file,
'cell-disable input').checked ? 1 : 0);
到
this.images[index].label = this
.getFileElement(file, 'cell-label input').value;
this.images[index].position = this.getFileElement(file,
'cell-position input').value;
this.images[index].removed = (this.getFileElement(file,
'cell-remove input').checked ? 1 : 0);
this.images[index].page = (this.getFileElement(file,
'cell-page input').checked ? 1 : 0);
this.images[index].disabled = (this.getFileElement(file,
'cell-disable input').checked ? 1 : 0);
只需使用搜索文本来查找更改代码的位置.希望这对您有所帮助.
Simply use search text to find where to change the code. Hope this helped.
这篇关于在产品图片库中添加一个复选框(例如“禁用/排除")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!