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();
  }

2 Answers 2

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.

6
  • If it helps, you can mark as accepted. Commented Apr 7, 2016 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. Commented Apr 7, 2016 at 11:09
  • join collection with table manufacturer_store Commented Apr 7, 2016 at 11:11
  • but in Core. it don't need use join table. Commented Apr 7, 2016 at 11:16
  • Refer demacmedia.com/magento-commerce/… Commented Apr 7, 2016 at 11:20
0

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

$collection->addFieldToFilter('store_id',array('in',$value));
1
  • tkss, but error: Column not found: 1054 Unknown column 'store_id' in 'where clause', i had column 'store_id' in table manufactorer_store Commented Apr 7, 2016 at 10:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.