【发布时间】:2016-04-07 10:06:06
【问题描述】:
我们如何在 magento CE 1.9 中以编程方式为产品创建属性?我一直在尝试多种方法来为产品创建属性,该属性的布尔值默认设置为 false 并分配给默认属性集,但任何管理面板用户均不可见/不可编辑。
我的模型/资源/Eav/Mysql4/Setup.php
<?php
class Mofosys_Quickbuy_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', 0),
'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_GLOBAL
),
'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', 0),
'is_visible_on_front' => $this->_getValue($attr, 'visible_on_front', 0),
'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;
}
}
?>
我的 etc/config.xml
<global>
<resources>
<mofosys_quickbuy_setup>
<setup>
<module>Mofosys_Quickbuy</module>
<class>Mofosys_Quickbuy_Model_Resource_Eav_Mysql4_Setup</class>
</setup>
</mofosys_quickbuy_setup>
</resources>
</global>
我的 sql/mofosys_quickbuy_setup/install-0.0.1.php
<?php
// Installer file to create an attribute name "approved" inside Default attribute set
$installer = $this;
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$installer->startSetup();
// the attribute added will be displayed under the group/tab Special Attributes in product edit page
$setup->addAttribute('catalog_product', 'approved', array(
'group' => 'Default',
'input' => 'select',
'type' => 'int',
'default' => '0',
'label' => 'Testing',
'backend' => '',
'visible' => 0,
'required' => 0,
'user_defined' => 0,
'searchable' => 0,
'filterable' => 0,
'comparable' => 0,
'visible_on_front' => 0,
'visible_in_advanced_search' => 0,
'is_html_allowed_on_front' => 0,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
$installer->endSetup();
?>
【问题讨论】:
-
您能在此处发布您到目前为止所做的代码吗?
-
我已经把我的整个代码放在那里创建我的属性
标签: php mysql magento zend-framework magento-1.9