В Пользовательской Сетке Кнопка Поиска Не Работает


Я создал пользовательскую сетку на стороне администратора. в сетке я создал выпадающий список. но когда я выбираю любое значение из выпадающего списка для поиска, поиск не работает...

enter image description here

C:\xampp2\htdocs\testmagento\app\code\local\Sigmasolve\Makemodel\Block\Adminhtml\Makemodel\Grid.php

<?php

class Sigmasolve_Makemodel_Block_Adminhtml_Makemodel_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
    public function __construct()
    {
        parent::__construct();
        $this->setId('makemodelGrid');
        // This is the primary key of the database
        $this->setDefaultSort('id');
        $this->setDefaultDir('ASC');
        $this->setSaveParametersInSession(true);
        $this->setUseAjax(true);
    }

    protected function _prepareMassaction()
    {
        $this->setMassactionIdField('id');
        $this->getMassactionBlock()->setFormFieldName('makemodel');

        $this->getMassactionBlock()->addItem('delete', array(
             'label'    => Mage::helper('makemodel')->__('Delete'),
             'url'      => $this->getUrl('*/*/massDelete', array('' => '')),
             'confirm'  => Mage::helper('makemodel')->__('Are you sure?')
        ));


        return $this;
    }

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

    protected function _prepareColumns()
    {
        $this->addExportType('*/*/exportCsv', Mage::helper('makemodel')->__('CSV'));
        $this->addExportType('*/*/exportXml', Mage::helper('makemodel')->__('XML'));        

        $this->addColumn('id', array(
            'header'    => Mage::helper('makemodel')->__('Id'),
            'align'     =>'right',
            'width'     => '50px',
            'index'     => 'id',  
        ));

        $this->addColumn('manufacturer', array(
            'header'    => Mage::helper('makemodel')->__('Manufacturer'),
            'align'     =>'left',
            'index'     =>'manufacturer',
            'type'      =>'options',
            'options'=> Mage::getModel('makemodel/makemodel')->getManufacturers()

        ));

        $this->addColumn('model', array(
            'header'    => Mage::helper('makemodel')->__('Model'),
            'align'     =>'left',
            'index'     => 'model',
            'type'      =>'options',
            'options'=> Mage::getModel('makemodel/makemodel')->getModels()
        ));

        $this->addColumn('capacity', array(
            'header'    => Mage::helper('makemodel')->__('Capacity'),
            'align'     =>'left',
            'index'     => 'capacity',
            'type'      =>'options',
            'options'=> Mage::getModel('makemodel/makemodel')->getCapacitys()
        ));

        $this->addColumn('year_from', array(
            'header'    => Mage::helper('makemodel')->__('Year-From'),
            'align'     =>'left',
            'index'     => 'year_from',
            'type'      =>'options',
            'options'=> Mage::getModel('makemodel/makemodel')->getYearFroms()
        ));

        $this->addColumn('year_to', array(
            'header'    => Mage::helper('makemodel')->__('Year-To'),
            'align'     =>'left',
            'index'     => 'year_to',
            'type'      =>'options',
            'options'=> Mage::getModel('makemodel/makemodel')->getYearTos()
        ));

        $this->addColumn('fuel', array(
            'header'    => Mage::helper('makemodel')->__('Fuel'),
            'align'     =>'left',
            'index'     => 'fuel',
            'type'      =>'options',
            'options'=> Mage::getModel('makemodel/makemodel')->getFuels()
        ));

        $this->addColumn('ktyp', array(
            'header'    => Mage::helper('makemodel')->__('KTYP'),
            'align'     =>'left',
            'index'     => 'ktyp',
        ));

        $this->addColumn('engine_code', array(
            'header'    => Mage::helper('makemodel')->__('Engine code'),
            'align'     =>'left',
            'index'     => 'engine_code',
        ));



        return parent::_prepareColumns();
    }



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

    public function getGridUrl()
    {
      return $this->getUrl('*/*/grid', array('_current'=>true));      
    }

}

C:\xampp2\htdocs\testmagento\app\code\local\Sigmasolve\Makemodel\Model\Makemodel.php

