2012-07-24 55 views
5

在mysql4安装-0.1.0.php,我可以在我的Magento模块添加自定义文本字段是这样的:如何向magento中的客户添加自定义复选框字段?

$entityTypeId  = $setup->getEntityTypeId('customer'); 
$attributeSetId = $setup->getDefaultAttributeSetId($entityTypeId); 
$attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId); 

$setup->addAttribute('customer', 'resale', array(
    'input'   => 'text', 
    'type'   => 'varchar', 
    'label'   => 'Resale number', 
    'visible'  => 1, 
    'required'  => 1, 
    'user_defined' => 1, 
)); 

$setup->addAttributeToGroup(
$entityTypeId, 
$attributeSetId, 
$attributeGroupId, 
'resale', 
'999' //sort_order 
); 

$oAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'resale'); 
$oAttribute->setData('used_in_forms', array('adminhtml_customer','customer_account_create')); 
$oAttribute->save(); 

我还想添加一个复选框字段。我补充这样的:

$setup->addAttribute('customer', 'marketattended1', array(
    'input'   => 'checkbox', 
    'type'   => 'int', 
    'label'   => 'San Francisco International Gift Fair', 
    'visible'  => 1, 
    'required'  => 0, 
    'user_defined' => 1, 
)); 

$setup->addAttributeToGroup(
$entityTypeId, 
$attributeSetId, 
$attributeGroupId, 
'marketattended1', 
'999' //sort_order 
); 

$oAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'marketattended1'); 
$oAttribute->setData('used_in_forms', array('adminhtml_customer','customer_account_create')); 
$oAttribute->save(); 

我可以看到管理/我的客户复选框字段,但是当我试图编辑或添加新的客户也不会保存客户。它只是永远显示“请稍等”指标。如何使这项工作?

* 编辑

呼叫一个成员函数的setAttribute()的非对象

上我发现这个错误或服务器响应。

* 编辑

我改变了安装程序代码:

$setup->addAttribute('customer', 'marketattended1', array(
    'input'   => 'boolean', 
    'type'   => 'int', 
    'label'   => 'San Francisco International Gift Fair', 
    'visible'  => 1, 
    'required'  => 0, 
    'user_defined' => 1, 
    //'source'  => 'eav/entity_attribute_source_boolean' 
)); 

$setup->addAttributeToGroup(
$entityTypeId, 
$attributeSetId, 
$attributeGroupId, 
'marketattended1', 
'999' //sort_order 
); 

$oAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'marketattended1'); 
$oAttribute->setData('used_in_forms', array('adminhtml_customer','customer_account_create')); 
$oAttribute->save(); 

现在我可以看到选择组件用是|否选项及其工作完美。它也显示在这样的客户登记表上:

<div class="field"> 
    <label for="marketattended1">San Francisco International Gift Fair</label> 
    <select id="marketattended1" name="marketattended1" class=" select"> 
     <option value="0">No</option> 
     <option value="1">Yes</option> 
    </select></div> 

我希望它是复选框。我试过这样:

<div class="field"> 
     <input class="checkbox" id="marketattended1" onchange="[removed]changechecked()" type="checkbox" value="1" /> 
     <label class="required">*Others</label > 
    </div> 

但它不会保存。如何让它保存?

回答

1

我使它与JavaScript一起工作。我隐藏了select元素并添加了jQuery复选框。当用户点击复选框时,我改变选择的值。

(function($){ 
    $(document).ready(function(){ 
     var selects = $('.checkselect'); 
     $.each(selects, function(index, select){ 
      var checkbox = "<input class='selectcheckbox' type='checkbox' value='0' />"; 
      $(select).append($(checkbox)); 
      $(select).find('select').hide(); 
      $(select).on('click', '.selectcheckbox', function(){ 
       if($(this).is(':checked')) 
        $(select).find('select').val('1'); 
       else 
        $(select).find('select').val('0'); 
      }); 
     }); 
    }); 
})(jQuery); 

不是最好的解决方案,但我只需要在项目中前进。如果有人找到更好的解决方案,请在此回答。

5

必须添加的复选框的名称:

<input class="checkbox" id="marketattended1" name="marketattended1" onchange="[removed]changechecked()" type="checkbox" value="1" /> 

然后,它的工作原理

相关问题