0

To my catalog grid ive added an extra column, which contains an attribute value, better said a color value.

Now I added a filter function with a dropdown.

This one looks like this:

protected function _colorFilter($collection, $column) {
    if (!$value = $column->getFilter()->getValue()) {
        return $this;
    }
    $field = $column->getFilterIndex() ? $column->getFilterIndex() : $column->getIndex();
    $cond = $column->getFilter()->getCondition();
    $this->getCollection()->addFieldToFilter($field, $cond["eq"]);
    return $this;
}

This works great, except it filters just for the values which are excactly the ones selected. That means: some fields have the value 140, some 76 and some 33.

When I select the value for 76, it gives me all the products wich have the attribute-/color-value 76. But what I want, are all the products wich have the value 76, 76,140, 76,33, 76,140,33.

I cannot find any way to perform this. Is this even possible with the function addFieldToFilter() ?

1

Try this (untested code).
Instead of

 $this->getCollection()->addFieldToFilter($field, $cond["eq"]);

You should alter the condition value and change the condition mode.
So.

$condition = $cond["eq"];
$this->getCollection()->addFieldToFilter($field, array('finset'=>$condition));

In case this does not work, log the value of $cond["eq"] and post it in the question.

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.