I want to get all items from the product compare list, but only for a certain visitor. This is what I tried:
$_productCollection = Mage::helper('catalog/product_compare')->getItemCollection();
$test = $_productCollection->addFieldToFilter('visitor_id', 2)->getItems();
This should return nothing, because in my catalog_compare_item table is no row for visitor_id 2. But it returns everything no matter if I use a filter or not. Whats the correct way of doing that?
Thanks!
->getItems()
part and complete your code with:$_productCollection->count(); echo $_productCollection->getSelect()->__toString();
and see what's happening in the SQL query, it might lead you to the solution$_productCollection->count()
it gives you 1? That is some weird stuff. What is you loop through thegetItems()
? Is there something out of the ordinary in what it gives you?$collection = Mage::helper('catalog/product_compare')->getItemCollection(); $collection->addFieldToFilter('visitor_id', 2); $sql = $collection->getSelect()->__toString(); $count = $collection->count(); foreach($collection as $product) { $id = $product->getId(); // thats the id from the product with visitor_id 1 }