0

my manufactorer manage grid can't filter at store column.

Uncaught Error: Call to undefined method Magebuzz_Manufacturer_Model_Mysql4_Manufacturer_Collection::addStoreFilter()

prepare column:

if (!Mage::app()->isSingleStoreMode()) {
  $this->addColumn('store_id', array(
    'header'     => Mage::helper('manufacturer')->__('Store View'),
    'index'      => 'store_id',
    'type'       => 'store',
    'store_all'  => TRUE,
    'store_view' => TRUE,
    'sortable'   => FALSE,
    'filter_condition_callback'
                 => array($this, '_filterStoreCondition'),
  ));
}

function:

  protected function _filterStoreCondition($collection, $column)
  {
    if(!$value = $column->getFilter()->getValue()) {
      return;
    }
    $this->getCollection()->addStoreFilter($value);
  }

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

Use below code for store filter

protected function _filterStoreCondition($collection, $column){
    $array = explode(",",$column->getFilter()->getValue());
    if(is_array($array)){
        foreach($array as $child){
            if (!$value = $child) {
                return;
            }
             $collection->addFieldToFilter('store_id',array(
                        array('finset'=> array('0')),
                        array('finset'=> array($value)),
                    ));
            return $this;
        }
    }
    else{
        if (!$value = $column->getFilter()->getValue()) {
            return;
        }
        $collection->addFieldToFilter('store_id',array(
                    array('finset'=> array('0')),
                    array('finset'=> array($value)),
                ));
        return $this;
    }
 }

It helpful to you.

  • If it helps, you can mark as accepted. – Prashant Valanda Apr 7 '16 at 10:55
  • sr. error: Column not found: 1054 Unknown column 'store_id' in 'where clause', but i had column 'store_id' in table manufacturer_store. i create 2 table: manufaturer and manufacturer-store with manufacturer_id is foreign key. but can't find 'store_id' column. – Tùng Mạc Sơn Apr 7 '16 at 11:09
  • join collection with table manufacturer_store – Prashant Valanda Apr 7 '16 at 11:11
  • but in Core. it don't need use join table. – Tùng Mạc Sơn Apr 7 '16 at 11:16
0

Use below code instead of $this->getCollection()->addStoreFilter($value);

$collection->addFieldToFilter('store_id',array('in',$value));
  • tkss, but error: Column not found: 1054 Unknown column 'store_id' in 'where clause', i had column 'store_id' in table manufactorer_store – Tùng Mạc Sơn Apr 7 '16 at 10:32

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.