Magento,sql,setup的方式添加一个select属性,add attribute selet by module sql

本文主要是介绍Magento,sql,setup的方式添加一个select属性,add attribute selet by module sql,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

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_Setup


2.数据库文件

<?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(); 




清空缓存,运行,就会建立起来属性了


这篇关于Magento,sql,setup的方式添加一个select属性,add attribute selet by module sql的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/845213

相关文章

shell脚本批量导出redis key-value方式

《shell脚本批量导出rediskey-value方式》为避免keys全量扫描导致Redis卡顿,可先通过dump.rdb备份文件在本地恢复,再使用scan命令渐进导出key-value,通过CN... 目录1 背景2 详细步骤2.1 本地docker启动Redis2.2 shell批量导出脚本3 附录总

Oracle查询表结构建表语句索引等方式

《Oracle查询表结构建表语句索引等方式》使用USER_TAB_COLUMNS查询表结构可避免系统隐藏字段(如LISTUSER的CLOB与VARCHAR2同名字段),这些字段可能为dbms_lob.... 目录oracle查询表结构建表语句索引1.用“USER_TAB_COLUMNS”查询表结构2.用“a

MySQL中EXISTS与IN用法使用与对比分析

《MySQL中EXISTS与IN用法使用与对比分析》在MySQL中,EXISTS和IN都用于子查询中根据另一个查询的结果来过滤主查询的记录,本文将基于工作原理、效率和应用场景进行全面对比... 目录一、基本用法详解1. IN 运算符2. EXISTS 运算符二、EXISTS 与 IN 的选择策略三、性能对比

MySQL常用字符串函数示例和场景介绍

《MySQL常用字符串函数示例和场景介绍》MySQL提供了丰富的字符串函数帮助我们高效地对字符串进行处理、转换和分析,本文我将全面且深入地介绍MySQL常用的字符串函数,并结合具体示例和场景,帮你熟练... 目录一、字符串函数概述1.1 字符串函数的作用1.2 字符串函数分类二、字符串长度与统计函数2.1

SpringBoot多环境配置数据读取方式

《SpringBoot多环境配置数据读取方式》SpringBoot通过环境隔离机制,支持properties/yaml/yml多格式配置,结合@Value、Environment和@Configura... 目录一、多环境配置的核心思路二、3种配置文件格式详解2.1 properties格式(传统格式)1.

Oracle数据库定时备份脚本方式(Linux)

《Oracle数据库定时备份脚本方式(Linux)》文章介绍Oracle数据库自动备份方案,包含主机备份传输与备机解压导入流程,强调需提前全量删除原库数据避免报错,并需配置无密传输、定时任务及验证脚本... 目录说明主机脚本备机上自动导库脚本整个自动备份oracle数据库的过程(建议全程用root用户)总结

SQL Server跟踪自动统计信息更新实战指南

《SQLServer跟踪自动统计信息更新实战指南》本文详解SQLServer自动统计信息更新的跟踪方法,推荐使用扩展事件实时捕获更新操作及详细信息,同时结合系统视图快速检查统计信息状态,重点强调修... 目录SQL Server 如何跟踪自动统计信息更新:深入解析与实战指南 核心跟踪方法1️⃣ 利用系统目录

MySQL 内存使用率常用分析语句

《MySQL内存使用率常用分析语句》用户整理了MySQL内存占用过高的分析方法,涵盖操作系统层确认及数据库层bufferpool、内存模块差值、线程状态、performance_schema性能数据... 目录一、 OS层二、 DB层1. 全局情况2. 内存占js用详情最近连续遇到mysql内存占用过高导致

Debian系和Redhat系防火墙配置方式

《Debian系和Redhat系防火墙配置方式》文章对比了Debian系UFW和Redhat系Firewalld防火墙的安装、启用禁用、端口管理、规则查看及注意事项,强调SSH端口需开放、规则持久化,... 目录Debian系UFW防火墙1. 安装2. 启用与禁用3. 基本命令4. 注意事项5. 示例配置R

Mysql中设计数据表的过程解析

《Mysql中设计数据表的过程解析》数据库约束通过NOTNULL、UNIQUE、DEFAULT、主键和外键等规则保障数据完整性,自动校验数据,减少人工错误,提升数据一致性和业务逻辑严谨性,本文介绍My... 目录1.引言2.NOT NULL——制定某列不可以存储NULL值2.UNIQUE——保证某一列的每一