Speeding Up your Magento Website

Series of articles about speeding up the magento site.

  • Get product name using its sku - in efficient way - using collection

    Posted on February 6, 2012 by admin

    If for some reason you have list of products skus, and for each you need to fetch out it's name,
    you will better not use the old way of
    $pname = Mage::getSingleton("catalog/product")->load(Mage::getSingleton("catalog/product")->getIdBySku($productSku))->getName();

    because it will slow up dramatically your site.
    Better use the following piece of code:

    <?php
    
    $productSku = 'sku1';
    
    $pname = Mage::getSingleton("catalog/product")
    	    		->getCollection()
    	    		->addFieldToFilter('sku', $newpsku)
    	    		->addAttributeToSelect('name')
    	    		->load()
    	    		->getFirstItem()
    	    		->getName();

    This post was posted in Speeding Up your Magento Website, Working With Magento Collections

Items 4 to 4 of 4 total

Page:
  1. 1
  2. 2
Magento is a well-engineered eCommerce platform designed to help engineers develop customized eCommerce online stores. Due to lack of proper coding documentation, Engineer-ing.com was created with the sole purpose of instructing Magento developers to-be with the "how-to-do" know-how. In the event of unresolved issues, you are more than welcome to contact me for consultation. However, please do so only if you possess a Software Engineering background and you're able to specify your question.