配置文件在数据库中的反应
CONFIG.xml与SETUP
Setup 在数据库的处理流程
I'm going to stop right here to explain how/when the setup scripts are run:
The setup script mechanism is run the FIRST time a request is made after the cache is cleared.
o Magento will get a collection of all the "setup resources" and their corresponding Module version numbers from the config.xml files.
o Magento will then go to the core_resource table and get a collection of all the "setup resources" and their version numbers stored in the table.
o Magento will then do 1 of 3 things:
o If the setup resource doesn't exist in the core_resource table it will run an install script.
o If the resource version in the database is less than the one in the config.xml file, it will run one to many update scripts.
o If the resource version in the database is greater than the one in the config.xml file, it will run a rollback script.
mysql4-upgrade与mysql4-install
各种EAV的Entity与属性
MAGENTO与EAV的设计与应用,主要包如下的几个方面: EAV设计在数据库中的反映;
对entity 对象的查询,单个实体对象的查找,entity实体对象的修改,添加,删除操作;
新建一个新的entity.
EAV设计或者是entity实体在数据库中的反映:
EAV设计或者对实体的操作大多是通过封装方法或者是配置来实现的,而非单纯的SQL语句。这样做的好处是操作更加简单,但是所产生的问题就在于配置出现问题导致调试非常麻烦。
针对setup与resource(即module中所必须定义的resource)
in the config.xml we need to define the resources. The one we really care about here is the "setup" resource.Remember the name "awesome_setup" and notice the module element inside of it. The module is the "driver" for the setup scripts. If the module's version number changes, it will look for scripts to run.
如:
1: 2: ...3: 4: 5: 6: Super_Awesome7: 8: 9: core_setup10: 11: 12: 13: 14: core_write15: 16: 17: 18: 19: core_read20: 21: 22: 23:
install与upgrade SQL脚本
Magento will then do 1 of 3 things:
SQL INSTALL & CORE_RESOURCE: If the setup resource doesn't exist in the core_resource table it will run an install script,并且将setup resource 插入到core_resource表中。
SQL UPGRADE: If the resource version in the database is less than the one in the config.xml file, it will run one to many update scripts.
If the resource version in the database is greater than the one in the config.xml file, it will run a rollback script.
针对自定义attribute的关键表:
在EAV实体设计中,是可以自行添加attribute,而非重新新建字段等。使用EAV来添加属性。其中的方法包括:
addAttribute(),removeAttribute(),upgradeAttribute().
如;
1: $setup->addAttribute('customer', 'school', array(2: 'type' => 'int',3: 'input' => 'select',4: 'label' => 'School',5: 'global' => 1,6: 'visible' => 1,7: 'required' => 0,8: 'user_defined' => 1,9: 'default' => '0',10: 'visible_on_front' => 1,11: 'source'=> 'profile/entity_school',12: ));
其中对于属性处理,所涉及到的关键公用表[也就是说任何的一个实体自定义属性都会添加或者修改数据在这三张表中]:
eav_entity_type
eav_attribute
eav_entity_attribute
entity与form
eav_form_element
eav_form_type : 所有处理entity的form
eav_form_type_entity: entity与entity type 之间的关联。如customer涉及到哪些form操作等
eav_entity_type: 记录所有entity实体对象的关键配置信息
关键字段
entity_type_id:实体对象的ID值,与多个表有着关联关系,特别是eav_attribute,使用entity_type_id,可以知道该实体对象所有的属性(包括MAGENTO默认的系统属性以及customize的属性值)
entity_type_code:实体标识
entity_model:ORM的结果, 可使用getmodel()来实例化model,进而调用model所定义的方法。
entity_table:实体所对应的最关键表
eav_attribute表
关键字段
attribute_code:属性所对应的关键标识。
attribute_id: 属性的ID值
其它的字段信息,直接与addAttribute()所添加的信息保持一致。
也就是说如果添加或者是删除了某一个实体对象,它会直接反映在eav_entity_type表中。
First entry it made in the eav_attribute table
1: INSERT INTO `eav_attribute` (2: `attribute_id` ,3: `entity_type_id` ,4: `attribute_code` ,5: `attribute_model` ,6: `backend_model` ,7: `backend_type` ,8: `backend_table` ,9: `frontend_model` ,10: `frontend_input` ,11: `frontend_label` ,12: `frontend_class` ,13: `source_model` ,14: `is_required` ,15: `is_user_defined` ,16: `default_value` ,17: `is_unique` ,18: `note`19: )20: VALUES (21: NULL , '1', 'school', NULL , NULL , 'int', NULL , NULL , 'select', 'School', NULL , 'profile/entity_school', '1', '0', '0', '0', ''22: );
After insert query, the attribute generated is my case is 121. Next this attribute needs to be associated to an attribute set, the sql for this is
1: INSERT INTO `eav_entity_attribute` (2: `entity_attribute_id` ,3: `entity_type_id` ,4: `attribute_set_id` ,5: `attribute_group_id` ,6: `attribute_id` ,7: `sort_order`8: )9: VALUES (10: NULL , '1', '1', '1', '121', '0'11: );12: The sort_order value in this table, specifies where the attribute will show in admin.
针对单个entity attribute的数据表:
customer:
customer_eav_attribute:定义website_id,is_visible,is_required 等
customer_eav_attribute_website:If your using multiple store, you need to make an entry in customer_eav_attribute_website as well
customer_form_attribute: 属性出现,设置在哪些form中,比如说注册,修改用户信息等
Next we need to make entry in a table “customer_eav_attribute”
1: INSERT INTO `customer_eav_attribute` (2: `attribute_id` ,3: `is_visible` ,4: `input_filter` ,5: `multiline_count` ,6: `validate_rules` ,7: `is_system` ,8: `sort_order` ,9: `data_model`10: )11: VALUES (12: '121', '1', NULL , '1', NULL , '0', '0', NULL13: );
If your using multiple store, you need to make an entry in customer_eav_attribute_website as well, but this entry is not compulsary
1: INSERT INTO `customer_eav_attribute_website` (2: `attribute_id` ,3: `website_id` ,4: `is_visible` ,5: `is_required` ,6: `default_value` ,7: `multiline_count`8: )9: VALUES (10: '121', '0', '1', '0', NULL , NULL11: );
Next we need to make entry in a table called “customer_form_attribute”
1: INSERT INTO `customer_form_attribute` (2: `form_code` ,3: `attribute_id`4: )5: VALUES (6: 'adminhtml_customer', '121'7: ), (8: 'checkout_register', '121'9: ), (10: 'customer_account_create', '121'11: ), (12: 'customer_account_edit', '121'13: )14: ;
customer_address
bill
MAGENTO系统预定义的实体对象:
商品模块
Catalog(商品类)
catalog_category
catalog_product
用户模块
customer(用户)
customer
customer_address (集中表现在bill)
销售模块
creditmemo(支付)
creditmemo
creditmemo_comment
creditmemo_item
Invoice(发票)
• invoice_comment
• invoice_item
• invoice_payment
Order(订单)
• order_address
• order_item
• order_payment
• order_status_history
Quote(销售单据凭证)
• quote_address
• quote_address_item
• quote_address_rate
• quote_item
• quote_payment
运输模块
Shipment(运输模块)
• shipment_comment
• shipment_item
• shipment_track
KIPS:所有的实体model都会自动的做set与get. 具体的所使用到的set与get可以参考:http://docs.magentocommerce.com
Global Tag
Adminhtml Tag
Frontend Tag
Default Tag
The default tag allows you to specify any set of config variables needed for yourmodule. The values are normally obtained with getStoreConfig, passing the name of your XML tags as a slash separated string. For better organization of these ad-hoc variables it is customary to wrap all of your settings in a tag that matches your modu’les name. The values in the default tag can be overwritten on the configuration page
of the administrative back-end. Any changes to the defaults are inserted into the database table core_config_data. Thesemodified values are still retrieved with a call to getStoreConfig.
entity attribute 在数据库中的反应
为product catelog 添加 Attribute ,
为不同的Entity 添加Attribute
订单表
sales_flat_order
sales_flat_order_address
sales_flat_order_item
coupon 表
salesrule_coupon 存储所有的coupon code
salesrule_coupon_usage 使用情况