<?php
require_once 'app/Mage.php';
Mage::app('default');
Mage::getSingleton("core/session", array("name" => "frontend"));
?>
<?php
/* create functions */
function isCustomerHasOrders($customerId, $grandTotal = null)
{
$orderCollection = $this->getCustomerOrderCollection($customerId, $grandTotal);
return (bool)$orderCollection->getSize();
}
function getCustomerOrderCollection($customerId, $grandTotal = null)
{
$orderCollection = Mage::getResourceModel('sales/order_collection')
->addFieldToSelect('*')
->addFieldToFilter('customer_id', $customerId)
->addFieldToFilter('state', array('in' => Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates()))
->setOrder('created_at', 'desc')
;
if ($grandTotal && $grandTotal > 0) {
$orderCollection->addFieldToFilter('base_grand_total', array ('gteq' => $grandTotal));
}
return $orderCollection;
}
/* end function */
// start code here
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
$customer = Mage::getSingleton('customer/session')->getCustomer();
$customerId = $customer->getId();
$ordercol=getCustomerOrderCollection($customerId, $grandTotal = null);
$countorder= count($ordercol);
if($countorder > 0)
{
$i=0;
foreach($ordercol as $orderdet)
{
$order = Mage::getModel('sales/order')->load($orderdet->getId());
$orderid=$orderdet->getId();
// get order id or order number
$ordernumber=$order->getIncrementId();
$orderdate1=$order->getCreatedAtStoreDate();
$orderdate2 = str_replace(",","",$orderdate1);
$orderdate=trim($orderdate2,'');
//echo date(strtotime($order->getCreatedAtStoreDate());
//get order total value:
$orderTotalValue = number_format ($order->getGrandTotal(), 2, '.' , $thousands_sep = '');
$payment_method_code = $order->getPayment()->getMethodInstance()->getCode();
$status= $order->getStatusLabel();
$firstname = $order->getCustomerFirstname();
$currency_code = Mage::app()->getStore()->getCurrentCurrencyCode();
$lastname = $order->getCustomerLastname();
// item list
$orderItems = $order->getItemsCollection();
$j=0;
foreach ($orderItems as $item){
$productid = $item->product_id;
$productsku = $item->sku;
$productprice = $item->getPrice();
$productname = $item->getName();
$productqty = $item->getData('qty_ordered');
//echo $productsubtotal = $item->getSubTotal();
$productsubtotal = $productqty * $productprice;
// get product image
$productimg2 = Mage::getModel('catalog/product')->load($item->product_id);
$productMediaConfig = Mage::getModel('catalog/product_media_config');
$prodimgthumbnailUrl = $productMediaConfig->getMediaUrl($productimg2->getThumbnail());
$itemdetail[$j]=array("productId"=>$productid,"productName"=>$productname,"productSku"=>$productsku,"productQty"=>$productqty,"productPrice"=>$productprice,"productSubTotal"=>$productsubtotal,"prodImgUrl" =>$prodimgthumbnailUrl);
$j++;
}
$orderlist[$i]=array("orderId"=>$orderid,"orderNumber"=>$ordernumber,"orderDate"=>$orderdate,"shipTo"=>$firstname.''.$lastname,"orderTotal"=>$orderTotalValue,"currency"=>$currency_code,"itemList"=>$itemdetail);
$i++;
}
$data['responseCode']='1';
$data['msg']='successfull';
$data['orderListResponse']=$orderlist;
}
else
{
$data['responseCode']='0';
$data['msg']='No Order Found';
}
}
else
{
$data['responseCode']='0';
$data['msg']='Please Login First';
}
$data2=json_encode($data);
echo $data2;
?>
EmoticonEmoticon