magento添加客户自定义字段

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_id
INSERT 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>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值