Php 在签出中显示自定义客户字段

Php 在签出中显示自定义客户字段,php,magento,magento-1.7,Php,Magento,Magento 1.7,我已成功地向客户添加自定义字段。但是,我需要这些字段显示在onepage签出中 我已经覆盖了Mage\u Customer\u Block\u Widget\u Name并创建了自己的Customer/Widget/Name.phtml,在sql/xxx\u setup/installer-x.y.z.php中添加了属性(将它们添加到adminhtml\u customer,customer\u account\u edit,checkout\u register和customer\u acco

我已成功地向客户添加自定义字段。但是,我需要这些字段显示在onepage签出中

我已经覆盖了
Mage\u Customer\u Block\u Widget\u Name
并创建了自己的
Customer/Widget/Name.phtml
,在
sql/xxx\u setup/installer-x.y.z.php中添加了属性(将它们添加到
adminhtml\u customer
customer\u account\u edit
checkout\u register
customer\u account\u create
)并且它们在管理站点中工作正常,但它们只是无法在签出表单上工作。显示该字段,但其值错误且没有标签

我不明白为什么它在客户登记表中有效,但在结账时不起作用

要添加属性的安装程序代码为:

$attributes = array(
    'lastname2' =>  array(
        'frontend_label'=>'Apellido Materno',
        'label' => 'Apellido Materno',
        'input' => 'text',
        'type'  => 'varchar',
        //System =  False and visible true = Show in 'customer_account_create', 'customer_account_edit', 'checkout_register'
        'system'=>true,
        'visible'=>true, //Watch out!! Only visible fields get processed by the form controllers!!!
        'user_defined'=>false,
        'used_in_forms' => array('adminhtml_customer', 'customer_account_edit', 'checkout_register','customer_account_create'),
        'required' => 0,
        'position' =>69
    ));


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

        /**
        * @var Mage_Eav_Model_Config
        */
        Mage::getSingleton('eav/config')
        ->getAttribute('customer', $attribute_code)
        ->setData('used_in_forms',$definition['used_in_forms'])
        ->save();
    }
name.phtml中的代码是

