gpt4 book ai didi

magento - 如何在 Magento 中获取送货地址和订单状态?

转载 作者:行者123 更新时间:2023-12-01 22:25:00 25 4
gpt4 key购买 nike

我有这个代码:

$session = Mage::getSingleton('checkout/session');

foreach ($session->getQuote()->getAllItems() as $item) {
echo $item->getName();
echo $item->getId();
echo Mage::helper('core')->formatPrice($item->getPrice());
}

但我想获取我订购的每件商品的送货地址和订单状态。

最佳答案

获取当前登录客户的所有订单

$customerId = Mage::getSingleton('customer/session')->getCustomer()->getId();

$_orders = Mage::getModel("sales/order")->getCollection()
->addAttributeToSelect('*')
->addFieldToFilter('customer_id', $customerId);
/* to get last order only -- uncomment
->setOrder('created_at', Varien_Data_Collection_Db::SORT_ORDER_DESC)
->setPageSize(1);
*/


foreach($_orders as $order) {
foreach($order->getAllItems() as $item){
echo $item->getName();
echo $item->getId();
echo Mage::helper('core')->formatPrice($item->getPrice());
}

//display status
echo $order->getStatusLabel();
//display shipping address
print_r($order->getShippingAddress()->getData());
}

通过 order_id 获取特定订单的订单信息

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

if(!$_order->getID()){
echo 'Order not found.';
}
else{

//display shipping address
print_r($_order->getShippingAddress()->getData());

foreach($_order->getAllItems() as $order) {
echo $order->getName();
echo $order->getId();
echo Mage::helper('core')->formatPrice($order->getPrice());
echo $order->getStatusLabel();

}
}

此代码获取客户购物车(因此这是在您下订单之前)

$session = Mage::getSingleton('checkout/session');

关于magento - 如何在 Magento 中获取送货地址和订单状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12781821/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com