I want to get ONE random product from the productlist of a category. The product must have "status=1".

Is it possible?


  • every thing is possible my friend – Keyul Shah Jun 19 '14 at 12:20
  • by query twice, list and get random of it. then get product. – Tai Jun 19 '14 at 12:23
  • You need to extend the API, just search for Magento Custom API and you will come across various resources explaining how to do it. – user2935 Jun 19 '14 at 12:23

You need to refine your product with status attribute filter.

$mydata['id'] it specified the category id's array.

$collection = Mage::getModel('catalog/product')
                             ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left')
                             ->addAttributeToFilter('category_id', array('eq' =>$mydata['id'][$key]))
| improve this answer | |

I think It is Proper way for you.

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

$collection = Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToSelect('*') // select all attributes


$collection->setPageSize(1) // limit number of results returned
| improve this answer | |

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.