Magento – How to get all orders(and orders sum) for current customer magento-1.9 How to get all orders(and orders sum) for current customer? Best Answer create a module which will add new tab in customer tab. Step1: create Mydons_Customertab.xml at app/etc/modules/Mydons_Customertab.xml and code of this file: <?xml version="1.0"?><config> <modules> <Mydons_Customertab> <active>true</active> <codePool>local</codePool> </Mydons_Customertab> </modules> </config> Step2: create config.xml at app/code/local/Mydons/Customertab/etc/ and it code is <?xml version="1.0" ?> <config> <modules> <Mydons_Customertab> <version>0.1.0</version> </Mydons_Customertab> </modules> <adminhtml> <layout> <updates> <customertab> <file>customertab.xml</file> </customertab> </updates> </layout> </adminhtml> <global> <blocks> <customertab> <class>Mydons_Customertab_Block</class> </customertab> </blocks> </global> </config> Step3: add tab code class file location: app/code/local/Mydons/Customertab/Mydons/Customertab/Block_Adminhtml/Customer/Edit/Tab/Action.php code is <?php /** * Adminhtml customer action tab * */ class Mydons_Customertab_Block_Adminhtml_Customer_Edit_Tab_Action extends Mage_Adminhtml_Block_Template implements Mage_Adminhtml_Block_Widget_Tab_Interface { public function __construct() { $this->setTemplate('customertab/action.phtml'); } public function getCustomtabInfo(){ $customer = Mage::registry('current_customer'); $customtab='My Custom tab Action Contents Here'; return $customtab; } /** * Return Tab label * * @return string */ public function getTabLabel() { return $this->__('Action Center'); } /** * Return Tab title * * @return string */ public function getTabTitle() { return $this->__('Action Tab'); } /** * Can show tab in tabs * * @return boolean */ public function canShowTab() { $customer = Mage::registry('current_customer'); return (bool)$customer->getId(); } /** * Tab is hidden * * @return boolean */ public function isHidden() { return false; } /** * Defines after which tab, this tab should be rendered * * @return string */ public function getAfter() { return 'tags'; } } ?> and then action.phtml at design\adminhtml\default\default\template\customertab\ code is <?php $total=0; echo $customer_email=Mage::registry('current_customer')->getEmail(); $collection = Mage::getModel('sales/order') ->getCollection() // ->addFieldToFilter('status', 'complete') ->addAttributeToFilter('customer_email',array('like'=>$customer_email)); foreach($collection as $eachOrder){ echo $eachOrder->getGrandTotal(); $total+=$eachOrder->getGrandTotal(); echo $eachOrder->getId(); echo "<br/>"; } echo $total; ?> Step4: customertab.xml at app\design\adminhtml\default\default\layout\ code is <?xml version="1.0"?> <layout version="0.1.0"> <adminhtml_customer_edit> <reference name="customer_edit_tabs"> <action method="addTab"><name>customer_edit_tab_actionr</name><block>customertab/adminhtml_customer_edit_tab_action</block></action> </reference> </adminhtml_customer_edit> </layout> Related SolutionsMagento – How to get all orders id for curent customer magento is stored customer_email in order table(sales_flat_order) Now you can order list of order by using email id and but need fetch current customer email id then you can customer order list by below code: $orderCollection = Mage::getModel('sales/order')->getCollection() ->addFieldToFilter('customer_email',$customerEmail)->addFieldToSelect('*'); foreach($orderCollection as $order){ echo "<pre>"; print_r($order->getData()); echo "</pre>"; } How to Get Orders for Specific Product Attribute in Magento 1.9 $productId = 123; $orders = array(); $collection = Mage::getResourceModel('sales/order_item_collection') ->addAttributeToFilter('product_id', array('eq' => $productId)) ->load(); foreach($collection as $orderItem) { echo $orderItem->getOrder(); } Related TopicMagento – get all disabled products in current categoryMagento 1.9 Orders Collection – Get All in Current Day Range
Best Answer
create a module which will add new tab in customer tab.
Step1: create Mydons_Customertab.xml at app/etc/modules/Mydons_Customertab.xml and code of this file:
Step3: add tab code class file location:
app/code/local/Mydons/Customertab/Mydons/Customertab/Block_Adminhtml/Customer/Edit/Tab/Action.php
code is
and then action.phtml at design\adminhtml\default\default\template\customertab\ code is
Step4: customertab.xml at app\design\adminhtml\default\default\layout\
code is