【发布时间】:2015-09-23 07:36:17
【问题描述】:
我正在尝试运行一个在 magento admin 中创建附加产品属性的脚本。但是该属性不会出现在管理后端。
这是我的模特:Setup.php
class Rts_Cattribute_Model_Resource_Eav_Mysql4_Setup extends Mage_Eav_Model_Entity_Setup
{
protected function _prepareValues($attr)
{
$data = parent::_prepareValues($attr);
$data = array_merge($data, array(
'apply_to' => $this->_getValue($attr, 'apply_to'),
'frontend_input_renderer' => $this->_getValue($attr, 'input_renderer'),
'is_comparable' => $this->_getValue($attr, 'comparable', 0),
'is_configurable' => $this->_getValue($attr, 'is_configurable', 1),
'is_filterable' => $this->_getValue($attr, 'filterable', 0),
'is_filterable_in_search' => $this->_getValue($attr, 'filterable_in_search', 0),
'is_global' => $this->_getValue(
$attr,
'global',
Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE
),
'is_html_allowed_on_front' => $this->_getValue($attr, 'is_html_allowed_on_front', 0),
'is_searchable' => $this->_getValue($attr, 'searchable', 0),
'is_used_for_promo_rules' => $this->_getValue($attr, 'used_for_promo_rules', 0),
'is_visible' => $this->_getValue($attr, 'visible', 1),
'is_visible_on_front' => $this->_getValue($attr, 'visible_on_front', 1),
'is_wysiwyg_enabled' => $this->_getValue($attr, 'wysiwyg_enabled', 0),
'is_visible_in_advanced_search' => $this->_getValue($attr, 'visible_in_advanced_search', 0),
'position' => $this->_getValue($attr, 'position', 0),
'used_for_sort_by' => $this->_getValue($attr, 'used_for_sort_by', 0),
'used_in_product_listing' => $this->_getValue($attr, 'used_in_product_listing', 0)
));
return $data;
}
}
这是我的配置:config.xml
<config>
<modules>
<Rts_Cattribute>
<version>0.1.0</version>
</Rts_Cattribute>
</modules>
<global>
<resources>
<cattribute_setup>
<setup>
<module>Rts_Cattribute</module>
<class>Rts_Cattribute_Model_Resource_Eav_Mysql4_Setup</class>
</setup>
</cattribute_setup>
</resources>
</global>
</config>
最后这是我的安装脚本:mysql4-install-0.1.0.php
$installer = $this;
$installer->startSetup();
$installer->addAttribute('catalog_product', 'max_ftlbs', array(
'type' => 'int',
'backend' => '',
'frontend' => '',
'label' => 'Max Ft.Lbs',
'input' => 'text',
'class' => '',
'source' => '',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => false,
'required' => false,
'user_defined' => false,
'default' => '',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'unique' => false,
'apply_to' => '',
'is_configurable' => false
));
$installer->endSetup();
我按照本教程进行操作
http://magento4newbies.blogspot.com/2015/01/how-to-adding-custom-product-attributes.html
http://codegento.com/2011/02/install-scripts-and-upgrade-scripts/
在这个链接Adding custom product attributes in Magento using setup script
它说magento安装程序的标准类是Mage_Eav_Model_Entity_Setup,但是在处理产品时,你需要使用Mage_Catalog_Model_Resource_Setup。
我尝试了很多解决方案,但都没有成功。
每次我进行一些更改时,我总是在刷新页面之前删除资源版本。
问题:
自定义属性不会显示或未在后台管理中创建。
问题:
magento 安装程序的正确标准类是什么?
我的安装程序正确吗?
希望你能帮我解决这个问题。
【问题讨论】:
-
app/etc/modules 中有xml文件吗?例如Rts_Cattribute.xml
0.1.0 -
是的,我已经包含了它,但是属性不显示,但版本已经在 core_resource 中。
-
也许你需要重新索引并清除缓存。你检查过数据库中的属性吗?
-
我总是清除我的缓存,但没有创建属性,但是版本已在 core_resource 表上注册。
-
如果您运行了一次设置,并且您的版本的设置表中有一行,则设置脚本不会再次运行。您需要将其从数据库中删除。