Grid.php 3.56 KB
<?php

/**
 * @package magento
 * @subpackage AncPricepercustomer
 *
 * @author netz.coop code[at]netz.coop
 *
 * @license http://www.gnu.org/licenses/gpl-3.0.de.html GNU GENERAL PUBLIC LICENSE VERSION 3
 * @copyright (C) 2015 netz.coop eG
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
class Anc_Pricespercustomer_Block_Adminhtml_Ncpriceslists_Grid extends Mage_Adminhtml_Block_Widget_Grid {

    public function __construct() {
        parent::__construct();

        $this->setId('pricespercustomer_ncpriceslists_grid');
        $this->setDefaultSort('entity_id');
        $this->setDefaultDir('DESC');
        $this->setSaveParametersInSession(true);
    }

    protected function _prepareCollection() {
        $collection = Mage::getModel('anc_pricespercustomer/entity')->getCollection();
        $this->setCollection($collection);
        return parent::_prepareCollection();
    }

    protected function _prepareColumns() {
        $this->addColumn('entity_id', array(
            'header' => Mage::helper('pricespercustomer/data')->__('Id'),
            'align' => 'right',
            'width' => '50px',
            'index' => 'entity_id',
        ));
        $this->addColumn('customer_id', array(
            'header' => Mage::helper('pricespercustomer/data')->__('customer id'),
            'align' => 'left',
            'index' => 'customer_id',
        ));
        $this->addColumn('product_id', array(
            'header' => Mage::helper('pricespercustomer/data')->__('product id'),
            'align' => 'left',
            'index' => 'product_id',
        ));
        $this->addColumn('price_adjustment', array(
            'header' => Mage::helper('pricespercustomer/data')->__('price adjustment'),
            'align' => 'left',
            'index' => 'price_adjustment',
        ));
        $this->addColumn('price_adjustment_type', array(
            'header' => Mage::helper('pricespercustomer/data')->__('pricetyp'),
            'align' => 'left',
            'index' => 'price_adjustment_type',
        ));
        $this->addColumn('created_at', array(
            'header' => Mage::helper('pricespercustomer/data')->__('created'),
            'align' => 'left',
            'index' => 'created_at',
        ));
        return parent::_prepareColumns();
    }

    public function getRowUrl($row) {
        return $this->getUrl('adminhtml/pricespercustomer/edit', array('id' => $row->getId()));
    }

    public function getMainButtonsHtml() {
        $html = parent::getMainButtonsHtml(); //get the parent class buttons
        $addButton = $this->getLayout()->createBlock('adminhtml/widget_button') //create the add button
                        ->setData(array(
                            'label' => Mage::helper('adminhtml')->__('create new price'),
                            'onclick' => "setLocation('" . $this->getUrl('adminhtml/pricespercustomer/new', array()) . "')",
                            'class' => 'task'
                        ))->toHtml();
        return $addButton . $html;
    }

}