doulian7305 2014-04-01 20:03
浏览 17
已采纳

通过代码在客户帐户中启用字段

I'm developing a module where it will change the value of the field Display Date of Birth and View CPF/CNPJ in Settings>customers>settings>name and address options.

When this value is set as required, it shows fields in the customer master in "customer / account / create /", for this I use the following code in an installation script, so that when the module is activated it already enable these fields that do not come by default.

Code:

$inchooSwitch = new Mage_Core_Model_Config();

$inchooSwitch->saveConfig('customer/address/dob_show', "req", 'default', '');
$inchooSwitch->saveConfig('customer/address/taxvat_show', "req", 'default', '');

Code changes successfully, but when I access the page customer/account/create/ fields do not appear.

Any idea why this happens?

update

I used the hint of Himansu, but happens the same as before does not show the fields on the page:

fields

as you can see not appear on the Birth Date field

update x2

yes, it changes value in core_config_data table, but does not show the field on the page, do not understand why it does not show the fields on the page

table

  • 写回答

2条回答 默认 最新

  • dousigan0499 2014-04-02 19:12
    关注

    I used the suggestion of Himansu and changed this:

    $inchooSwitch = new Mage_Core_Model_Config();
    
    $inchooSwitch->saveConfig('customer/address/dob_show', "req", 'default', '');
    $inchooSwitch->saveConfig('customer/address/taxvat_show', "req", 'default', '');
    $inchooSwitch->saveConfig('customer/address/gender_show', "req", 'default', '');
    

    for this:

    Mage::getModel('core/config')->saveConfig('customer/address/dob_show', 'req');
    Mage::getModel('core/config')->saveConfig('customer/address/taxvat_show', 'req');
    Mage::getModel('core/config')->saveConfig('customer/address/gender_show', 'req');
    

    then I saw the system.xml they used a backend_model adminhtml/system_config_backend_customer_show_customer, which possessed the _afterSave function that set the attribute as visible and necessary, so I used:

    $dobAtribute = Mage::getModel('eav/entity_attribute')->loadByCode('customer', 'dob');
    $dobAtribute->setData('is_required', 1);
    $dobAtribute->setData('is_visible', 1);
    $dobAtribute->save();
    
    $taxvatAtribute = Mage::getModel('eav/entity_attribute')->loadByCode('customer', 'taxvat');
    $taxvatAtribute->setData('is_required', 1);
    $taxvatAtribute->setData('is_visible', 1);
    $taxvatAtribute->save();
    
    $genderAtribute = Mage::getModel('eav/entity_attribute')->loadByCode('customer', 'gender');
    $genderAtribute->setData('is_required', 1);
    $genderAtribute->setData('is_visible', 1);
    $genderAtribute->save();
    

    all code:

    <?php
    
    Mage::getModel('core/config')->saveConfig('customer/address/dob_show', 'req');
    Mage::getModel('core/config')->saveConfig('customer/address/taxvat_show', 'req');
    Mage::getModel('core/config')->saveConfig('customer/address/gender_show', 'req');
    
    $dobAtribute = Mage::getModel('eav/entity_attribute')->loadByCode('customer', 'dob');
    $dobAtribute->setData('is_required', 1);
    $dobAtribute->setData('is_visible', 1);
    $dobAtribute->save();
    
    $taxvatAtribute = Mage::getModel('eav/entity_attribute')->loadByCode('customer', 'taxvat');
    $taxvatAtribute->setData('is_required', 1);
    $taxvatAtribute->setData('is_visible', 1);
    $taxvatAtribute->save();
    
    $genderAtribute = Mage::getModel('eav/entity_attribute')->loadByCode('customer', 'gender');
    $genderAtribute->setData('is_required', 1);
    $genderAtribute->setData('is_visible', 1);
    $genderAtribute->save();
    

    Thanks for all

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址