将自定义属性添加到客户注册表单


8

我需要创建两个新的客户属性。我遵循的指南来自:http : //www.fontis.com.au/blog/magento/know-more-about-your-customers-adding-custom-signup-attributes

创建这些属性。我已经检查了数据库中的“ eav_attribute”表,并可以确认两个属性都存在。唯一的事情是我不知道如何创建复选框属性,因此我将两个属性都创建为“是/否”。

按照我在注册表格上如何显示字段的代码进行操作:

<li class="control">
<div class="input-box">
    <label for="publisheroffer"><?php echo $this->__('Publisher Offer') ?><span class="required">*</span></label><br />
    <input type="checkbox" name="publisheroffer" id="publisheroffer" value="<?php echo $this->htmlEscape($this->getFormData()->getPublisheroffer()) ?>" title="<?php echo $this->__('Publisher Offer') ?>" class="input-text" />
</div>
</li>

其中属性ID为“ publisheroffer”。创建帐户后,它可以很好地创建,但自定义属性字段不会更改。

如何在注册页面上将此属性显示为复选框,以及如何处理这些值。

感谢您提前提供的所有帮助。


Magento自定义注册字段模块是扩展magento用户注册,与其他模块(如marketplacestore.webkul.com/Magento-Extensions/…)配合
webkul 2014年

Answers:


12

为了允许在注册表单和某些其他表单页面中发布属性,您必须设置该属性对那些表单可用。

为此,这里是将示例代码放入下面的sql设置中。您可以在我的github帐户上找到我用于Magento用户名模块的其余代码。

/* @var $installer Diglin_Username_Model_Entity_Setup */
$installer = $this;

/* @var $eavConfig Mage_Eav_Model_Config */
$eavConfig = Mage::getSingleton('eav/config');

$store = Mage::app()->getStore(Mage_Core_Model_App::ADMIN_STORE_ID);

$attributes = $installer->getAdditionalAttributes();

foreach ($attributes as $attributeCode => $data) {
    $installer->addAttribute('customer', $attributeCode, $data);

    $attribute = $eavConfig->getAttribute('customer', $attributeCode);
    $attribute->setWebsite( (($store->getWebsite()) ? $store->getWebsite() : 0));

    if (false === ($attribute->getIsSystem() == 1 && $attribute->getIsVisible() == 0)) {
        $usedInForms = array(
            'customer_account_create',
            'customer_account_edit',
            'checkout_register',
        );
        if (!empty($data['adminhtml_only'])) {
            $usedInForms = array('adminhtml_customer');
        } else {
            $usedInForms[] = 'adminhtml_customer';
        }
        if (!empty($data['adminhtml_checkout'])) {
            $usedInForms[] = 'adminhtml_checkout';
        }

        $attribute->setData('used_in_forms', $usedInForms);
    }
    $attribute->save();
}

嗨,注册表格上允许使用属性。我已经对“文本”输入类型执行了相同的过程,并且它们在提交注册时会更新得很好。我遇到的问题是我需要使用“是/否”输入类型,这是注册表单上的复选框。
user1669256

为什么不将的值设置为html标记中input的属性。您将拥有应该删除并设置(或其他)的功能checked$this->getFormData()->getPublisheroffer() == 1<input ... value="1" <?php echo ($this->getFormData()->getPublisheroffer() == 1): 'checked' : ''; ?>value="<?php echo $this->htmlEscape(...)"value="1"
SylvainRayé13年

0

您可以尝试以下代码来创建复选框自定义属性。

$customerSetup->addAttribute(Customer::ENTITY, 'customer_approved', [
            'type' => 'int',
            'label' => 'Customer Approved',
            'input' => 'boolean',
            'required' => false,
            'visible' => true,
            'user_defined' => true,
            'sort_order' => 1001,
            'position' => 1001,
            'system' => 0,
        ]);

        $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'customer_approved')
        ->addData([
            'attribute_set_id' => $attributeSetId,
            'attribute_group_id' => $attributeGroupId,
            'used_in_forms' => ['adminhtml_customer'],
        ]);

        $attribute->save();

使用输入“布尔”而不是“复选框”。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.