0

I would like to get all the product IDs from the current category page. I don't want to load the whole collection, I just need to get the product IDs from the products currently displayed.


E.g.:

  1. Customer goes on category, order is set to price descending, number of displayed products is set to 20 --> I just want to retrieve these product IDs

  2. Customer goes to page 2 --> now I just want to retrieve these product IDs

  3. Customer changes order to name asc, number of displayed products to 50 --> now I just want to retrieve these product IDs


So, getting the whole collection via

$category_id = Mage::getModel('catalog/layer')
     ->getCurrentCategory()
     ->getId();

$category = Mage::getModel('catalog/category')
     ->load($category_id);

$products = Mage::getModel('catalog/product')
    ->getCollection()
    ->addAttributeToSelect('*')
    ->addCategoryFilter($category)
    ->setOrder('price', 'ASC')
    ->load();

does not really help me, because I can't actually just the product IDs which are currently displayed to the customer. Is there some kind of way to filter and limit the collections to the values which the customer currently uses?


P.S: Get product id of current category page this guy had the same question (I guess) but didn't receive any answer, at least none, that would help me with my problem.

1

I found the solution, so nevermind, this topic can be closed

https://stackoverflow.com/questions/12317519/magento-get-current-sort-direction-with-getcollection

if( $this->getMode()!='grid' ) {
    $limit = Mage::getStoreConfig('catalog/frontend/list_per_page'); 
}
else {
    $limit = Mage::getStoreConfig('catalog/frontend/grid_per_page');
}   
  $_productCollection= Mage::getModel('catalog/product')->getCollection()
                        ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
                         ->addAttributeToSelect('sku_base')
                         ->addStoreFilter(Mage::app()->getStore()->getId())
                         ->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds())
                         ->setPage(Mage::getBlockSingleton('page/html_pager')->getCurrentPage(), $limit)
                         ->setPageSize( $limit )
                         ->setOrder(Mage::getBlockSingleton('catalog/product_list_toolbar')->getCurrentOrder(), Mage::getBlockSingleton('catalog/product_list_toolbar')->getCurrentDirection())
                         ->load();

so, it's possible to get the current category page SortOrder and the PageNumber and use it as CollectionFilter

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.