<div class="<?php echo $this->getContainerClassName()?>">
    <?php if ($this->showPrefix()): ?>
        <div class="field name-prefix">
            <label for="<?php echo $this->getFieldId('prefix')?>"<?php if ($this->isPrefixRequired()) echo ' class="required"' ?>><?php if ($this->isPrefixRequired()) echo '<em>*</em>' ?><?php echo $this->getStoreLabel('prefix') ?></label>
            <div class="input-box">
                <?php if ($this->getPrefixOptions() === false): ?>
                    <input type="text" id="<?php echo $this->getFieldId('prefix')?>" name="<?php echo $this->getFieldName('prefix')?>" value="<?php echo $this->escapeHtml($this->getObject()->getPrefix()) ?>" title="<?php echo $this->getStoreLabel('prefix') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('prefix') ?>" <?php echo $this->getFieldParams() ?> />
                    <?php else: ?>
                    <select id="<?php echo $this->getFieldId('prefix')?>" name="<?php echo $this->getFieldName('prefix')?>" title="<?php echo $this->getStoreLabel('prefix') ?>" class="<?php echo $this->helper('customer/address')->getAttributeValidationClass('prefix') ?>" <?php echo $this->getFieldParams() ?>>
                        <?php foreach ($this->getPrefixOptions() as $_option): ?>
                            <option value="<?php echo $_option?>"<?php if ($this->getObject()->getPrefix()==$_option):?> selected="selected"<?php endif; ?>><?php echo $this->__($_option)?></option>
                        <?php endforeach; ?>
                </select>
                <?php endif; ?>
            </div>
        </div>
        <?php endif; ?>
    <div class="field name-firstname">
        <label for="<?php echo $this->getFieldId('firstname')?>" class="required"><em>*</em><?php echo $this->getStoreLabel('firstname') ?></label>
        <div class="input-box">
            <input type="text" id="<?php echo $this->getFieldId('firstname')?>" name="<?php echo $this->getFieldName('firstname')?>" value="<?php echo $this->escapeHtml($this->getObject()->getFirstname()) ?>" title="<?php echo $this->getStoreLabel('firstname') ?>" maxlength="255" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('firstname') ?>" <?php echo $this->getFieldParams() ?> />
        </div>
    </div>
    <?php if ($this->showMiddlename()): ?>
        <?php $isMiddlenameRequired = $this->isMiddlenameRequired(); ?>
        <div class="field name-middlename">
            <label for="<?php echo $this->getFieldId('middlename')?>"<?php echo $isMiddlenameRequired ? ' class="required"' : '' ?>><?php echo $isMiddlenameRequired ? '<em>*</em>' : '' ?><?php echo $this->getStoreLabel('middlename') ?></label>
            <div class="input-box">
                <input type="text" id="<?php echo $this->getFieldId('middlename')?>" name="<?php echo $this->getFieldName('middlename')?>" value="<?php echo $this->escapeHtml($this->getObject()->getMiddlename()) ?>" title="<?php echo $this->getStoreLabel('middlename') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('middlename') ?>" <?php echo $this->getFieldParams() ?> />
            </div>
        </div>
        <?php endif; ?>
    <div class="field name-lastname">
        <label for="<?php echo $this->getFieldId('lastname')?>" class="required"><em>*</em><?php echo $this->getStoreLabel('lastname') ?></label>
        <div class="input-box">
            <input type="text" id="<?php echo $this->getFieldId('lastname')?>" name="<?php echo $this->getFieldName('lastname')?>" value="<?php echo $this->escapeHtml($this->getObject()->getLastname()) ?>" title="<?php echo $this->getStoreLabel('lastname') ?>" maxlength="255" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('lastname') ?>" <?php echo $this->getFieldParams() ?> />
        </div>
    </div>

    <div class="field name-lastname">
        <label for="<?php echo $this->getFieldId('lastname2')?>"><?php echo $this->getStoreLabel('lastname2') ?></label>
        <div class="input-box">
            <input type="text" id="<?php echo $this->getFieldId('lastname2')?>" name="<?php echo $this->getFieldName('lastname2')?>" value="<?php echo $this->escapeHtml($this->getObject()->getLastname2()) ?>" title="<?php echo $this->getStoreLabel('lastname2') ?>" maxlength="255" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('lastname2') ?>" <?php echo $this->getFieldParams() ?> />
        </div>
    </div>

    <?php if ($this->showSuffix()): ?>
        <div class="field name-suffix">
            <label for="<?php echo $this->getFieldId('suffix')?>"<?php if ($this->isSuffixRequired()) echo ' class="required"' ?>><?php if ($this->isSuffixRequired()) echo '<em>*</em>' ?><?php echo $this->getStoreLabel('suffix') ?></label>
            <div class="input-box">
                <?php if ($this->getSuffixOptions() === false): ?>
                    <input type="text" id="<?php echo $this->getFieldId('suffix')?>" name="<?php echo $this->getFieldName('suffix')?>" value="<?php echo $this->escapeHtml($this->getObject()->getSuffix()) ?>" title="<?php echo $this->getStoreLabel('suffix') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('suffix') ?>" <?php echo $this->getFieldParams() ?> />
                    <?php else: ?>
                    <select id="<?php echo $this->getFieldId('suffix')?>" name="<?php echo $this->getFieldName('suffix')?>" title="<?php echo $this->getStoreLabel('suffix') ?>" class="<?php echo $this->helper('customer/address')->getAttributeValidationClass('suffix') ?>" <?php echo $this->getFieldParams() ?>>
                        <?php foreach ($this->getSuffixOptions() as $_option): ?>
                            <option value="<?php echo $_option?>"<?php if ($this->getObject()->getSuffix()==$_option):?> selected="selected"<?php endif; ?>><?php echo $this->__($_option)?></option>
                        <?php endforeach; ?>
                </select>
                <?php endif; ?>
            </div>
        </div>
        <?php endif; ?>
</div>
>

您正在谈论的签出中的这些字段是地址属性,而不是客户属性。因此您需要以不同的方式加载它们。对于注册用户,您可以使用
Mage::getSingleton('customer/session')->getCustomer()->getLastname2()
,但它不会保存到您的地址,因为还没有属性

根据您希望访问lastname2的位置,您可以为实体
客户地址
报价地址
订单地址
创建相应的属性。它们的创建方式与您对
客户
的创建方式相同

$installer->addAttribute($entityName, $attribute_code,  $definition); 
但这还不是全部。要正确转换属性,您需要在module config.xml中设置转换规则。例如,请参见
Mage\u Sales
的配置。 在
全局
节点中,有一个节点
字段集
,其中包含相应的规则。有一个节点
客户地址
用于将地址属性转换为报价地址属性。在
销售转换
中,有一些规则用于将此属性转换为订单属性

因此,要在所有配置中访问属性,应如下所示:

<global>
   <fieldsets>
      <customer_address>
         <lastname2>
            <to_quote_address>*</to_quote_address>
         </lastname2>
      </customer_address>
      <sales_copy_order_billing_address>
         <lastname2>
            <to_order>*</to_order>
         </lastname2>
       <sales_copy_order_billing_address>
       <sales_copy_order_shipping_address>
         <lastname2>
            <to_order>*</to_order>
         </lastname2>
       </sales_copy_order_shipping_address>
       <sales_convert_quote_address>
           <lastname2>
              <to_order_address>*</to_order_address>
              <to_customer_address>*</to_customer_address>
           </lastname2>
       </sales_convert_quote_address>
       <sales_convert_order_address>
            <lastname2>
               <to_quote_address>*</to_quote_address>
            </lastnam2e>
       <sales_convert_order_address>
       <customer_address>
           <lastname2>
              <to_quote_address>*</to_quote_address>
           </lastname2>
       </customer_address>
   </fieldsets>
