>我使用 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>
现在,组合框出现在前端。但它不会保存数据。然后我在地址控制器中检查提交表单值
$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) "" }
我'卡在这一点上。
我尝试了您的代码,但它破坏了编辑页面。
该扩展在 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>
我解决了。
确保您拥有最新版本的 Hwg 属性管理器扩展。
您可以使用此链接直接下载-洋红色扩展将扩展作为 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 必须是属性代码。