我们的客户希望在客户注册中添加“行业”下拉列表。我们创建了一个新的客户属性“行业”并输入了适当的值。
它没有显示在前端。我查看了customer/form/register.phtml
并且它没有为属性调用任何内容,所以我从enterprise/default/template/customer/form/register.phtml
取出了以下内容:
<?php $customerAttributes = $this->getChild('customer_form_user_attributes');?>
<?php if ($customerAttributes): ?>
<?php $customerAttributes->setShowContainer(false);?>
<?php $this->restoreSessionData($customerAttributes->getForm());?>
<?php echo $customerAttributes->toHtml()?>
<?php endif;?>
然后我添加了'enterprise / layout / customer.xml'中的.xml更新:
<remove name="right"/>
<remove name="left"/>
<reference name="root">
<action method="setTemplate"><template>page/1column.phtml</template></action>
</reference>
<block type="page/html_wrapper" name="customer.form.register.fields.before" translate="label">
<label>Form Fields Before</label>
<!--action method="setMayBeInvisible"><value>1</value></action-->
<action method="setElementClass"><value>rewards</value></action>
</block>
<block type="enterprise_customer/form" template="customer/form/userattributes.phtml" name="customer_form_user_attributes">
<action method="setFormCode"><code>customer_account_create</code></action>
<action method="setEntityModelClass"><code>customer/customer</code></action>
</block>
<block type="enterprise_customer/form" template="customer/form/userattributes.phtml" name="customer_form_address_user_attributes">
<action method="setFormCode"><code>customer_register_address</code></action>
<action method="setEntityModelClass"><code>customer/address</code></action>
</block>
<reference name="content">
<block type="customer/form_register" name="customer_form_register" template="customer/form/register.phtml">
<action method="append"><block>customer.form.register.fields.before</block> <alias>form_fields_before</alias></action>
<action method="append"><block>customer_form_user_attributes</block> </action>
<action method="append"> <block>customer_form_address_user_attributes</block></action>
</block>
</reference>
<update handle="customer_form_template_handle"/>
此时,属性在前端不可见。如果我执行:
<pre>
<?php print_r($customerAttributes->getUserDefinedAttributes()) ?>
</pre>
我按照预期返回了属性数组。我在这里缺少什么?
答案 0 :(得分:3)
找到它。在customer.xml中需要这些东西。出于某种原因,使用enterprise / default customer.xml不起作用,但我添加了这个并且它很好。
<customer_form_template_handle>
<reference name="content">
<block name="customer_form_template" type="enterprise_customer/form_template">
<action method="addRenderer">
<type>text</type>
<renderer_block>enterprise_customer/form_renderer_text</renderer_block>
<template>customer/form/renderer/text.phtml</template>
</action>
<action method="addRenderer">
<type>textarea</type>
<renderer_block>enterprise_customer/form_renderer_textarea</renderer_block>
<template>customer/form/renderer/textarea.phtml</template>
</action>
<action method="addRenderer">
<type>multiline</type>
<renderer_block>enterprise_customer/form_renderer_multiline</renderer_block>
<template>customer/form/renderer/multiline.phtml</template>
</action>
<action method="addRenderer">
<type>date</type>
<renderer_block>enterprise_customer/form_renderer_date</renderer_block>
<template>customer/form/renderer/date.phtml</template>
</action>
<action method="addRenderer">
<type>select</type>
<renderer_block>enterprise_customer/form_renderer_select</renderer_block>
<template>customer/form/renderer/select.phtml</template>
</action>
<action method="addRenderer">
<type>multiselect</type>
<renderer_block>enterprise_customer/form_renderer_multiselect</renderer_block>
<template>customer/form/renderer/multiselect.phtml</template>
</action>
<action method="addRenderer">
<type>boolean</type>
<renderer_block>enterprise_customer/form_renderer_boolean</renderer_block>
<template>customer/form/renderer/boolean.phtml</template>
</action>
<action method="addRenderer">
<type>file</type>
<renderer_block>enterprise_customer/form_renderer_file</renderer_block>
<template>customer/form/renderer/file.phtml</template>
</action>
<action method="addRenderer">
<type>image</type>
<renderer_block>enterprise_customer/form_renderer_image</renderer_block>
<template>customer/form/renderer/image.phtml</template>
</action>
</block>
</reference>
</customer_form_template_handle>
答案 1 :(得分:0)
您应该检查控制用户定义属性的template/customer/form/userattributes.phtml
。我不知道,是否有人触过此文件?先检查一下。
<?php foreach ($this->getUserDefinedAttributes() as $attribute):?>
<?php $attributeContent = $this->getAttributeHtml($attribute);?>
<?php if ($attributeContent): ?>
<li><?php echo $attributeContent;?></li>
<?php endif;?>
<?php endforeach;?>