我正在努力獲取客戶訂購的訂單號(名稱)列表。我一直在使用如何獲得magento中登錄客戶的訂單列表
Mage::getModel('sales/order')->load($order_id);
嘗試,但並沒有對我的作品?其實我正在幫助臺模塊上工作,並嘗試將訂單分配給票據。
我正在努力獲取客戶訂購的訂單號(名稱)列表。我一直在使用如何獲得magento中登錄客戶的訂單列表
Mage::getModel('sales/order')->load($order_id);
嘗試,但並沒有對我的作品?其實我正在幫助臺模塊上工作,並嘗試將訂單分配給票據。
好的朋友感謝您的提示,我用這個
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;
$ orders = Mage :: getModel('sales/order') - > getCollection();
$ orders-> getSelect() - > where('e.customer_id ='。$ customer_id);
你可以試試這個:
$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>";
}
你可以試試這個也得到了這個,
$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();
}