Magento的。如何在报价中获取地址

时间:2013-06-05 13:16:52

标签: magento

我尝试获取地址,客户在结帐时选择地址步骤。

我在/app/code/local/Mandarin/AddressTypeDiscount/Block/Onepage/Review.php中使用此代码:

$checkout = Mage::getSingleton('checkout/session')->getQuote();
$bilAddress = $checkout->getBillingAddress();
$mylog = print_r($bilAddress, true);
Mage::log("addres:".$mylog, null, 'mygento.log');

但是在我的日志文件中,我得到了所有客户地址的数组。

如何在地址步骤中获取所选地址? 感谢。

2 个答案:

答案 0 :(得分:10)

您的代码似乎是正确的,请参阅Get billing information in order review section of one page checkout in Magento

print_r($bilAddress, true)将打印整个对象,而不是$bilAddress->getData()

尝试

 $checkout = Mage::getSingleton('checkout/session')->getQuote();
 $billAddress = $checkout->getBillingAddress();

 Mage::log($billAddress->getData());

答案 1 :(得分:2)

对于基于订单的增量订单地址ID,

$order_id=Mage::getSingleton('checkout/session')->getLastRealOrderId();
$sales_order=Mage::getModel('sales/order')->load($order_id);
$billing_address_id=$sales_order->billing_address_id; 
$shipping_address_id=$sales_order->shipping_address_id;

对于基于客户的订单的地址实体ID,

$quote = Mage::getSingleton('checkout/session')->getQuote();
$billing_address_id=$quote->getBillingAddress()->customer_address_id;
$shipping_address_id=$quote->getShippingAddress()->customer_address_id;

Source