cancel
Showing results for 
Search instead for 
Did you mean: 

Get all products of a category by its ID and the ID of a website

SOLVED

Get all products of a category by its ID and the ID of a website

I am trying to obtain a list of products inside a category searching by the category ID and the website ID.

 

Right now I have all the products of the category correctly, but the website filter isn't working, I selected a product to be in for example website Peru, but not Venezuela, but it doesn't respect that and it is always returning the product.

 

First I am obtaining the website id based on its code, which gives me the right value. I am using setStoreId then.

 

This is the part of code:

 

 

$currentCountry = Mage::getModel('core/store')->loadConfig('ve')->getId();
$productData = Mage::getModel('catalog/category')->load($category->getId())
                                                 ->getProductCollection()
                                                 ->setStoreId($currentCountry)
                                                 ->addAttributeToSelect('*')
                                                 ->addAttributeToFilter('status', 1)
                                                 ->addAttributeToFilter('visibility', 4)

 

 

In the product page, in the Websites submenu, I have checked Peru, but not Venezuela.

2 REPLIES

Re: Get all products of a category by its ID and the ID of a website

You probably want to add a store filter to that collection before using it, like so:

 

$productData->addStoreFilter($currentCountry);

That should filter the collection based on the selected website.

Problem solved? Click Accept as Solution!
www.iweb.co.uk | Magento Small Business Partner

Re: Get all products of a category by its ID and the ID of a website

Thanks, that solved my problem Smiley Happy