I'm working on a site that has 3 root categories, one per store in the Magento installation.

On the categories page (Catalog > Manage Categories) I can see the category ids and the number of products they have respectively.

  • Category1 - Id: 6 - store: 3 - 11 products
  • Category2 - Id: 10 - store: 4 - 11 products
  • Category3 - Id: 14 - store: 5 - 11 products

I've used the CMS to distinguish the content at the store-view level for each store. For example, on the store for the first category, I have this (filtering the products to category 6)

{{block type="catalog/product_list" name="home.catalog.product.list" alias="products_homepage" category_id="6" template="catalog/product/list.phtml"}}

However, all 33 products are being displayed. Any idea why products from the other categories are being displayed?


I've been digging more and it looks like it has something to do with product indexing in Magento. Here's the query that's erroneously selecting 33 products

SELECT `e`.*, 
       `cat_index`.`position` AS `cat_index_position`, 
       IF(price_index.tier_price IS NOT NULL, Least(price_index.min_price, 
       price_index.min_price) AS `minimal_price`, 
FROM   `catalog_product_entity` AS `e` 
       INNER JOIN `catalog_category_product_index` AS `cat_index` 
               ON cat_index.product_id = e.entity_id 
                  AND cat_index.store_id = 3 
                  AND cat_index.visibility IN( 2, 4 ) 
                  AND cat_index.category_id = '6' 
                  AND cat_index.is_parent = 1 
       INNER JOIN `catalog_product_index_price` AS `price_index` 
               ON price_index.entity_id = e.entity_id 
                  AND price_index.website_id = '1' 
                  AND price_index.customer_group_id = 0

I've verified store_id=3 is correct (as well as category_id=6 like I mentioned earlier). If I query the catalog_category_product table directly, it meets expectations, there are 11 products.

SELECT Count(*) 
FROM   catalog_category_product_index 
WHERE  category_id = 6 
       AND store_id = 3; 

However, if I query catalog_category_product_index with the relevant filters from the large query Magento is running, there are 33 products.

SELECT Count(*) 
FROM   catalog_category_product_index 
WHERE  category_id = 6 
       AND store_id = 3 
       AND is_parent = 1 
       AND visibility IN ( 2, 4 );

I reindexed everything under Index Management and that had no effect.

Better Update

There is something definitely spurious going on with the indexing, I've narrowed the issue even further.

Directly selecting from catalog_category_product

SELECT category_id 
FROM   catalog_category_product 
WHERE  product_id = 3445; 


| category_id |
|          10 |
|          13 |

Selecting from catalog_category_product_index

SELECT category_id 
FROM   catalog_category_product_index 
WHERE  product_id = 3445 
GROUP  BY category_id; 


| category_id |
|           2 |
|           6 |
|          10 |
|          13 |
|          14 |

Somehow Magento's catalog indexing process is erroneously saying this product is in categories 2,6 & 14, when in point of fact, it's not! Any idea what could be wrong??

  • are you sure that products are only listed to categry 1 -id 6 not listed under category 2 and 3 ? – samumaretiya Sep 16 '15 at 18:55
  • Yes, the products are only in one category. They all have distinct SKUs, but they duplicate names, I don't think that would matter, but unsure. – quickshiftin Sep 16 '15 at 19:06

I ended up biting the bullet and digging into the indexing process. I tracked the addition of bogus products into this file


which defines class Mage_Catalog_Model_Resource_Category_Indexer_Product which has the method _prepareEnabledProductsVisibility. This is where things were going awry.

It was running this query

SELECT `pw`.`product_id`, 
       IF(pvs.value_id > 0, `pvs`.`value`, `pvd`.`value`) AS `visibility` 
FROM   `catalog_product_website` AS `pw` 
       LEFT JOIN `catalog_product_entity_int` AS `pvd` 
              ON pvd.entity_id = pw.product_id 
                 AND pvd.attribute_id = '102' 
                 AND pvd.store_id = 0 
       LEFT JOIN `catalog_product_entity_int` AS `pvs` 
              ON pvs.entity_id = pw.product_id 
                 AND pvs.attribute_id = '102' 
                 AND pvs.store_id = '3' 
       LEFT JOIN `catalog_product_entity_int` AS `psd` 
              ON psd.entity_id = pw.product_id 
                 AND psd.attribute_id = '96' 
                 AND psd.store_id = 0 
       LEFT JOIN `catalog_product_entity_int` AS `pss` 
              ON pss.entity_id = pw.product_id 
                 AND pss.attribute_id = '96' 
                 AND pss.store_id = '3' 
WHERE  ( pw.website_id = '1' ) 
       AND ( IF(pss.value_id > 0, `pss`.`value`, `psd`.`value`) = 1 )

the purpose of which is to enumerate products and their visibility. However this query was returning products outside of the target store (in this case 3). By adding some more constraints to the WHERE clause I was able to reduce the result set to products within the target store. I did this by adding the following to the chained method invocation which builds the query

->where('pss.store_id=? AND pvs.store_id=?', (int)$storeId, (int)$storeId);

This seems to be working, but I'm guessing (read: hoping) there's just some sort of problem with how I've entered the products and categories into this multi-store installation. After all, it's my first such Magento installation, so perhaps there's something I've overlooked as to how the catalog has been entered.


I have applied the blow code with category id 3 it work perfectly for me

{{block type="catalog/product_list" name="home.catalog.product.list" alias="products_homepage" category_id="3" template="catalog/product/list.phtml"}}

Make sure clearing the cache

Let me know if you have any query

  • I've completely disabled the cache and still all products from all 3 root categories are displayed. – quickshiftin Sep 16 '15 at 19:00

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.