2

Am using Magento 1.9.3. Here am creating a custom order gird in admin->sales->order table, those columns following

  1. Coupon Code
  2. Sliver Exchange Declaration

In Coupon Code is used to showing coupon_code name for the order.

And Sliver Exchange Declaration is showing some link

for the more info for following image enter image description here

My query i would like to show Silver Exchange Declaration when coupon code = SE50 otherwise don't show the Sliver Exchange Declaration

My codes app\code\core\Mage\Adminhtml\Block\Sales\Order\Grid.php

protected function _prepareCollection()
    {
        $collection = Mage::getResourceModel($this->_getCollectionClass());
        $collection->getSelect()->joinLeft(array('order' => Mage::getModel('core/resource')->getTableName('sales/order')),
        'order.entity_id=main_table.entity_id',array('silver_exchange' => 'coupon_code'));
        $this->setCollection($collection);
        return parent::_prepareCollection();
    }

In protected function _prepareColumns()

$this->addColumn('coupon_code', array(
          'header'    => Mage::helper('sales')->__('Coupon Code'),
          'align'     =>'left',
          'width'     => '50px',
          'index'     => 'silver_exchange',
          'filter'    => false,
          'sortable'  => false,
        )); //code for coupon_code



$this->addColumn('silver_exchange', array(
                'header' => Mage::helper('sales')->__('Sliver Exchange Declaration'),
                'index' => 'silver_exchange',
                //'filter_index' => 'payment.method',
                //'type'  => 'options',
                //'options' => $silver_exchange,
                'width' => '170px',
                'filter' => false,
                'sortable'  => false,
                'type'      => 'action',
                'actions'   => array(
                        array(
                            'caption' => Mage::helper('sales')->__('Silver Exchange Declaration'),
                            'url'     => array('base'=>'*/sales_order/declaration'),
                            'field'   => 'order_id',
                            'data-column' => 'action',
                        )
                    ),
                )); //code for Silver Exchange Declaration

query is if coupon code is SE50 showing Silver Exchange Declaration link

3

You can create a renderer for this as follow.

app\code\core\Mage\Adminhtml\Block\Sales\Order\Silverexchange.php

<?php
class Mage_Adminhtml_Block_Sales_Order_Silverexchange extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
    public function render(Varien_Object $row)
    {    
        $value =  $row->getData($this->getColumn()->getIndex());
        $order = Mage::getModel('sales/order')->load($value);
        $coupon_code = $order->getCouponCode();

        if($coupon_code == 'SE50') {
            $text = '<a href="'.Mage::helper('adminhtml')->getUrl('*/*/declaration', array("order_id" => $row->getId())).'">Silver Exchange Declaration</a>';
        } else {
            $text = '';
        }

        return $text; 
    }
}
?>

And in app\code\core\Mage\Adminhtml\Block\Sales\Order\Grid.php change following code under function protected function _prepareColumns()

$this->addColumn('silver_exchange', array(
    'header' => Mage::helper('sales')->__('Silver Exchange Declaration'),
    'index' => 'entity_id',
    'width' => '170px',
    'filter' => false,
    'sortable'  => false,
    'renderer'  => 'Mage_Adminhtml_Block_Sales_Order_Silverexchange',
));
  • Hi Lokesh Thanks for your answer. Sorry to say this nothing showing in the column for info this see this link ibb.co/cFnoP5 – Ramesh S Aug 28 '17 at 13:00
  • i think error in if($coupon_code == 'SE50') actually $coupon_code values not showing in Silverexchange.php. am using print_r($coupon_code); for testing – Ramesh S Aug 28 '17 at 13:33
  • 1
    Hi Ramesh, I have edited the answer. Change index of 'silver_exchange' to 'entity_id'. – Lokesh Naik Aug 28 '17 at 13:42
  • Hi it's working Bro – Ramesh S Aug 28 '17 at 13:43
  • Bro if you free come this chat room chat.stackexchange.com/rooms/64544/magento-be – Ramesh S Aug 28 '17 at 13:48

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.