如何获取magento登录客户的订单列表

时间:2012-08-28 14:35:45

标签: magento

我正在努力获取客户订购的订单号(名称)列表。我尝试过使用

Mage::getModel('sales/order')->load($order_id);

但对我不起作用?实际上我正在处理帮助台模块并尝试为门票分配订单。

4 个答案:

答案 0 :(得分:12)

好的朋友感谢您的提示,我使用此

得到了这个
require_once 'app/Mage.php'; 
      Mage::app();       

      $orders = Mage::getResourceModel('sales/order_collection')
        ->addFieldToSelect('*')
        ->addFieldToFilter('customer_id', Mage::getSingleton('customer/session')->getCustomer()->getId())
        ->addFieldToFilter('state', array('in' => Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates()))
        ->setOrder('created_at', 'desc')
    ;   

     $this->setOrders($orders); 

     foreach ($orders as $order):

    echo $order->getRealOrderId().' at '.$this->formatDate($order->getCreatedAtStoreDate()).' ('.$order->formatPrice($order->getGrandTotal()).')';

    endforeach;

答案 1 :(得分:3)

你可以试试这个:

$yourCustomerId = '123123';
$field          = 'customer_id';
$collection     = Mage::getModel("sales/order")->getCollection()
                   ->addAttributeToSelect('*')
                   ->addFieldToFilter($field, $yourCustomerId);
echo "<pre>";
print_r($collection);
echo "</pre>";

// if the customer is logged in you can add this
if(!Mage::getSingleton('customer/session')->isLoggedIn()){
    $yourCustomerId = Mage::getSingleton('customer/session')->getCustomer()->getId();
    $field          = 'customer_id';
    $collection     = Mage::getModel("sales/order")->getCollection()
                       ->addAttributeToSelect('*')
                       ->addFieldToFilter($field, $yourCustomerId);
    echo "<pre>";
    print_r($collection);
    echo "</pre>";
}

答案 2 :(得分:3)

你也可以试试这个,

$customer = Mage::getSingleton('customer/session')->getCustomer();
$email = $customer->getEmail();     

现在,您的$ email变量中有客户电子邮件地址。因此,您可以使用以下电子邮件地址轻松获取订单:

 $orderCollection = Mage::getModel(‘sales/order’)->getCollection();
 $orderCollection->addFieldToFilter(‘customer_email’, $email);

foreach ($orderCollection as $_order)
{
    echo $_order->getRealOrderId() ;
    echo $this->formatDate($_order->getCreatedAtStoreDate()) ;
    echo $_order->getShippingAddress() ? $this->escapeHtml($_order->getShippingAddress()->getName()) ;
    echo $_order->formatPrice($_order->getGrandTotal());
    echo $_order->getStatusLabel();
 }

答案 3 :(得分:1)

$ orders = Mage :: getModel('sales / order') - &gt; getCollection();

$ orders-&gt; getSelect() - &gt; where('e.customer_id ='。$ customer_id);