Magento 在产品图像库中添加复选框(如“禁用/排除”)

Magento 在产品图像库中添加复选框(如“禁用/排除”),magento,Magento,我正在尝试编写一个新的复选框,添加到图像库中“禁用”旁边的列中。它的行为将与“Disable/Exclude”=Yes/No以及数据库中的条目相同 其想法是为图像库中的每个图像添加一个“用作页面”复选框。目标是制作一个JS旋转木马,所有图片都被选中为“用作页面” 我做了一些事情,但我不能: 更新数据库中的数据=>将0或1设置为“页面”字段(见下文) 从数据库检索数据,然后根据“页面”字段选中/取消选中复选框 -->所以我的问题是:如何更新数据库中的数据并在复选框中检索它(0或1取决于字段值)

我正在尝试编写一个新的复选框,添加到图像库中“禁用”旁边的列中。它的行为将与“Disable/Exclude”=Yes/No以及数据库中的条目相同

其想法是为图像库中的每个图像添加一个“用作页面”复选框。目标是制作一个JS旋转木马,所有图片都被选中为“用作页面”

我做了一些事情,但我不能:

  • 更新数据库中的数据=>将0或1设置为“页面”字段(见下文)
  • 从数据库检索数据,然后根据“页面”字段选中/取消选中复选框
-->所以我的问题是:如何更新数据库中的数据并在复选框中检索它(0或1取决于字段值)

谢谢大家的宝贵帮助


以下是我所做的(1.4.1.0):

1-更新表格目录\产品\实体\媒体\图库\价值

添加了一个新字段(名称为“页面”):

  • 第tinyint(4)页未签名的编号0
2-对类别Mage\u目录\u型号\u产品\u属性\u后端\u媒体进行了以下更改

第49行:

第223行:

第301行

第328行

3-对模板adminhtml/default/default/template/catalog/product/helper/gallery.phtml进行了以下更改

第64行



第77行

disabled=“disabled”onclick=“.updateImage”(“文件”)

disabled=“disabled”onclick=“.updateImage”(“文件”)
disabled=“disabled”onclick=“.updateImage”(“文件”)/>
第105行


我最近正在做类似的工作,发现这段代码是解决方案的一部分:

$fieldset->addField('entire_range', 'checkbox', array(
      'checked'    => $this->getEntireRange()==1 ? 'true' : 'false',
      'onclick'    => 'this.value = this.checked ? 1 : 0;'
)))

我也无法让它将值保存到数据库中。它与Varien_Data_Form_Element_Checkbox类有关

希望这有帮助,如果你找到了,请发布你的解决方案

干杯,
JD

这就是我解决问题的方法,并且工作得非常完美。除了你的改变之外,也要做这些

1。在图像\目录\模型\产品\属性\后端\媒体中

改变

public function addImage(Mage_Catalog_Model_Product $product, $file,
    $mediaAttribute = null, $move = false, $exclude = true)

改变

public function addImagesWithDifferentMediaAttributes(Mage_Catalog_Model_Product $product,
    $fileAndAttributesArray, $filePath = '', $move = false, $exclude = true)
$savedFileName = $this->addImage($product, $filePath . $value['file'], null, $move, $exclude);
array('label','position','disabled')
            array(
                'label_default' => 'label',
                'position_default' => 'position',
                'disabled_default' => 'disabled',
            )
    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.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);

改变

public function addImagesWithDifferentMediaAttributes(Mage_Catalog_Model_Product $product,
    $fileAndAttributesArray, $filePath = '', $move = false, $exclude = true)
$savedFileName = $this->addImage($product, $filePath . $value['file'], null, $move, $exclude);
array('label','position','disabled')
            array(
                'label_default' => 'label',
                'position_default' => 'position',
                'disabled_default' => 'disabled',
            )
    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.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);

2。转到图像\目录\模型\资源\产品\属性\后端\媒体

改变

public function addImagesWithDifferentMediaAttributes(Mage_Catalog_Model_Product $product,
    $fileAndAttributesArray, $filePath = '', $move = false, $exclude = true)
$savedFileName = $this->addImage($product, $filePath . $value['file'], null, $move, $exclude);
array('label','position','disabled')
            array(
                'label_default' => 'label',
                'position_default' => 'position',
                'disabled_default' => 'disabled',
            )
    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.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);

改变

public function addImagesWithDifferentMediaAttributes(Mage_Catalog_Model_Product $product,
    $fileAndAttributesArray, $filePath = '', $move = false, $exclude = true)
$savedFileName = $this->addImage($product, $filePath . $value['file'], null, $move, $exclude);
array('label','position','disabled')
            array(
                'label_default' => 'label',
                'position_default' => 'position',
                'disabled_default' => 'disabled',
            )
    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.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);

3。在js/mage/adminhtml/product.js中

改变

public function addImagesWithDifferentMediaAttributes(Mage_Catalog_Model_Product $product,
    $fileAndAttributesArray, $filePath = '', $move = false, $exclude = true)
$savedFileName = $this->addImage($product, $filePath . $value['file'], null, $move, $exclude);
array('label','position','disabled')
            array(
                'label_default' => 'label',
                'position_default' => 'position',
                'disabled_default' => 'disabled',
            )
    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.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);

改变

public function addImagesWithDifferentMediaAttributes(Mage_Catalog_Model_Product $product,
    $fileAndAttributesArray, $filePath = '', $move = false, $exclude = true)
$savedFileName = $this->addImage($product, $filePath . $value['file'], null, $move, $exclude);
array('label','position','disabled')
            array(
                'label_default' => 'label',
                'position_default' => 'position',
                'disabled_default' => 'disabled',
            )
    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.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);


只需使用搜索文本查找更改代码的位置。希望这有帮助

经过大量的努力,我发现除了最初的帖子和第二张海报的推荐之外,你还需要打开/app/code/core/Mage/Catalog/sql/Catalog\u setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php,转到第2023行的以下内容:

$installer->getTable('catalog/product_attribute_media_gallery_value') => array(
更改此项:

'disabled' => array(
    'type'      => Varien_Db_Ddl_Table::TYPE_SMALLINT,
    'unsigned'  => true,
    'nullable'  => false,
    'default'   => '0',
    'comment'   => 'Is Disabled'
 )
为此:

'disabled' => array(
    'type'      => Varien_Db_Ddl_Table::TYPE_SMALLINT,
    'unsigned'  => true,
    'nullable'  => false,
    'default'   => '0',
    'comment'   => 'Is Disabled'
 ),
'page' => array(
    'type'      => Varien_Db_Ddl_Table::TYPE_SMALLINT,
    'unsigned'  => true,
    'nullable'  => false,
    'default'   => '0',
    'comment'   => 'Page'
 )
当Magento保存时,它会检查此文件,以确保传递的字段与这些数组中的值匹配。

我得到了错误信息

注意:未定义索引“页面”

在课堂上

图像目录、模型、产品、属性、后端、媒体

在第224行

我得换衣服

js/mage/adminhtml/product.js

现在效果很好


谢谢。

谢谢Jonathan的回答,但我认为它适用于标准的网格小部件,而图片/图像小部件则不适用。不-事实上,自从我发布了这个问题后,我没有看它。。。