Catalog Product Model

While working in Magento, you might have seen that there are various model defined like sales,catalog etc.

I am writing here a script for working with catalog product model.

$model = Mage::getModel('catalog/product') //get product model

//get product collection
$collection = $model->getCollection()
            ->addStoreFilter()    //store filter
            ->addAttributeToSelect('*') //for getting all attributes, you can specify the attributes also (comma seperated)
            ->addAttributeToFilter('sku',array('like' => '%ABC%')) //for restricting data
            ->addAttributeToSort('sku', 'asc');  // for sorting the result set

//now you can fetch products data
	foreach($collection as $_product)
	    echo $_product->getShortDescription(); //product's short description
	    echo $_product->getDescription(); // product's long description
	    echo $_product->getName(); //product name
	    echo $_product->getPrice(); //product's regular Price
	    echo $_product->getSpecialPrice(); //product's special Price
	    echo $_product->getProductUrl(); //product url
	    echo $_product->getId(); //product's id
	    echo $_product->getSku(); //product's sku

I hope it is useful to you.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top