Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Filter orders by customer group id ??? 
 
lorenzo01
Sr. Member
 
Avatar
Total Posts:  221
Joined:  2007-09-06
France
 

Hello,
i try to modify orders history, in the frontend customer account : instead of viewing orders by customer_id , i want to filter orders by customer_group_id ...

Here is the file app/code/core/Mage/Sales/Block/Order/history.php :

class Mage_Sales_Block_Order_History extends Mage_Core_Block_Template
{

    
public function __construct()
    
{
        parent
::__construct();
        
$this->setTemplate('sales/order/history.phtml');

        
//TODO: add full name logic
        
$orders Mage::getResourceModel('sales/order_collection')
            ->
addAttributeToSelect('*')
            ->
joinAttribute('shipping_firstname''order_address/firstname''shipping_address_id'null'left')
            ->
joinAttribute('shipping_lastname''order_address/lastname''shipping_address_id'null'left')
 
///---> How can we filter by customer group id instead of customer id???////
            
->addAttributeToFilter('customer_id'Mage::getSingleton('customer/session')->getCustomer()->getId()) 
///--------///
            
->addAttributeToFilter('state', array('in' => Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates()))
            ->
addAttributeToSort('created_at''desc')
        ;

        
$this->setOrders($orders);

        
Mage::app()->getFrontController()->getAction()->getLayout()->getBlock('root')->setHeaderTitle(Mage::helper('sales')->__('My Orders'));
    
}

    
protected function _prepareLayout()
    
{
        parent
::_prepareLayout();

        
$pager $this->getLayout()->createBlock('page/html_pager''sales.order.history.pager')
            ->
setCollection($this->getOrders());
        
$this->setChild('pager'$pager);
        
$this->getOrders()->load();
        return 
$this;
    
}

    
public function getPagerHtml()
    
{
        
return $this->getChildHtml('pager');
    
}

    
public function getViewUrl($order)
    
{
        
return $this->getUrl('*/*/view', array('order_id' => $order->getId()));
    
}

    
public function getTrackUrl($order)
    
{
        
return $this->getUrl('*/*/track', array('order_id' => $order->getId()));
    
}

    
public function getReorderUrl($order)
    
{
        
return $this->getUrl('*/*/reorder', array('order_id' => $order->getId()));
    
}

    
public function getBackUrl()
    
{
        
return $this->getUrl('customer/account/');
    
}
}

I need some helps ....
Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
lorenzo01
Sr. Member
 
Avatar
Total Posts:  221
Joined:  2007-09-06
France
 

...when you delete this line :

->addAttributeToFilter('customer_id'Mage::getSingleton('customer/session')->getCustomer()->getId())
all orders from all customer group are listed...how can we filter orders by customer group ? I try this :
->addAttributeToFilter('customer_group_id'Mage::getSingleton('customer/session')->getCustomerGroupId())
but it is not work…
any ideas ?
thanks
 
Magento Community Magento Community
Magento Community
Magento Community
 
lorenzo01
Sr. Member
 
Avatar
Total Posts:  221
Joined:  2007-09-06
France
 

[RESOLVED]it works fine, you have to modify OrderController.php

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top