1

I have a page that I getting all products with some attributes. (room, color, size, price)

I change "Catalog Input Type for Store Owner" for room attribute on database. It was dropdown, now multiselect.

After this change the page returning null. Is anyone know why?

It's the part of code:

$room = $_POST['room'];
$collection = Mage::getResourceModel('reports/product_collection')
    ->addAttributeToSelect('*')
    //->addAttributeToFilter('color', 7)
    ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id=entity_id', null, 'left')
    ->addAttributeToFilter('category_id', array('in' => $catID))
    ->addAttributeToFilter('size', array('in'=>$size))
    ->addAttributeToFilter('room', array('in'=>$room))
    ->addStoreFilter()
    ->setOrder('created_at', 'desc')
    ->setPage($pageNumber, $productPerPage)
    ->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());
    //$collection->getSelect()->order('rand()');
    //$collection->getSelect()->limit(12);
    $collection->addAttributeToFilter('price', array('gt'=>$priceL));
    $collection->addAttributeToFilter('price', array('lt'=>$priceG));

Edit: If I remove "->addAttributeToFilter('room', array('in'=>$room))" line, it's perfectly working.

1
  • are you using a flat catalog? May 22, 2014 at 18:07

1 Answer 1

2

I assume that $room is one of the values from the available options of the room attribute.
Since the multiselects are saved in the db as a string with values concatenated by comma (1,4,5,6,7,15), you need to filter like this:

->addAttributeToFilter('room', array('finset'=>$room));

If the $room variable is an array you need to apply a multiple FIND_IN_SET filter with or condition.
See an example for this kind of filter in here

9
  • returned this error: pastebin.com/jk6Frg6L Mar 10, 2014 at 13:00
  • @ibrahim What is the value of the $room variable?
    – Marius
    Mar 10, 2014 at 13:07
  • $room = array("3","4","5","6"); Mar 10, 2014 at 13:09
  • @ibrahim. In this case you need a different kind of filter. See my updated answer.
    – Marius
    Mar 10, 2014 at 13:14
  • @ibrahim. Did it work?
    – Marius
    Mar 10, 2014 at 13:31

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.