gpt4 book ai didi

magento - 如何在magento中向客户添加自定义复选框字段?

转载 作者:行者123 更新时间:2023-12-02 12:45:33 25 4
gpt4 key购买 nike

在 mysql4-install-0.1.0.php 中,我可以在我的 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();

现在我可以看到带有 yes|no 选项的选择组件并且其工作完美。它还显示在客户注册表上,如下所示:

<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>

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

最佳答案

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

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

然后就可以了

关于magento - 如何在magento中向客户添加自定义复选框字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11624091/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com