Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7589611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:12:17+00:00 2026-05-30T20:12:17+00:00

I have a category called New which has 14 products within it. I’m using

  • 0

I have a category called “New” which has 14 products within it.

I’m using Mage::getModel('catalog/category')->load(6); to load this category (6 is the ID within the admin).

If I call echo $category->getProductCount(); it correctly displays 14 (the amount of products in this category).

Now, I’m grabbing the products from the category with

$products = Mage::getModel('catalog/product')
    ->setStoreId( Mage::app()->getStore()->getId() )
    ->getCollection()
    ->addAttributeToFilter('visibility', $visibility)
    ->addCategoryFilter($category)
    ->addAttributeToSelect("*")
    ->setOrder('name','asc');

to display all 14 of these products, then using a simple foreach() loop, but when I loop through the $products object, it actually returns ALL my products.

I’m using version 1.6.2.0, and I’ve cleared my cache.

Does anyone have a reason why this isn’t working?

EDIT

Calling echo (string) $products->getSelect(); returns

SELECT `e`.*, IF(at_visibility.value_id > 0, at_visibility.value, at_visibility_default.value) AS `visibility`, `cat_index`.`position` AS `cat_index_position`, IF(at_name.value_id > 0, at_name.value, at_name_default.value) AS `name` FROM `catalog_product_entity` AS `e` INNER JOIN `catalog_product_entity_int` AS `at_visibility_default` ON (`at_visibility_default`.`entity_id` = `e`.`entity_id`) AND (`at_visibility_default`.`attribute_id` = '95') AND `at_visibility_default`.`store_id` = 0 LEFT JOIN `catalog_product_entity_int` AS `at_visibility` ON (`at_visibility`.`entity_id` = `e`.`entity_id`) AND (`at_visibility`.`attribute_id` = '95') AND (`at_visibility`.`store_id` = 1) INNER JOIN `catalog_category_product_index` AS `cat_index` ON cat_index.product_id=e.entity_id AND cat_index.store_id=1 AND cat_index.category_id='13' AND cat_index.is_parent=1 LEFT JOIN `catalog_product_entity_varchar` AS `at_name_default` ON (`at_name_default`.`entity_id` = `e`.`entity_id`) AND (`at_name_default`.`attribute_id` = '65') AND `at_name_default`.`store_id` = 0 LEFT JOIN `catalog_product_entity_varchar` AS `at_name` ON (`at_name`.`entity_id` = `e`.`entity_id`) AND (`at_name`.`attribute_id` = '65') AND (`at_name`.`store_id` = 1) WHERE (((IF(at_visibility.value_id > 0, at_visibility.value, at_visibility_default.value) = '4') OR (IF(at_visibility.value_id > 0, at_visibility.value, at_visibility_default.value) = '2'))) ORDER BY `name` as
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T20:12:18+00:00Added an answer on May 30, 2026 at 8:12 pm

    It works for me when simplified to:

    $cat = Mage::getModel('catalog/product')->setId(198);
    
    $products = Mage::getModel('catalog/product')
        ->getCollection()
        ->addCategoryFilter($cat)
        ->addAttributeToSelect("*")
        ->setOrder('name','asc')
        ->load();
    
    foreach($products as $p) {
        print_r($p->getSku().PHP_EOL);
    }
    

    By the way, SQL is more readable (to me, anyway) if you put the addAttributeToSelect call immediately after getCollection.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a table called category in which i have main category ids and
I have a object called category, in my view/store/manage.html.erb, I want to do this
Within my WP site I have a category called 'events' where I am publishing
I have a simple Crud application where there is one filed called Category. During
I have two JSF <h:selectOneMenu> components. One called category another is subcategory . If
I have a table called courses. The fields are: id, category, sortorder, fullname, etc.....
I have category model that has a tree structure. In my database I have
I have a category tree and i'd like to get all products that are
I'm working with a product called SiteFinity. I have a class which looks like
Learning php! I have a sql database which contains a table called 'images' which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.