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));
Solved! Go to Solution.
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.
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.
Fantastic. Worked great. Thank you very much!
Great solution
How to Load all Orders for Specified Customer's Phone Number