资讯专栏INFORMATION COLUMN

magento1给customer添加自定义属性

HollisChuang / 693人阅读

摘要:在模块的文件中将以上属性存入数据库,并且添加到页面表单中添加下拉框的属性,添加性别和

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

Add Attribute mobile for customer
*/

//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++,
),

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

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",  
));  
$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);  

}

$installer->endSetup();

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/30315.html

相关文章

  • magento1 得到产品的相关信息

    摘要:一产品信息先判定是否为产品页面获取产品的,根据得到产品对象通过获取产品对象产品的信息产品库存将产品加入购物车注如果产品购买时需要选择下拉框时,该将进入产品详情页,否则直接就如购物车。 一、产品信息 1、先判定是否为产品页面 if (Mage::registry(‘product’)){ } 2、获取产品的Id,根据Id得到产品对象 通过sku获取产品...

    Fourierr 评论0 收藏0
  • magento1为产品gird表格添加缩略图

    1、在Girid.php添加: $this->addColumn(image,array( header => Mage::helper(employee)->__(Image), align => center, index => image,/*数据库中存储图片的字段名称*/ renderer => Nam...

    libin19890520 评论0 收藏0
  • 一个简单的Magento1.9模块示例

    摘要:本次要做的就是,撰写一个模块,让该模块跑完整个的流程。创建模型,需要启用模型,启用资源模型,在资源模型中添加实体,再为资源模型设置读写适配器。 很多时候,不知道Magento模块到底该怎么写,比如ThinkPHP,YII框架,它是直接将控制器Controller中的所取得相关数据直接传递到视图层View,而Magento虽然也是MVC三层,但是在中间多了布局对象Layout与区块Blo...

    Pikachu 评论0 收藏0
  • Magento1如何打开调试模式,来显示前台路径提示信息?

    摘要:的版本中如何开启调试模式呢在前面,写了一篇有关如何开启调试模式来显示前台的路径信息,便于在学习的时候,能快速的找到各个对应的文件。但是,现在这个项目用的,在的版本中如何开启调试模式呢两种方法供参考方法一通过后台控制台来操作,选择也选择。 magento1.x的版本中如何开启调试模式呢? 在前面,写了一篇有关Magento2.0如何开启调试模式来显示前台的路径信息,便于在学习magent...

    hlcfan 评论0 收藏0
  • Magento1.X 如何在线安装插件?

    摘要:版本中,安装插件,有两种方式可以安装插件,程序员最常用的方法就是将开发的插件模块文件直接从上传到对应目录即可。等到显示就是安装完成此时就可以去你的后台,来操作你刚刚装的插件模块了 Magento1.X版本中,安装插件,有两种方式可以安装插件,程序员最常用的方法就是将开发的插件模块文件直接从FTP上传到对应目录即可。而对于新手或不懂程序的人来说,此方法就有些晦涩难懂了(参见另一片文章)。...

    xingpingz 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<