Get product name using its sku – in efficient way – using collection

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...
Read more

Find Out The SQL Query That Was Used To Retrieve A Collection

To find out the SQL query Magento uses to retrieve a specific collection, just do the following: Let’s say you would like to know what query is used to get a product collection – go to your debugging area (or maybe some phtml file), and paste following code:   $_productCollection = Mage::getResourceModel("catalog/product_collection");...
Read more

Changing The Select After The Collection Has Been Loaded

Lets observe at the following example: For some reason you want to show the products whose price is lower than 100$. If you go to list.phtml at app/design/frontend/base/default/template/catalog/product, you will see the following line: $_productCollection=$this->getLoadedProductCollection(); $_productCollection is instance of Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection, and of course this is already loaded collection (collection that has items)....
Read more