</global>

*
*
*
*
*
*
*

您正在谈论的签出中的这些字段是地址属性,而不是客户属性。因此,您需要以不同的方式加载它们。对于注册用户,您可以使用
Mage::getSingleton('customer/session')->getCustomer()->getLastname2()
,但它不会保存到您的地址,因为还没有属性

根据您希望访问lastname2的位置,您可以为实体
客户地址
报价地址
订单地址
创建相应的属性。它们的创建方式与您对
客户
的创建方式相同

$installer->addAttribute($entityName, $attribute_code,  $definition); 
但这还不是全部。要正确转换属性,您需要在module config.xml中设置转换规则。例如,请参见
Mage\u Sales
的配置。 在
全局
节点中,有一个节点
字段集
,其中包含相应的规则。有一个节点
客户地址
用于将地址属性转换为报价地址属性。在
销售转换
中,有一些规则用于将此属性转换为订单属性

因此,要在所有配置中访问属性,应如下所示:

<global>
   <fieldsets>
      <customer_address>
         <lastname2>
            <to_quote_address>*</to_quote_address>
         </lastname2>
      </customer_address>
      <sales_copy_order_billing_address>
         <lastname2>
            <to_order>*</to_order>
         </lastname2>
       <sales_copy_order_billing_address>
       <sales_copy_order_shipping_address>
         <lastname2>
            <to_order>*</to_order>
         </lastname2>
       </sales_copy_order_shipping_address>
       <sales_convert_quote_address>
           <lastname2>
              <to_order_address>*</to_order_address>
              <to_customer_address>*</to_customer_address>
           </lastname2>
       </sales_convert_quote_address>
       <sales_convert_order_address>
            <lastname2>
               <to_quote_address>*</to_quote_address>
            </lastnam2e>
       <sales_convert_order_address>
       <customer_address>
           <lastname2>
              <to_quote_address>*</to_quote_address>
           </lastname2>
       </customer_address>
   </fieldsets>
</global>

*
*
*
*
*
*
*

您正在谈论的签出中的这些字段是地址属性,而不是客户属性。因此,您需要以不同的方式加载它们。对于注册用户,您可以使用
Mage::getSingleton('customer/session')->getCustomer()->getLastname2()
,但它不会保存到您的地址,因为还没有属性

根据您希望访问lastname2的位置,您可以为实体
客户地址
报价地址
订单地址
创建相应的属性。它们的创建方式与您对
客户
的创建方式相同

$installer->addAttribute($entityName, $attribute_code,  $definition); 
但这还不是全部。要正确转换属性,您需要在module config.xml中设置转换规则。例如,请参见
Mage\u Sales
的配置。 在
全局
节点中,有一个节点
字段集
,其中包含相应的规则。有一个节点
客户地址
用于将地址属性转换为报价地址属性。在
销售转换
中,有一些规则用于将此属性转换为订单属性

因此,要在所有配置中访问属性,应如下所示:

<global>
   <fieldsets>
      <customer_address>
         <lastname2>
            <to_quote_address>*</to_quote_address>
         </lastname2>
      </customer_address>
      <sales_copy_order_billing_address>
         <lastname2>
            <to_order>*</to_order>
         </lastname2>
       <sales_copy_order_billing_address>
       <sales_copy_order_shipping_address>
         <lastname2>
            <to_order>*</to_order>
         </lastname2>
       </sales_copy_order_shipping_address>
       <sales_convert_quote_address>
           <lastname2>
              <to_order_address>*</to_order_address>
              <to_customer_address>*</to_customer_address>
           </lastname2>
       </sales_convert_quote_address>
       <sales_convert_order_address>
            <lastname2>
               <to_quote_address>*</to_quote_address>
            </lastnam2e>
       <sales_convert_order_address>
       <customer_address>
           <lastname2>
              <to_quote_address>*</to_quote_address>
           </lastname2>
       </customer_address>
   </fieldsets>
</global>

*
*
*
*
*
*
*

您正在谈论的签出中的这些字段是地址属性,而不是客户属性。因此,您需要以不同的方式加载它们。对于注册用户,您可以使用
Mage::getSingleton('customer/session')->getCustomer()->getLastname2()
,但它不会保存到您的地址,因为还没有属性

根据您希望lastname2可访问的位置,您可以创建co