博客
关于我
magento1给customer添加自定义属性
阅读量:794 次
发布时间:2023-02-06

本文共 2750 字,大约阅读时间需要 9 分钟。

在模块的SQL文件中,添加了以下功能:首先,新增了“chuanzhen”和“sex”属性,分别对应身份证号和性别字段。其次,通过循环添加这些属性到页面表单中,确保数据准确同步到数据库。最后,手动添加性别下拉框选项,支持“Male”和“Female”两个值。

// 初始化设置$installer = $this;$installer->startSetup();// 获取当前店铺信息$store = Mage::app()->getStore(Mage_Core_Model_App::ADMIN_STORE_ID);// 定义排序顺序$sortOrder = 999;// 添加自定义属性$attributes = array(    'chuanzhen' => array(        'type'          => 'varchar',        'label'         => 'chuanzhen',        'input'         => 'text',        'required'      => 1,        'global'        => 1,        'is_visible'    => 1,        'is_system'     => 0,        'position'      => 40,        'is_user_defined' => 1,        'sort_order'    => $sortOrder++    ),    'sex' => array(        'type'          => 'int',        'label'         => 'Sex',        'input'         => 'radio',        'required'      => 1,        'is_visible'    => 1,        'is_system'     => 0,        'global'        => 1,        'is_user_defined' => 1,        'position'      => 44,        'sort_order'    => $sortOrder++    ));// 将定义的属性添加到数据库foreach ($attributes as $attributeCode => $data) {    $installer->addAttribute('customer', $attributeCode, $data);}// 设置属性访问权限foreach ($attributes as $attributeCode => $data) {    $attribute = $eavConfig->getAttribute('customer', $attributeCode);    $attribute->setWebsite($store->getWebsite());    $attribute->addData($data);    // 设置属性在表单中的可用性    if ($data['is_system'] == 1 && $data['is_visible'] == 0) {        $usedInForms = array(            'customer_account_create',            'customer_account_edit',            'checkout_register',            'adminhtml_customer',            'adminhtml_checkout'        );        $attribute->setData('used_in_forms', $usedInForms);    }    $attribute->save();}$installer->endSetup();// 添加性别下拉框选项$installer->startSetup();$installer->addAttribute('customer', 'gender', array(    'label'        => 'Gender',    'visible'      => true,    'required'     => false,    'type'         => 'int',    'input'        => 'select',    'source'        => 'eav/entity_attribute_source_table'));// 添加性别选项$tableOptions = $installer->getTable('eav_attribute_option');$tableOptionValues = $installer->getTable('eav_attribute_option_value');$attributeId = (int)$installer->getAttribute('customer', 'gender', 'attribute_id');foreach (array('Male', 'Female') as $sortOrder => $label) {    $installer->getConnection()->insert($tableOptions, array(        'attribute_id' => $attributeId,        'sort_order' => $sortOrder    ));    $optionId = (int)$installer->getConnection()->lastInsertId($tableOptions, 'option_id');    $installer->getConnection()->insert($tableOptionValues, array(        'option_id' => $optionId,        'store_id' => 0,        'value' => $label    ));}$installer->endSetup();

转载地址:http://ahufk.baihongyu.com/

你可能感兴趣的文章
Mac电脑生成git的公私钥(拉取代码更便捷)
查看>>
Magentic-One、AutoGen、LangGraph、CrewAI 或 OpenAI Swarm:哪种多 AI 代理框架最好?
查看>>
magento1给customer添加自定义属性
查看>>
Magic Leap是快出产品的节奏,已开放内容开发者注册通道
查看>>
Majorization-Minimization (MM) 和 Successive Convex Approximation (SCA)
查看>>
makefile 打印
查看>>
makefile工作笔记0001---认识使用makefile
查看>>
Makefile遗漏分隔符错误解决
查看>>
malloc和定位new表达式
查看>>
MAMP无法正常启动,错误提示The built-in Apache is active
查看>>
Managing CentOS/RHEL kernel modules.
查看>>
Mangoa-Auth/芒果自助多应用企业级授权系统拥有盗版入库、远程更新等功能
查看>>
MangoDB4.0版本的安装与配置
查看>>
Manjaro 24.1 “Xahea” 发布!具有 KDE Plasma 6.1.5、GNOME 46 和最新的内核增强功能
查看>>
Manjaro 24.2 “Yonada” 发布:尖端功能与精美界面再度进化
查看>>
Manjaro Linux 推出新不可变版本:扩展产品范围,开放社区反馈和测试
查看>>
Manual write code to record error log in .net by Global.asax
查看>>
map 函数返回的列表在使用一次后消失
查看>>
Map 遍历取值及jstl的取值
查看>>
Mapbox GL示例教程【目录】-- 已有80篇
查看>>