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? Commented 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 Commented Mar 10, 2014 at 13:00
  • @ibrahim What is the value of the $room variable? Commented Mar 10, 2014 at 13:07
  • $room = array("3","4","5","6"); Commented Mar 10, 2014 at 13:09
  • @ibrahim. In this case you need a different kind of filter. See my updated answer. Commented Mar 10, 2014 at 13:14
  • @ibrahim. Did it work? Commented Mar 10, 2014 at 13:31

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.