Get Order List By Customer Id using Magento programmatically

Get Order List By Customer Id using Magento programmatically

In this Post We Will Explain About is Get Order List By Customer Id using Magento programmatically With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Get customer order count in Magento Example

In this post we will show you Best way to implement magento 2 get orders by customer id, hear for How to get order list for logged in customer in magento with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Magento Get Order List By Customer Id

Hear is the simple source code for Magento Get Order List simple display By Customer Id in Magento, You can use this root file out-side of PHP using magento(on first main root of magento).

 "frontend")); 
 
// create functions 
function isCustomerHasOrders($id_Cust, $total_grand = null)
{
    $getgetorderCollection = $this->getCustomerOrder($id_Cust, $total_grand);
    return (bool)$getorderCollection->getSize();
}
 
function getCustomerOrder($id_Cust, $total_grand = null)
{   
    $getorderCollection = Mage::getResourceModel('sales/order_collection')
        ->addFieldToSelect('*')
        ->addFieldToFilter('id_Cust', $id_Cust)
        ->addFieldToFilter('state', array('in' => Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates()))
        ->setOrder('created_at', 'desc');
    if ($total_grand && $total_grand > 0) 
    {
        $getorderCollection->addFieldToFilter('base_grand_total', array ('gteq' => $total_grand));
    }
    return $getorderCollection;
}
// first magento end function 
 
// start source code here
 
if (Mage::getSingleton('customer/session')->isLoggedIn()) 
{  
    $allcust_info = Mage::getSingleton('customer/session')->getCustomer();
    $id_Cust = $allcust_info->getId();
    $mycol_order = getCustomerOrder($id_Cust, $total_grand = null);
    $countorder = count($mycol_order);
    if($countorder > 0)
    {
        $i=0;
        foreach($mycol_order as $liveOrder_Value)
        {
            $liveOrder   = Mage::getModel('sales/order')->load($liveOrder_Value->getId());
            $orderid = $liveOrder_Value->getId();
 
            // Now we can show get order id or order number
            $ordernumber = $liveOrder->getIncrementId();
 
            $orderdate1 = $liveOrder->getCreatedAtStoreDate();
 
            $orderdate2 = str_replace(",","",$orderdate1);
            $orderdate = trim($orderdate2,'');
 
            //echo date(strtotime($liveOrder->getCreatedAtStoreDate()); 
 
            //Now we can show get liveOrder total value:
            $totalOrderVal = number_format ($liveOrder->getGrandTotal(), 2, '.' , $thousands_sep = '');
 
            $payment_method_code = $liveOrder->getPayment()->getMethodInstance()->getCode();
 
            $status= $liveOrder->getStatusLabel();
 
            $cust_fname = $liveOrder->getCustomerFirstname();
 
            $code_curr = Mage::app()->getStore()->getCurrentCurrencyCode(); 
            $cust_lname = $liveOrder->getCustomerLastname();
 
            // Now we can show liveItem list
            $orderItems = $liveOrder->getItemsCollection();
            $j = 0;
            foreach ($orderItems as $liveItem)
            {
                $productid    = $liveItem->product_id;
                $productsku   = $liveItem->sku;
                $productprice = $liveItem->getPrice();
                $productname  = $liveItem->getName();
                $productqty   = $liveItem->getData('qty_ordered');
                //echo $productsubtotal = $liveItem->getSubTotal();
                $productsubtotal = $productqty * $productprice;
 
                // Now we can show get product image 
                $productimg2 = Mage::getModel('catalog/product')->load($liveItem->product_id);
                $productMediaConfig = Mage::getModel('catalog/product_media_config');
                $prodimgthumbnailUrl = $productMediaConfig->getMediaUrl($productimg2->getThumbnail());
                $ItemInfo[$j] = array(
                        "productId" => $productid,   
                        "productName" => $productname,   
                        "productSku" => $productsku,
                        "productQty" => $productqty,
                        "productPrice" => $productprice,
                        "productSubTotal" => $productsubtotal,
                        "prodImgUrl" => $prodimgthumbnailUrl
                    );
                $j++; 
            }
            $listOf_order[$i] = array(
                    "orderId" => $orderid,   
                    "orderNumber" => $ordernumber,
                    "orderDate" => $orderdate,
                    "shipTo" => $cust_fname.''.$cust_lname,
                    "orderTotal" => $totalOrderVal,
                    "currency" => $code_curr,
                    "itemList" => $ItemInfo
                );
            $i++;
        }
        $data['responseCode'] = '1';
        $data['msg'] = 'successfull';
        $data['orderListResponse'] = $listOf_order;
    }
    else
    {
		//if countorder no so display
        $data['responseCode'] = '0';
        $data['msg'] = 'Sorry .....No Data Found';
    }
}
else
{
	//magento authentication error
    $data['responseCode'] = '0';
    $data['msg'] = 'First of all simple You must Login';
}

//display all the json_encode data
$result = json_encode($data);
echo $result;
?>

You are Most welcome in my youtube Channel Please subscribe my channel. and give me FeedBack.
More Details……
Angularjs Example

Example

I hope you have Got What is Logged In User Order List in magento programmatically And how it works.I would Like to have FeedBack From My Blog(Pakainfo.com) readers.Your Valuable FeedBack,Any Question,or any Comments about This Article(Pakainfo.com) Are Most Always Welcome.

Leave a Comment