Monthly Archives: July 2013


Display Most Viewed Products In Magneto.

hello Friends today I will give some solution about Display Most Viewed Products In Magneto.

You can use this code any .phtml or .php files of Magento.

$storeId = Mage::app()->getStore()->getId();
$products_list = Mage::getResourceModel('reports/product_collection')
foreach ($products_list as $product)
	echo "product Views : ". $product['views'];

We create an object of the Mage::getResourceModel(‘reports/product_collection’) and filter out the data.

Hope you get the proper solution.

Difference between Mage::getSingleton() and Mage::getModel() in Magento

Hello all of you today I will explain you what is Difference between Mage::getSingleton() and Mage::getModel() in Magento.


Mage::getSingleton() will first check the same class instance is exits or not in memory. If the instance is created then it will return the same object from memory. So Mage::getSingleton() faster then Mage::getModel().

$product1 = Mage::getSingleton('catalog/product');
$product2 = Mage::getSingleton('catalog/product');

$product1 and $product2  both will share same memory of OS and return only one instance each time. 


Mage::getModel() will create a new instance of an object each time even such object exists in configuration.


$product1 = Mage::getModel('catalog/product');
$product2 = Mage::getModel('catalog/product');

$product1 and $product2 both have different instant of same object and also occupy different memory .

Hope you like this. 🙂 🙂

Magento: Design Patterns

Magento Design Pattern
Magento Design Pattern

The list of design pattern Which Magento used.

  • Model/View/Controller

Magento follow Model/View/Controller design pattern.

  • Singleton

Ensure that only one instance of a class is created and Provide a global access point to the object.

$category = Mage::getSingleton('catalog/session');
  • Factory

Creates objects without exposing the instantiation logic to the clientand Refers to the newly created object through a common interface.

$product = Mage::getModel('catalog/product');
  • Registry

It will provide you one way to store your information throughout your application.

$currentCategory = Mage::registry('current_category');
  • Prototype

Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype.

  • Event/Observer

Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.

Mage::dispatchEvent('model_load_after', $params);
  • Object Pool

Reuses and shares objects that are expensive to create.

$id = Mage::objects()->save($object);
$object = Mage::objects($id);
  • Iterator

Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.

  • Vew Helper

It will react as a to access the helper classes.

  • Null object

Provide an object as a surrogate for the lack of an object of a given type. / The Null Object Pattern provides intelligent do nothing behavior, hiding the details from its collaborators.

  • Decorator

Aadd additional responsibilities dynamically to an object.

<script type="text/javascript">

Hope you  like article. Thanks for reading.