1

I am looking for function which is similar to getLoadedProductCollection and which retrieves all products from this category with selected filters, not only those I can see on current page like getLoadedProductCollection do.

I've tried to do:

$productCollection = Mage::getModel('catalog/product')->getCollection()
                         ->addAttributeToSelect('sku')
                         ->addAttributeToSelect('collection_price')
                         ->addAttributeToSelect('price')
                         ->addAttributeToSelect('special_price')
                         ->addAttributeToSelect('name');

But it retrieves all products from whole store, not only products from current category with selected filters. Any ideas?

1 Answer 1

0

You can filter product collection by any category using below code.

$cat_id = 'Your category id here';

    $ProductCollection = Mage::getResourceModel('catalog/product_collection')
    ->joinField('category_id','catalog/category_product','category_id','product_id=entity_id',null,'left')
    ->addAttributeToFilter('category_id', array('in' => $cat_id))
    ->addAttributeToSelect('*');

You can also use below code to get product of specific category.

$collection = Mage::getModel('catalog/category')
                    ->load(cat_id)
                    ->getProductCollection();
3
  • Nice, it works. Any ideas how to apply current filters to this function?
    – Mr. AP
    Commented Jan 12, 2017 at 12:06
  • You can use registry to get current category Mage::registry('current_category')->getId();
    – Kul
    Commented Jan 12, 2017 at 12:13
  • @Mr.AP hope its work for you? for product page there will be multiple category so you need to get array of categories assign to product
    – Kul
    Commented Jan 13, 2017 at 9:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.