magento1给customer添加自定义属性 customer orientation customer journey map customer bas

php中文网
发布: 2016-07-29 08:51:43
原创
944人浏览过

data-id="1190000005008696" data-license="cc">

在模块的sql文件中:
/**

  • Add Attribute mobile for customer
    */

<code>//echo 12345;
$installer = $this;
$installer->startSetup();
$eavConfig = Mage::getSingleton('eav/config');
$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++,
),</code>
登录后复制

);
/将以上属性存入数据库,并且添加到页面表单中/

度加剪辑
度加剪辑

度加剪辑(原度咔剪辑),百度旗下AI创作工具

度加剪辑 63
查看详情 度加剪辑
<code>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 (false === ($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->endSeup();



添加下拉框的属性,添加性别 male 和 famale:
$installer->startSetup();  
  
$installer->addAttribute('customer', 'gender', array(  
    'label'        => 'Gender',  
    'visible'      => true,  
    'required'     => false,  
    'type'         => 'int',  
    'input'        => 'select',  
    'source'        => 'eav/entity_attribute_source_table',  
));  
</code>
登录后复制
<code>$tableOptions        = $installer->getTable('eav_attribute_option');  
$tableOptionValues   = $installer->getTable('eav_attribute_option_value');  
  
// add options for level of politeness  
$attributeId = (int)$installer->getAttribute('customer', 'gender', 'attribute_id');  
foreach (array('Male', 'Female') as $sortOrder => $label) {  
  
// add option  
$data = array(
    'attribute_id' => $attributeId,  
    'sort_order'   => $sortOrder,  
);  
$installer->getConnection()->insert($tableOptions, $data);  

// add option label  
$optionId = (int)$installer->getConnection()->lastInsertId($tableOptions, 'option_id');  
$data = array(  
    'option_id' => $optionId,  
    'store_id'  => 0,  
    'value'     => $label,  
);  
$installer->getConnection()->insert($tableOptionValues, $data);  
</code>
登录后复制

}

<code>$installer->endSetup();
</code>
登录后复制

以上就介绍了magento1给customer添加自定义属性,包括了customer,magento方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门推荐
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号