support

How to show Products collection in Magento?

You can use below code to get all Products collection in Magento on any of Magento page:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$_productCollection = Mage::getModel('catalog/product')->getCollection();
$_productCollection->addAttributeToFilter('status', 1); //enabled or not
$_productCollection->addAttributeToFilter('visibility', 4); //catalog, search enabled or not
foreach ($_productCollection as $_product)
{
$model = Mage::getModel('catalog/product');
$product_id = $_product->getId();
$_product = $model->load($product_id);
$_image=Mage::getModel('catalog/product')->load($product_id);
 
<div class="feature-product">
<div class="feature-product-price"><?php echo $_product->getPrice(); ?></div>
<div class="feature-product-name"><?php echo $_product->getName(); ?></div>
<div class="feature-product-image"><a href="<?php echo $_product->getProductUrl() ?>"><img src="<?php echo Mage::helper('catalog/image')->init($_image, 'image')->resize(200,200); ?>"></a></div>
</div>
<?php
}

If you want Product Collection with specific ids then use below code

<?php
$productIds = array(45,43);
$_productCollection = Mage::getModel('catalog/product')->getCollection();
$_productCollection->addAttributeToFilter('status', 1); //enabled
$_productCollection->addAttributeToFilter('visibility', 4); //catalog, search
$_productCollection->addAttributeToFilter('entity_id', array('in' => $productIds));
 
 
foreach ($_productCollection as $_product)
{
 
$model = Mage::getModel('catalog/product');
$product_id = $_product->getId();
$_product = $model->load($product_id);
$_image=Mage::getModel('catalog/product')->load($product_id);
?>
<div class="feature-product">;
<div class="feature-product-image">resize(200,200); >"</div>
 
</div>
<?php }?>
© 2008-2021 Copyright Startbit IT Solutions Pvt. Ltd.(Formerly known as Vivacity InfoTech Pvt. Ltd.) | All Rights Reserved.
Loading...