Magento,sql,setup的方式添加一个select属性,add attribute selet by module sql
2013-12-20 17:02
399 查看
1.新建一个模块Resource里面这么定义:
<resources> <wailian_setup> <setup> <module>Lon_Wailian</module> <class>Mage_Catalog_Model_Resource_Setup</class> </setup> <connection> <use>core_setup</use> </connection> </wailian_setup> </resources>注意:在<setup>里面<class>Mage_Catalog_Model_Resource_Setup</class>,这个一定要填写正确Mage_Catalog_Model_Resource_Setup2.数据库文件
<?php $installer = $this; $installer->startSetup(); //属性的Attribute Code,只能用字母和下划线,中间可以加入数字 $attribute_name = 'ccc'; //属性集中的group,和general等一个东西,是后台产品详细页面左侧的标签 $AttributeGroup = "sss"; if(! ($this instanceof Mage_Catalog_Model_Resource_Setup) ) { throw new Exception("Resource Class needs to inherit from " . "Mage_Catalog_Model_Resource_Setup for this to work"); } //属性定义 $attr = array ( 'attribute_model' => NULL, 'backend' => '', 'type' => 'int', 'table' => '', 'frontend' => '', 'input' => 'select', //Catalog Input Type for Store Owner 'label' => 'bbb', //label 'frontend_class' => '', 'source' => '', 'required' => '0', //Values Required 'user_defined' => '1', 'default' => '', 'unique' => '0', 'note' => '', 'input_renderer' => NULL, 'global' => '1', //Scope 'visible' => '1', 'searchable' => '1', //Use in Quick Search 'filterable' => '1', //Use In Layered Navigation 'comparable' => '1', //Comparable on Front-end 'visible_on_front' => '0', 'is_html_allowed_on_front' => '0', //Allow HTML Tags on Frontend 'is_used_for_price_rules' => '1', 'filterable_in_search' => '1', //Use In Search Results Layered Navigation 'used_in_product_listing' => '0', //Used in Product Listing 'used_for_sort_by' => '0', //Used for Sorting in Product Listing 'is_configurable' => '1', //Use To Create Configurable Product 'apply_to' => 'simple', //Apply To * 'visible_in_advanced_search' => '1', //Use in Advanced Search 'position' => '1', //Position 'wysiwyg_enabled' => '0', 'used_for_promo_rules' => '1', 'option' => array ( 'values' => array ( 0 => 'Green', 1 => 'Silver', 2 => 'Black', 3 => 'Blue', 4 => 'Red', 5 => 'Pink', 6 => 'Magneta', 7 => 'Brown', 8 => 'White', 9 => 'Gray', ), ), ); //新建属性 $this->addAttribute('catalog_product',$attribute_name,$attr); //下面的部分为把新建的属性加入属性集 //得到属性的id $attributeId = $installer->getAttributeId( 'catalog_product', $attribute_name ); //得到属性集的id $defaultSetId = $installer->getAttributeSetId('catalog_product', 'default'); //在属性集里面新建group,也就是打开产品后,左边的标签,譬如general $installer->addAttributeGroup( 'catalog_product', $defaultSetId, $AttributeGroup ); //得到新建的group的id $groupId = $installer->getAttributeGroup( 'catalog_product', $defaultSetId, $AttributeGroup, 'attribute_group_id' ); //把属性加入到属性集,并在上面新建的group中 if ($attributeId > 0) { $installer->addAttributeToSet( 'catalog_product', $defaultSetId, $groupId, $attributeId ); } //OK新建一个select属性到这里就完成了 $installer->endSetup();清空缓存,运行,就会建立起来属性了
相关文章推荐
- 给分类添加一个属性,模块sql的方式 -- magento
- [Magento] Add custom attribute by SQL
- sql的select查询添加一个虚拟字段进去
- sql的方式修改产品属性 - 避免使用event (magento)
- magento addattributetoselect使用
- Magento 给用户customer ,添加一个属性
- SQL SELECT DISTINCT 单独一个字段 group by having where
- magento 为支付方式添加一个 最大金额和最小金额的限制
- 以编程方式向 ASP.NET 控件添加客户端事件处理程序--TextBox.Attributes.Add()
- hashtab:为文件属性添加一个数字指纹
- spring配置文件中添加hibernate属性---如:show_sql;format_sql
- Android高德地图,添加Marker会遮挡小蓝点,只需设置一个属性,可以让小蓝点显示在Marker上
- 如何利用运行时给系统分类添加一个属性?
- 如何给magento的分类添加自定义属性
- python mysql中不能在同一个sql语句中,先select同一个表的某些值,然后再update这个表。
- JavaScript中定义对象的方式,动态添加属性和动态删除属性!
- [Android Studio 权威教程]AS添加第三方库的6种方式(Jar,module,so等)
- 为某一个对象动态添加属性
- addAttributeToFilter Conditionals In Magento
- 有一个NSStirng类型,retain方式声明的name属性的setter方法内部每一行代码的作用?