Wednesday 22 June 2011

Magento Methods getModel(), getData()

getModel()

The getModel() function is used to create an instance of a Model class.
For example: $Product = Mage::getModel(’catalog/product’);
this tells magento to create instance of  Mage_Catalog_Model_Product class
Some useful methods include getName, getPrice, getTypeId, getStatus which we can execute like
<?php echo ‘Name: ‘. $Product->getName();?>
<?php echo ‘Price: ‘ . $Product->getPrice();?>
getData()



This function is used to get relevant data from the object instance. Let’s say you want to retrieve the SKU value. You can use some other method for that like getSku() method that needs to be executed on object of Product type or you can:

Example:
$min_sale_qty = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($this->getProduct())->getData('min_sale_qty');

No comments:

Post a Comment