Get upto 15% discount on Magento extensions & Themes. Join Now - Limited Period Offer!

Pitfalls for developers while working with Magento

Pitfalls for Magento developers

The Magento files and coding are quite complex and a single simple mistake can have a major impact on the performance of the store as well as on the business. In this section, we will see some most common pitfalls for developers when they work with Magento and how it can be solved.

Modifying Magento Core Files

To save their time, the developers modify the core files of the Magento. This may complete their work fast but then they interfere with the Magento Upgrades, later. However, for future upgrades, you need to keep the core files protected.

The best to modify the core files is to either create your own customized module or copy the same folder structure in your local module.

To modify:


Copy the structure to local folder:


Improper Memory usage

A heavy demand on the system and on network resources is caused due to large results sets from the fetchAll() database adapter method:

 $rowSet = $this->_getReadAdapter()->fetchAll($select);

foreach ($rowSet as $row) {

//process row


Better, keep an approach to fetch each database row separately using the fetch() method to reduce resource consumption:

$query = $this->_getReadAdapter()->query($select);

while ($row = $query->fetch()) {

//process row


Disorganized Data Set Utilization

This is a common mistake done by the developers where they only need to retrieve a limited number of data but they do so for complete data set:

public function getSelectedItem() {

$collection = Mage::getResourceModel(‘mymodule/custom_collection’);

return $collection->getFirstItem();


Ask your developers to put a limitation on every collection query. Example:

public function getSelectedItem() {

$collection = Mage::getResourceModel(‘mymodule/custom_collection’)->setPageSize(1);

return $collection->getFirstItem();


SQL Queries in a Loop

The process of running a SQL query is quite expensive and when it is done in the loop, it makes the process even worse. Below is the example of running a SQL query inside a loop:

 foreach ($this->getProductIds() as $productId){

$product = Mage::getModel(‘catalog/product’)->load($productId);



The benefit of data collection in Magento is that it offers control over the data fields. Multiple tables are requested and all the entities are selected while loading the EAV model:

$collection = Mage:getResourceModel(‘catalog/product_collection’)

->addFieldsToFilter(‘entity_id’, array($this->getProductIds()))


foreach ($collection as $product){



Loading the same model Multiple times

The model load operation is not cached internally. And when the developers do not take care of this, the same model is loaded multiple times. This can lead to scalability issues:

$name = Mage::getModel(‘catalog/product’)->load($productId)->getName();

$sku  = Mage::getModel(‘catalog/product’)->load($productId)->getSku();

$price = Mage::getModel(‘catalog/product’)->load($productId)->getPrice();

For an optimum performance, every model should load only once:

$product = Mage::getModel(‘catalog/product’)->load($productId);

$name    = $product->getName();

$sku     = $product->getSku();

$price    = $product->getPrice();

It may happen that you don’t need to work with the models in some cases. In that case, perform the work with loading only the required attributes:

Mage::getResourceModel(‘catalog/product’)->getAttributeRawValue($productId, ‘attribute_code’, $storeId);


$productId = Mage::getModel(‘catalog/product’)->getIdBySku($sku);

Neglecting Security Patches

Security patches serve as a base for making your store strong and secure from any hacking event. And when there are any chances of such events, Magento announces the security patches for that.

However, you need to make sure that you have installed the latest security patches from the Magento official website, for your store.

If you are planning to build your Magento eStore or looking for website maintenance, then you can talk with us. We will happy to help you

Tagged with:
  • a Good Magento Developer
  • develop a magento website
  • Hire Magento Developer
  • Magento Development Pitfalls
  • Magento Development Pitfalls and solutions
  • Magento mistakes
  • Pitfalls for developers while working with Magento
  • pitfalls to avoid while working with Magento
Recommended :

Leave a Reply

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

Need Help?
Support Ticket