Working With Magento Collections

Series of articles about things you can do with magento collections.

  • Magento 1.6.2 API Access Role - Bug

    Posted on December 22, 2012 by Nimrod Techn

    Granting API custom/full access role in Magento 1.6.2 (Web Services > Roles) simply doesn't work.
    How to we fix it?

    Copy app/code/core/Mage/AdminHtml/Block/Api/Tab/RolesEdit.php

    To: app/code/local/Mage/AdminHtml/Block/Api/Tab/RolesEdit.php


    Inside, place the following:

    class Mage_Adminhtml_Block_Api_Tab_Rolesedit extends Mage_Adminhtml_Block_Widget_Form {
        public function __construct() {
            $rid = Mage::app()->getRequest()->getParam('rid', false);
            $resources = Mage::getModel('api/roles')->getResourcesList();
            $rules_set = Mage::getResourceModel('api/rules_collection')->getByRoles($rid)->load();
            $selrids = array();
            foreach ($rules_set->getItems() as $item) {
    			if (array_key_exists(strtolower($item->getResource_id()), $resources)
                               && $item->getApiPermission() == 'allow') {
                    $resources[$item->getResource_id()]['checked'] = true;
                    array_push($selrids, $item->getResource_id());

    This post was posted in Working With Magento Collections

  • 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:

    $productSku = 'sku1';
    $pname = Mage::getSingleton("catalog/product")
    	    		->addFieldToFilter('sku', $newpsku)

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

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

    Posted on August 4, 2011 by admin

    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");


    Passing "true" as a parameter to the load function, will print out the query that Magento uses to retrieve the items for the collection.

    This post was posted in Working With Magento Collections and was tagged with Magento collections, debugging

Items 1 to 3 of 4 total

  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, 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.