magento添加客户自定义字段

来源:互联网 发布:文明5 for mac 汉化 编辑:程序博客网 时间:2024/05/17 00:10
INSERT INTO  `eav_attribute` (`attribute_id` ,`entity_type_id` ,`attribute_code` ,`attribute_model` ,`backend_model` ,`backend_type` ,`backend_table` ,`frontend_model` ,`frontend_input` ,`frontend_label` ,`frontend_class` ,`source_model` ,`is_required` ,`is_user_defined` ,`default_value` ,`is_unique` ,`note`) VALUES (NULL ,  '1',  'customertype', NULL , '' ,  'int', '' , '' , 'select', 'Customer Type', '' , 'eav/entity_attribute_source_table',  '1',  '0',  '',  '0',  '');运行上面语句后得到attribute_id再运行下面语句(例如attribute_id为121,120为sort_order)INSERT INTO  `eav_entity_attribute` (`entity_attribute_id` ,`entity_type_id` ,`attribute_set_id` ,`attribute_group_id` ,`attribute_id` ,`sort_order`)VALUES (NULL , '1', '1', '1', '121', '120');INSERT INTO  `customer_eav_attribute` (`attribute_id` ,`is_visible` ,`input_filter` ,`multiline_count` ,`validate_rules` ,`is_system` ,`sort_order` ,`data_model`)VALUES ('121',  '1', '' ,  '1', '' ,  '0',  '120', NULL);INSERT INTO  `customer_form_attribute` (`form_code` ,`attribute_id`)VALUES ('adminhtml_customer',  '121'), ('checkout_register',  '121'), ('customer_account_create',  '121'), ('customer_account_edit',  '121');下面为添加的选项INSERT INTO `eav_attribute_option` (`option_id`, `attribute_id`, `sort_order`) VALUES(NULL, 121, 0),(NULL, 121, 1),(NULL, 121, 2),(NULL, 121, 3);下面5,6,7,8为 eav_attribute_option 的 option_idINSERT INTO `eav_attribute_option_value` (`value_id`, `option_id`, `store_id`, `value`) VALUES(NULL, 5, 0, 'Wholesaler'),(NULL, 6, 0, 'Retailers'),(NULL, 7, 0, 'Agents'),(NULL, 8, 0, 'Individual customers');


在注册页面(/customer/form/register.phtml)添加:

<li>                    <?php                        $attribute = Mage::getModel('eav/config')->getAttribute('customer','customertype');                    ?>                    <div class="input-box" style="float:left; clear:none; width:275px;"><label for="customertype"><?php echo $this->__('Customer Type') ?><?php if($attribute->getIsRequired() == true){?> <span class="<?php if($attribute->getIsRequired() == true){?>required<?php } ?>">*</span><?php } ?></label><br />                        <select name="customertype" id="customertype" class="<?php if($attribute->getIsRequired() == true){?>required-entry<?php } ?>">                            <?php                                 $options = $attribute->getSource()->getAllOptions();                                 foreach($options as $option){                            ?>                                <option value='<?php echo $option['value']?>' <?php if($this->getFormData()->getCustomertype() == $option['value']){ echo 'selected="selected"';}?>><?php echo $this->__($option['label'])?></option>                            <?php } ?>                        </select>                    </div></li>
在编辑页面(/customer/form/edit.phtml)添加:
<li>                    <?php                        $attribute = Mage::getModel('eav/config')->getAttribute('customer','customertype');                    ?>                    <div class="input-box" style="float:left; clear:none; width:275px;"><label for="customertype"><?php echo $this->__('Customer Type') ?><?php if($attribute->getIsRequired() == true){?> <span class="<?php if($attribute->getIsRequired() == true){?>required<?php } ?>">*</span><?php } ?></label><br />                        <select name="customertype" id="customertype" class="<?php if($attribute->getIsRequired() == true){?>required-entry<?php } ?>">                            <?php                                 $options = $attribute->getSource()->getAllOptions();                                 foreach($options as $option){                            ?>                                <option value='<?php echo $option['value']?>' <?php if($this->getCustomer()->getCustomertype() == $option['value']){ echo 'selected="selected"';}?>><?php echo $this->__($option['label'])?></option>                            <?php } ?>                        </select>                    </div></li>

原创粉丝点击