cancel
Showing results for 
Search instead for 
Did you mean: 

How to Load all Orders for Specified Customer ID

SOLVED

How to Load all Orders for Specified Customer ID

How do we load all orders for a specific customer in Magento?

This is how we did in in Magento 1.

Thank you.

 

$orderCollection = Mage::getModel('sales/order')->getCollection(); 
$lastyear = date('Y-m-d', strtotime("-1 year"));
$orders = $orderCollection->addAttributeToFilter("customer_id", 123456)->addAttributeToFilter('state', 'complete')->addAttributeToFilter('created_at', array('gteq'  => $lastyear));
2 REPLIES

Re: How to Load all Orders for Specified Customer ID

You can call Specific customer order based on customer id from below way,

 

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$lastyear = date('Y-m-d', strtotime("-1 year"));
$orderCollection = $objectManager->create('\Magento\Sales\Model\ResourceModel\Order\Collection');
$orderCollection->addAttributeToFilter('customer_id',123456)
	        ->addAttributeToFilter('status','complete')
	        ->addAttributeToFilter('created_at', array('gteq'  => $lastyear))->load();

echo "<pre>";print_r($orderCollection->getData()); exit;	

if issue solved,Click kudos/Accept as solutions.

If Issue Solved, Click Kudos/Accept As solutions.

Re: How to Load all Orders for Specified Customer ID

Fantastic. Worked great. Thank you very much!