如何通过送货地址ID获取送货地址?


9

我有订单对象。由此,我可以获得送货地址ID。谁能建议如何通过送货地址ID得出送货地址?

Answers:


16

您可以使用order_address对象获取送货地址:

 $address = Mage::getModel('sales/order_address')->load($shippingId);
// $shippingId is the id you get from order object.
$custName = $address->getName();
$custAddr = $address->getStreetFull();
$region = $address->getRegion();
$country = $address->getCountry();

或使用

print_r(get_class_methods($address)); 

查看可以在地址对象($ address)上使用的方法。

希望它能解决您的问题:)


7

要从订单对象获取地址,您可以简单地执行 $order->getShippingAddress()

假设

$order_id = 123; // put your order id here
$order = Mage::getModel('sales/order')->load($order_id);

然后

$address = $order->getShippingAddress();
$custName = $address->getName();
$custAddr = $address->getStreetFull();
$region = $address->getRegion();
$country = $address->getCountry();

几个月前我已经解决了我的问题。即使感谢您的回应。+1
Sukeshini

$address使用$address = $order->getShippingAddress()时为空,但使用时$address = Mage::getModel('sales/order_address')->load($shippingId);返回地址
Pradeep Singh

2

Shathish给了您一个不错且正确的答案。

但是,您可以使用单例方法和查询:

$shimnetId = "1"; // use your shipment id: 

$read = Mage::getSingleton('core/resource')->getConnection('core_read');

$query = "SELECT * FROM sales_flat_order_address WHERE entity_id='".$shipmentId."'";

$results = $read->fetchAll($query);

var_dump($results);

sales_flat_order_address 包含帐单地址和送货地址。

希望它对您有用。


2
我没有测试您的解决方案。但是我认为按照Magento的开发方式进行开发比在源代码中使用直接SQL查询更好。无论如何,感谢您的建议。谢谢
Sukeshini
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.