I'm trying to get product collection and join table catalog/category_product.

$productCollection = Mage::getResourceModel('catalog/product_collection')

And I have the error. Item (Mage_Catalog_Model_Product) with the same id "338" already exist. What am I doing wrong? Thanks.

  • one product can be from multiple category Commented Apr 14, 2017 at 9:53
  • I understand that. And how can I filter my product collection by product id? Commented Apr 14, 2017 at 10:32
  • what exatly you want to achieve? Commented Apr 14, 2017 at 10:33
  • I want to take all products in all stores and adding to them category ids. I try to use ->addCategoryIds(), but it doesn't work. May be Iim doing some mistake. Commented Apr 14, 2017 at 11:31

2 Answers 2


Please use this collection.

$collection = Mage::getModel('catalog/product')
    ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left')
  • I tried this method. I had the error: Notice: Undefined index: l in /var/www/magento/public_html/app/code/core/Mage/ConfigurableSwatches/Helper/Productimg.php on line 145 Commented Apr 14, 2017 at 11:03
  • And I think it's the same like my version. Commented Apr 14, 2017 at 11:14
  • I'm sorry. You are right. My error is not related to this. I fixed problem, but I still use ResourceModel. Commented Apr 14, 2017 at 11:21

My category id is

<?php $catid=10 ;?>
I got all product by writing the below code

    $category = new Mage_Catalog_Model_Category();
    $category->load($catid); //My cat id is 10
    $prodCollection = $category->getProductCollection();
    foreach ($prodCollection as $product) {
    $prdIds[] = $product->getId(); ///Store all th eproduct id in $prdIds array

Now you have all the product ids in `$prdIds` variable. 

Just click here to get all details of the product from a particular product id.

You can get individual product id by the following loop.

    foreach($prdIds as $_prdIds){
    $product_id = $_prdIds;
    $obj = Mage::getModel(‘catalog/product’);
    $_product = $obj->load($product_id); // Enter your Product Id in $product_id
    // get Product’s name
    echo $_product->getName();
    //get product’s short description
    echo $_product->getShortDescription();
    //get Product’s Long Description
    echo $_product->getDescription();
    //get Product’s Regular Price
    echo $_product->getPrice();
    //get Product’s Special price
    echo $_product->getSpecialPrice();
    //get Product’s Url
    echo $_product->getProductUrl();
    //get Product’s image Url
    echo $_product->getImageUrl();

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.