Get product name using its sku - in efficient way - using collection
Posted on February 6, 2012 by admin There have been 0 comments
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
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.