向产品图片库添加一个复选框(如“禁用/排除") [英] Add a checkbox to product image gallery (like "Disable/Exclude")

查看:14
本文介绍了向产品图片库添加一个复选框(如“禁用/排除")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个新的复选框,以附加到图片库中的列中,在禁用"旁边.它的行为将与禁用/排除"= 是/否与数据库中的条目相同.

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") :

  • page tinyint(4) UNSIGNED No 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 行

来自 

            <td class="cell-disable"><input type="hidden" />&nbsp;</td>
            <td class="cell-page last"><input type="hidden" />&nbsp;</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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