I need to get all orders id for current customer in my custom customer tab!
I'm using: $orders = Mage::getModel('sales/order')->getCollection();
This is my Tab where I want to add Order No and Sum:
adminhtmlcustomergridmagento-1.9orders
I need to get all orders id for current customer in my custom customer tab!
I'm using: $orders = Mage::getModel('sales/order')->getCollection();
This is my Tab where I want to add Order No and Sum:
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>
user1618341,According magento an order can place
from one store
,Magento is save order store id at sales_flat_order,sales_flat_grid order
.
At your collection you need get store_id.Also need rectify collection query,Please use * instead of some field
<?php
try {
$orders = Mage::getModel('sales/order')->getCollection()
->addFieldToFilter(
'status',
array(
'nin' => array('complete', 'canceled', 'processing', 'holded', 'fraud'),
'in' => 'pending',
))
->addAttributeToSelect('store_id')
->addAttributeToSelect('status');
}
catch (Mage_Core_Exception $e) {
}
I have put the condition to skip create shipment for one store view[if($eachorder->getData('store_id')!=='YOUSKIPSTOREID'):]
see code:
try {
foreach ($orders as $eachorder) {
$order = Mage::getModel("sales/order")->load($eachorder->getId());
if (!$order->canInvoice()) {
Mage::throwException(Mage::helper('core')->__('Cannot create an invoice.'));
}
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
if (!$invoice->getTotalQty()) {
Mage::throwException(Mage::helper('core')->__('Cannot create an invoice without products.'));
}
$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
$invoice->register();
$transactionSave = Mage::getModel('core/resource_transaction')
->addObject($invoice)
->addObject($invoice->getOrder());
$transactionSave->save();
/* put code for skip for one store */
if($eachorder->getData('store_id')!=='YOUSKIPSTOREID'):
$shipment = $order->prepareShipment();
if ($shipment) {
$shipment->register();
$order->setIsInProcess(true);
$transaction_save = Mage::getModel('core/resource_transaction')
->addObject($shipment)
->addObject($shipment->getOrder())
->save();
} else {
throw new Exception("Cant get shipment");
}
endif;
$order->setState(Mage_Sales_Model_Order::STATE_COMPLETE);
$order->save();
}
}catch (Mage_Core_Exception $e) {
}
If you getting the issues for create invoice and shipment,Please see my Blog:
Best Answer
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: