0

I am trying to modify the order grid in which I require the customer information like active or deactivate which is my custom customer attribute so how can I display it in grid. I have also required to display it in order view template which I have already overridden it displayed it in that file.

Note: I have modified the grid but not understanding how to display the customer `custom information. I have added the field in the grid remain is to populate it with customer data.

  • What is the exact question here? – Sukeshini Dec 2 '13 at 9:15
  • you mean to say you have one customer field/attribute called customer_activated(or Any other with "Activate/Deactivate" option values) that field/attribute you need to display in sales order grid? – Bijal Bhavsar Dec 2 '13 at 9:24
  • Yes bijal do you have any idea?? – Milople Inc Dec 2 '13 at 9:28
1

@GarthHuff

Try below class if we have customer attribute like "customer_activated"

<?php
  class [MyCompanyName]_[MyModuleName]_Block_Adminhtml_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid
  {
    protected function _preparePage()
    {

         $collection  =  $this->getCollection(); 
         $customerActivated = Mage::getSingleton('customer/customer')->getResource()->getAttribute('customer_activated'); 
         $collection->getSelect()
                ->joinLeft(
                    array('customerActivatedTb' => $customerActivated->getBackend()->getTable()),
                    'main_table.customer_id = customerActivatedTb.entity_id AND customerActivatedTb.attribute_id = '.$customerActivated->getId(). ' AND customerActivatedTb.entity_type_id = '.Mage::getSingleton('customer/customer')->getResource()->getTypeId(),
                    array('customer_activated' =>'customerActivatedTb.value') 
                );    
        return parent::_preparePage();
    }

    protected function _prepareColumns()
    { 
        $options =array(
                        0 => Mage::helper('core')->__('No'),
                        1 => Mage::helper('core')->__('Yes')
                    );
        $this->addColumn('customer_activated',
            array(
                'header'=> Mage::helper('sales')->__('Customer Activated'),
                'width' => '70px',
                'index' => 'customer_activated',
                'type'  => 'options',
                'options' => $options,
                 'filter_condition_callback' => array($this, 'customerActivatedFilter'),
            ));

        $this->addColumnsOrder('customer_activated', 'shipping_name');
        return parent::_prepareColumns();
    }

    public function customerActivatedFilter($collection, $column){
        $filterValue = $column->getFilter()->getValue();
        if(!is_null($filterValue)){
            $filterValue = trim($filterValue);
            $filterValue = preg_replace('/[\s]+/', ' ', $filterValue);

            $where   = $collection->getConnection()->quoteInto("customerActivatedTb.value = ?", $filterValue); 
            $collection->getSelect()->where($where);
        }
    }

  }
?>

I hope above code helps you!

  • Code Works fine.... i have to modified something according to my change . Btw it works great – Milople Inc Dec 2 '13 at 10:57
0

@GarthHuff you can see here Extending A Single Method Using Depends It's an example to add customer group column in sales order grid. I haven't tested it for customer activated field.

  • What if i am having my attribute in the customer_eav_attribute – Milople Inc Dec 2 '13 at 10:08
  • please checkout my above answer, it works for me :) – Bijal Bhavsar Dec 2 '13 at 10:41

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.