Top 9Mistakes that Magento Development Should Avoid

1. SQL Queries inside a loop

foreach ($this->getProductIds() as $productId) { 
$product = Mage::getModel('catalog/product')->load($productId); $this->processProduct($product);
}
$collection = Mage::getResourceModel('catalog/product_collection')->addFieldToFilter('entity_id',array($this->getProductIds()))->addAttributeToSelect(array('name')); 
foreach ($collection as $product) {
$this->processProduct($product);
}

2. Loading the same model multiple times

$name = Mage::getModel('catalog/product')->load($productId)->getName(); 
$sku = Mage::getModel('catalog/product')->load($productId)->getSku();
$attr = Mage::getModel('catalog/product')->load($productId)->getAttr();
$product = Mage::getModel('catalog/product')->load($productId); $name = $product->getName(); 
$sku = $product->getSku();
$attr = $product->getAttr();
$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku); 
$res['id'] = $product->getId();
$res['id'] = Mage::getModel('catalog/product')->getIdBySku($sku);

3. Redundant data set utilization

public function getRandomItem() { 
$collection = Mage::getResourceModel('mymodule/my_collection')->setRandomOrder();
return $collection->getFirstItem();
}
public function getRandomItem() { 
$collection = Mage::getResourceModel('mymodule/my_collection')>setRandomOrder()->setPageSize(1);
return $collection->getFirstItem();
}

4. Inefficient memory utilization

$rowSet = $this->_getReadAdapter()->fetchAll($select); 
foreach ($rowSet as $row) {
//process row
}
$query = $this->_getReadAdapter()->query($select); 
while ($row = $query->fetch()) {
//process row
}

5. Basic PHP Code optimizations

for ($i = 0; $i < count($rows); $i++) { 
//some code
}
$rowNum = count($rows); 
for ($i = 0; $i < $rowNum; $i++) {
//some code
}

6. Modifying Magento core files

app/code/core/Mage/Checkout/controllers/OnepageController.php
app/code/local/Mage/Checkout/controllers/OnepageController.php

7. Security Patches

8. Admin router

admin

New Method

9. Magento Designer Guide

Conclusion

--

--

Techtic Solutions Inc. headquartered in New York, USA is a leading mobile apps development and web development company to SMEs and enterprises worldwide.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Techtic Solutions

Techtic Solutions Inc. headquartered in New York, USA is a leading mobile apps development and web development company to SMEs and enterprises worldwide.