How to properly add a shipping_description column in magento order grid?

后端 未结 3 1087
不思量自难忘°
不思量自难忘° 2021-01-24 21:51

There are many tutorials and suggestions including installing a custom extensions etc.

I\'ve added the shipping_description fine based on various tips and tricks by modi

3条回答
  •  [愿得一人]
    2021-01-24 22:42

    I guess what you are doing is adding the "shipping_description" field in the collection but, i can help you out by an easy one. i.e using renderer in the grid. This is a lot easier in my view.

    After you override the grid block for order(Override the block is a good practice) add this to your _prepareColumn() function

     $this->addColumn('shipping_description', array(
                'header'=> Mage::helper('sales')->__('Shipping Description'),
                'index' => 'shipping_description',
                'filter' => false,
                'sortable' => false,
                'renderer' => 'PackageName_ModuleName_Block_Adminhtml_Sales_Order_Renderer_Shipping',
            )); 
    

    Here you can see the renderer this points to the class "PackageName_ModuleName_Block_Adminhtml_Sales_Order_Renderer_Shipping". Now,go on and create folder Named "Renderer" in the above mentioned path and inside that folder create "Shipping.php" file.

    getData('entity_id');
    
            $customer = Mage::getModel('customer/customer')->load($customerId);
            $customerTotals = Mage::getResourceModel('sales/sale_collection')
                 ->setCustomerFilter($customer)
                 ->load()
                 ->getTotals();
            $customerLifetimeSales = $customerTotals->getLifetime();
            //$customerNumberOfOrders = $customerTotals->getNumOrders();
           echo Mage::helper('core')->currency($customerLifetimeSales); 
        }
    }
    

    In above class i override the customer module to determine the lifetime sales of the customer. In this function you can do whatever operation and what you "return" or "echo" in this file will be displayed in the grid.

    In this way you don't need to join tables in the collection.Just call the model that gets you shipping description and print it.That's it.It will make lot easier

    Hope this will help.

提交回复
热议问题