根据orderid获取address信息
代码实现:
$orderModel = Mage::getModel('sales/order')->loadByIncrementId($orderId);
$address = $orderModel->getShippingAddress();
$street = $address->getStreet();
$address_data = array(
'name' => $address->getData('lastname').$address->getData('firstname'),//姓名
'phone' => $address->getData('telephone'),//手机号
'province' => $address->getData('region'),//省
'city' => $address->getData('city'),//市
'district' => $street[0],//区
'street' => $street[1],//街道
);
原理:
public function getShippingAddress()
{
foreach ($this->getAddressesCollection() as $address) {
if ($address->getAddressType()=='shipping' && !$address->isDeleted()) {
return $address;
}
}
return false;
}
public function getAddressesCollection()
{
if (is_null($this->_addresses)) {
$this->_addresses = Mage::getResourceModel('sales/order_address_collection')
->setOrderFilter($this);
if ($this->getId()) {
foreach ($this->_addresses as $address) {
$address->setOrder($this);
}
}
}
return $this->_addresses;
}
/**
* get address street
*
* @param int $line address line index
* @return string
*/
public function getStreet($line=0)
{
$street = parent::getData('street');
if (-1 === $line) {
return $street;
} else {
$arr = is_array($street) ? $street : explode("\n", $street);
if (0 === $line || $line === null) {
return $arr;
} elseif (isset($arr[$line-1])) {
return $arr[$line-1];
} else {
return '';
}
}
}
网友评论