【问题标题】:Magento front end custom attribute value doesn't save the dataMagento 前端自定义属性值不保存数据
【发布时间】:2012-12-04 04:26:24
【问题描述】:

我使用 Hwg 属性管理器扩展(管理类别、客户和客户地址属性)向客户地址添加了一个自定义属性(以选择商业或住宅地址类型)。它在后端工作。但问题不适用于前端。所以我已将此代码添加到
app/design/frontend/base/default/template/customer/address/edit.phtml

<li class="fields">         
                <label for="billing:addresstype" class="required"><em>*</em><?php echo $this->__('Address Type') ?></label>
                <div class="input-box"> 
                    <select name="billingaddresstype" id="billingaddresstype">
                        <?php $collection = Mage::getResourceModel('eav/entity_attribute_option_collection');                           
                            $collection->setAttributeFilter(174);
                            $collection->setStoreFilter();
                            $collection->load();
                            $options = $collection->toOptionArray();
                            foreach ($options as $option) {
                                echo "<option value='".$option['value']."'>".$option['label']."</option>";             
                             }
                        ?>
                    </select><?php  //var_dump($options); ?>
                </div>
            </li>

现在组合框出现在前端。但它不保存数据。然后我检查 AddressController 中的提交表单值

 $addressForm = Mage::getModel('customer/form');
        $addressForm->setFormCode('customer_address_edit')
            ->setEntity($address);
        $addressData    = $addressForm->extractData($this->getRequest());

        var_dump($addressData);

        break;

它不包含我的自定义属性值。

array(11) { ["firstname"]=> string(8) "thushara" 
        ["lastname"]=> string(11) "Mannaperuma"
        ["company"]=> string(3) "flt"
        ["street"]=> array(2) 
            { [0]=> string(17) "1234 Heartwood Dr"   [1]=> string(0) "" } 
            ["city"]=> string(10) "Beltsville" 
            ["country_id"]=> string(2) "US" 
            ["region"]=> string(0) "" 
            ["region_id"]=> string(2) "31" 
            ["postcode"]=> string(5) "20705" 
            ["telephone"]=> string(12) "548-789-6548" 
            ["fax"]=> string(0) "" } 

我停留在这一点上。

【问题讨论】:

    标签: php zend-framework magento zend-form


    【解决方案1】:

    我尝试了您的代码,但它破坏了编辑页面。

    该扩展在 1.9 上适用于我,我正在使用自定义的 rwd 主题。
    这对我来说就是这样。

    我在我的主题文件夹中打开了这个文件: \magento\app\design\frontend\rwd\default\template\customer\address\edit.phtml

    在你的情况下,代码是这样的:

    <li class="field">
         <label for="adtype" class="required">
            <em>*</em>Adtype
         </label>
         <div class="input-box">
             <input type="text" name="adtype" id="adtype" value="<?php echo $this->escapeHtml($this->getAddress()->getAdtype()) ?>" />
        </div>
    </li>
    

    【讨论】:

    • 那么它是坏了还是有效?这是答案还是问题?
    【解决方案2】:

    我解决了。

    确保您拥有最新版本的 Hwg 属性管理器扩展。

    您可以使用此链接direct-download-magento-extension 以 zip 文件的形式获取扩展名。

    这是我用来将我的自定义属性添加到前端的代码。它正在正确保存数据。

    <li class="fields">
                    <?php 
                        $attribute = Mage::getModel('eav/config')->getAttribute('customer_address','adtype');
                    ?>
                    <label for="adtype" class="<?php if($attribute->getIsRequired() == true){?>required<?php } ?>"><?php if($attribute->getIsRequired() == true){?><em>*</em><?php } ?><?php echo $this->__('Address Type') ?></label>
                    <div class="input-box">
                        <select name="adtype" id="adtype" class="<?php if($attribute->getIsRequired() == true){?>required-entry<?php } ?>">
                            <?php
                                 $options = $attribute->getSource()->getAllOptions();                                
                                 foreach($options as $option){
                            ?>
                                <option value='<?php echo $option['value']?>' <?php if($this->getCustomer()->getAdtype() == $option['value']){ echo 'selected="selected"';}?>><?php echo $this->__($option['label'])?></option>
                            <?php } ?>
                        </select>
                    </div>
                </li> 
    

    adtype 是我的属性代码。字段名称和 id 必须是属性代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-25
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多