Error : Call to undefined method addStoreFilter()
-
29-09-2020 - |
Question
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();
}
Solution
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.
OTHER TIPS
Use below code instead of $this->getCollection()->addStoreFilter($value);
$collection->addFieldToFilter('store_id',array('in',$value));
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange