【问题标题】:While adding product attribute "Use is product listing" option setting as "Yes"将产品属性“使用是产品列表”选项设置为“是”时
【发布时间】:2014-07-06 10:28:02
【问题描述】:

我已在我的自定义 magento 模块的安装程序中添加了此代码。

$installer->addAttribute('catalog_product','size_guide',array( '组' => '一般', 'type' => 'tinyint', '标签' => '启用尺寸图', '输入' => '布尔', '来源' => 'eav/entity_attribute_source_table', 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, '可见' => 真, '必需' => 假, 'user_defined' => 真, 'used_in_product_listing' => 真, '默认' => '', '独特' => 假,enter code here 'apply_to' => '' )); 安装模块后添加了“size_guide”属性,但属性中的“用于产品列表”下拉列表仍设置为否,但正如您在我的代码中看到的那样,我已将产品列表中的使用设置为 true。

'used_in_product_listing' => 是的,

感谢您的帮助。

提前致谢。

【问题讨论】:

    标签: magento magento-1.7 magento-1.8


    【解决方案1】:

    当您查看Mage_Eav_Model_Entity_Setup 类中此方法的定义时,您将看到以下代码:

    $data = array_merge(
            array(
                'entity_type_id' => $entityTypeId,
                'attribute_code' => $code
            ),
            $this->_prepareValues($attr)
         );
    

    此代码为属性准备数据。在_prepareValues() 方法中,您可以看到返回的数组不包含used_in_product_listing 键。因此,即使您在数组中提供它,它也不会传递给方法。 要解决此问题,您必须在 config.xml 中声明您自己的资源设置模型

    <resources>
      <company_module_setup>
        <setup>
          <module>Company_Module</module>
          <class>Company_Module_Model_Resource_Setup</class>
        </setup>
      </company_module_setup>
    </resources>    
    

    然后创建类并像这样覆盖_prepareValues() 方法

    class Company_Module_Model_Resource_Setup extends Mage_Eav_Model_Entity_Setup {
    
      protected function _prepareValues($attr) {
        $data = parent::_prepareValues($attr);
        $data = array_merge($data, array(
            'frontend_input_renderer'       => $this->_getValue($attr, 'input_renderer'),
            'is_global'                     => $this->_getValue(
                $attr,
                'global',
                Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL
            ),
            'is_visible'                    => $this->_getValue($attr, 'visible', 1),
            'is_searchable'                 => $this->_getValue($attr, 'searchable', 0),
            'is_filterable'                 => $this->_getValue($attr, 'filterable', 0),
            'is_comparable'                 => $this->_getValue($attr, 'comparable', 0),
            'is_visible_on_front'           => $this->_getValue($attr, 'visible_on_front', 0),
            'is_wysiwyg_enabled'            => $this->_getValue($attr, 'wysiwyg_enabled', 0),
            'is_html_allowed_on_front'      => $this->_getValue($attr, 'is_html_allowed_on_front', 0),
            'is_visible_in_advanced_search' => $this->_getValue($attr, 'visible_in_advanced_search', 0),
            'is_filterable_in_search'       => $this->_getValue($attr, 'filterable_in_search', 0),
            'used_in_product_listing'       => $this->_getValue($attr, 'used_in_product_listing', 0),
            'used_for_sort_by'              => $this->_getValue($attr, 'used_for_sort_by', 0),
            'apply_to'                      => $this->_getValue($attr, 'apply_to'),
            'position'                      => $this->_getValue($attr, 'position', 0),
            'is_configurable'               => $this->_getValue($attr, 'is_configurable', 1),
            'is_used_for_promo_rules'       => $this->_getValue($attr, 'used_for_promo_rules', 0)
        ));
        return $data;
      }
    
    }
    

    它将允许您将其余选项添加到属性中

    【讨论】:

      【解决方案2】:

      尝试使用

      $_installer = Mage::getResourceModel('catalog/setup', 'catalog_setup');
      

      【讨论】:

        猜你喜欢
        • 2018-10-20
        • 2015-08-29
        • 2012-05-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-03-03
        • 2018-10-06
        相关资源
        最近更新 更多