<?php

class Sigmasolve_Makemodel_Model_Makemodel extends Mage_Core_Model_Abstract
{
    public function _construct()
    {
        parent::_construct();
        $this->_init('makemodel/makemodel');
    }

     public function getManufacturers() {
        $manufacturersArray = array();
        $ManufacturerCollection = Mage::getModel('makemodel/makemodel')->getCollection();   
        $ManufacturerCollection->getSelect()->group('manufacturer');
        $ManufacturerCollection->setOrder('manufacturer', 'ASC');

        foreach($ManufacturerCollection->getData() as $manufacturer){
            $manufacturersArray[$manufacturer['id']] = $manufacturer['manufacturer'];
        }
        return $manufacturersArray;
    }

    /* public function getModels() {
        $modelsArray = array();
        foreach($this->getCollection() as $model){
            $modelsArray[$model->getId()] = $model->getModel();
        }
        return $modelsArray; // All Commented Code For My Refference...... 
    } */

    public function getModels() {
        $modelsArray = array();
        $ModelCollection = Mage::getModel('makemodel/makemodel')->getCollection();  
        $ModelCollection->getSelect()->group('model');
        $ModelCollection->setOrder('model', 'ASC');

        foreach($ModelCollection->getData() as $model){
            $modelsArray[$model['id']] = $model['model'];
        }
        return $modelsArray;
    }

    public function getCapacitys() {
        $capacitysArray = array();
        $CapacityCollection = Mage::getModel('makemodel/makemodel')->getCollection();   
        $CapacityCollection->getSelect()->group('capacity');
        $CapacityCollection->setOrder('capacity', 'ASC');

        foreach($CapacityCollection->getData() as $capacity){
            $capacitysArray[$capacity['id']] = $capacity['capacity'];
        }
        return $capacitysArray;
    }

    public function getYearFroms() {
        $yearfromsArray = array();
        foreach($this->getCollection() as $yearfrom){
            $yearfromsArray[$yearfrom->getId()] = $yearfrom->getYearFrom();
        }
        return $yearfromsArray;
    }

    public function getYearTos() {
        $yeartosArray = array();
        foreach($this->getCollection() as $yearto){
            $yeartosArray[$yearto->getId()] = $yearto->getYearTo();
        }
        return $yeartosArray;
    }

    public function getFuels() {
        $fuelsArray = array();
        $FuelCollection = Mage::getModel('makemodel/makemodel')->getCollection();   
        $FuelCollection->getSelect()->group('fuel');
        $FuelCollection->setOrder('fuel', 'ASC');

        foreach($FuelCollection->getData() as $fuel){
            $fuelsArray[$fuel['id']] = $fuel['fuel'];
        }
        return $fuelsArray;
    }
}
Author: R_Solanki, 2017-01-27

1 answers

Я думаю, что проблема вот в чем:

$this->addColumn('manufacturer', array(
            'header'    => Mage::helper('makemodel')->__('Manufacturer'),
            'align'     =>'left',
            'index'     =>'manufacturer',
            'type'      =>'options',
            'options'=> Mage::getModel('makemodel/makemodel')->getManufacturers()

        ));

В приведенном выше коде вы упомянули index=>manufacturer, в то время как в приведенном ниже коде вы передаете идентификатор в качестве индекса

public function getManufacturers() {
    $manufacturersArray = array();
    $ManufacturerCollection = Mage::getModel('makemodel/makemodel')->getCollection();   
    $ManufacturerCollection->getSelect()->group('manufacturer');
    $ManufacturerCollection->setOrder('manufacturer', 'ASC');

    foreach($ManufacturerCollection->getData() as $manufacturer){
        $manufacturersArray[$manufacturer['id']] = $manufacturer['manufacturer'];
    }
    return $manufacturersArray;
}

Так что просто замените на

$manufacturersArray[$manufacturer['id']] = $manufacturer['manufacturer'];

Из

$manufacturersArray[$manufacturer['manufacturer']] = $manufacturer['manufacturer'];

Я надеюсь, что это сработает.

 1
Author: Arunendra, 2017-01-27 07:06:01