2

我有这个代码:

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

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

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

4

2 回答 2

10

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

$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');
于 2012-10-08T12:41:28.487 回答
1

通过订单 ID 获取运输详细信息

$order_id = 2314; //use your own order id

$order = Mage::getModel("sales/order")->load($order_id); //load order by order id

$shipping_address = $order->getShippingAddress();

echo $shipping_address->getTelephone();

echo $shipping_address->getPostcode(); //use print_r($shipping_address->getData()); to get all the available elements of the object
于 2015-03-26T11:34:59.803 回答