Magento Tutorials

How to Get All Products Programmatically in Magento

Below is the full code to get all products in Magento Admin Panel

<?php /* listing of all product */
$allproduct = Mage::getModel(‘catalog / product’)->getCollection()
    ->setOrder(‘entity_id’, ’desc’)
foreach ($allproduct as $product)
    $obj = Mage::getModel(‘catalog / product’);
    $productid = $product[‘entity_id’];
    $_product = $obj->load($productid); // Enter your Product Id in $product_id
    $productUrl = $_product->getProductUrl();
<li><a href=”<?php echo $productUrl ?>”><?php echo $_product->getName(); ?></a></li>
} ?>

Get all products under a category in Magento

In case you have to get all products in a category, use this code:

# Uncomment the next three lines if you're calling this outside of Magento
#require_once './app/Mage.php';
# If you're calling this from inside a phtml file then you can use something like this to get the category ID
#$category_id = $this->getCurrentCategory()->getId();
# or use the following line:
$category_id = 1; # Change category ID here.
$category = Mage::getModel('catalog/category')->load($category_id);
$products = Mage::getModel('catalog/product')->getCollection()
foreach ($products as $product)
    echo '<a href="' . $product->getProductUrl() . '">' . $product->getName() . "</a><br>";

Hope that helps!

Read more:
How to Create Shipment Programmatically in Magento 2
How to Get Category ID in Magento


A knowledge craver who always strive to be wiser everyday.

Notify of

Inline Feedbacks
View all comments