如何获得订单列表为登录用户在Magento(How to get order list for lo

2019-09-21 19:38发布

我努力让顾客订购订单编号(名称)的列表。 我已经尝试使用

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

但并没有对我的作品? 其实我的工作帮助台模块上,并试图订单分配给票。

Answer 1:

好,谢谢你的提示朋友们,我通过使用该得到这个

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;


Answer 2:

你可以试试这个:

$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>";
}


Answer 3:

你可以试试这个为好,

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

现在,你在$电子邮件变量有顾客的电子邮件地址。 所以,你可以使用这个电子邮件地址如下轻松获得指令集:

 $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();
 }


Answer 4:

$订单=法师:: getModel( '销售/订单') - > getCollection();

$订单 - > getSelect() - >其中( 'e.customer_id =' $ CUSTOMER_ID);



文章来源: How to get order list for logged in customer in magento
标签: magento