1

I use the following code to get products of specific category:

$products = Mage::getModel('catalog/category')->load($category_id)
 ->getProductCollection()
 ->addAttributeToSelect('*') // add all attributes - optional
 ->addAttributeToFilter('status', 1) // enabled
 ->addAttributeToFilter('visibility', 4) //visibility in catalog,search
 ->setOrder('price', 'ASC'); //sets the order by price

But how can I obtain all products instead?

2

Use this code below:

$collection = Mage::getResourceModel('catalog/product_collection');
foreach($collection as $product) {
    echo $product->getId();
}
0

You can use magento object to filter.

Example:

$categoryId = 123; // a category id that you can get from admin
$category = Mage::getModel('catalog/category')->load($categoryId);

$products = Mage::getModel('catalog/product')
    ->getCollection()
    ->addCategoryFilter($category)
    ->load();

print_r($products);
-1
   $collection = Mage::getResourceModel('catalog/product_collection');
foreach ($collection as $product) {

    $data = $product->getData();
    foreach ($data as $d)
        var_dump($d);

}

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.