Tag : products

Magento – products block

Go to “CMS – Manage Pages” and select the page do you want to display the products from the list of pages.

Use next code to display products labeled as “new”:

{{block type="catalog/product_new" name="catalog.product.new" alias="new_products" template="catalog/product/new.phtml"}}

Use next code to display all products from catalog:

{{block type="catalog/product_list" name="catalog.product.list" alias="all_products" template="catalog/product/list.phtml"}}

Use next code to display all products from a specific category:

{{block type="catalog/product_list" name="catalog.product.list" alias="category_products" category_id="4" template="catalog/product/list.phtml"}}

Magento get all products

Next code is a method to get all product from magento database:

$products = Mage::getModel('catalog/product')->getCollection();
$products->addAttributeToFilter('status', 1);//enabled
$products->addAttributeToFilter('visibility', 4); //catalog, search
$products->addAttributeToFilter('type_id', 'simple'); //catalog, search
$prodIds = $products->getAllIds();
foreach($prodIds as $productId)
$product = Mage::getModel('catalog/product');

Magento get products from a specific category

Next code is a sample to extract all products from a specific category:

$prodCat = Mage::getModel('catalog/category')->load($catId);
$prodCat = $prodCat->getProductCollection();
foreach( $prodCat->getAllIds() as $prodId)
print $_product->getName()."