cancel
Showing results for 
Search instead for 
Did you mean: 

How to Load all Orders for Specified Customer ID

SOLVED
   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

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));
1 ACCEPTED SOLUTION

Accepted Solutions

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. Get Magento insight from
Magento 2 Blogs/Tutorial

View solution in original post

4 REPLIES 4

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. Get Magento insight from
Magento 2 Blogs/Tutorial

Re: How to Load all Orders for Specified Customer ID

Fantastic. Worked great. Thank you very much!

Re: How to Load all Orders for Specified Customer ID

Great solution

Re: How to Load all Orders for Specified Customer ID

How to Load all Orders for Specified Customer's Phone Number