1

How to get all orders(and orders sum) for current customer?enter image description here

  • are you want all order total and it total no of order? – Amit Bera Oct 29 '14 at 11:55
  • I want to create information for orders and orders-price for customer(in manage castomers). When I choose some of them I want to see all orders(id) and price(for this order) – Guest Oct 29 '14 at 12:01
  • on a side note, you could download Skitch which is a free screenshot program that allows you to draw and write text in a more professional way on your screenshots. – Julien Lachal Oct 29 '14 at 13:44
2

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>
  • )) I`ve done! But what is after this code in action.phtml – Guest Oct 29 '14 at 12:18
  • give some times ,i will give u total code – Amit Bera Oct 29 '14 at 12:19
  • Amit are you still here? – Guest Oct 29 '14 at 12:51
  • Give me 1/2hrs. i have a task – Amit Bera Oct 29 '14 at 13:19
0

Try something like this

$customer_email=Mage::getSingleton('customer/session')->getCustomer()->getEmail();
$collection = Mage::getModel('sales/order')
            ->getCollection()
            ->addFieldToFilter('status', 'complete')
            ->addAttributeToFilter('customer_email',array('like'=>$customer_email));

use some foreach to display result and sum it

  • did u tried this ??? – Dhanasekar Oct 29 '14 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.