Browsing articles in "Magento frontend"
Jul 12, 2013

Magento convert quote item to order item

If you have custom product attribute(s), then you may need to convert them to quote item and then to order item in Magento when an order is placed. That helps the order get the product attributes details and saves it in order tables to reference in the backend Manage Orders screen. This allows you to know what values for the product is selected by the customer, so that you can consider it when dispatching the order items.

This is a two way process where first the product attribute converts to quote item, and then quote item (with your product attribute’s value) converts to order item.

To do this you will have to put the below code in your module’s config.xml file:

    <!--convert your custom product attribute "myattribute" from quote item to order item-->

    <!--add your custom product attribute "myattribute" to quote item-->

    <!--convert product attribute to quote item through event observer-->

Continue reading »

Jun 29, 2013

Magento get store information

Magento get store information from any page.

$store = Mage::app()->getStore(); //Mage_Core_Model_Store object

Now to get store ID,

$storeID = $store->getStoreId();

To get store code,

$storeCode = $store->getCode();

To get store Website ID,

$websiteID = $store->getWebsiteId();

To get store name,

$storeName = $store->getName();

To get Default View store name,

$storeName = $store->getFrontendName();

To check if store is active or not,

$active = $store->getIsActive();

To get store’s Home URL,

$storeHomeURL = $store->getHomeUrl();

If you want to find store’s group name,

$storeGroupName = $store->getGroup()->getName();

If you want ADMIN Store information, admin store has ID 0. So, you can get the details of Admin Store like this:

$store = Mage::getModel('core/store')->load(0);

and then getting all the information as shown above.

May 26, 2013

Magento filter products by status

Get all the products with status equal to enabled/disabled.

If you are using Flat Catalog in Magento, you will not get disabled products by this filter as in flat table all the products are only enabled one. You can check if your Magento website uses flat catalog or not by going here:
Admin > System > Configuration > Catalog section > Catalog > Frontend

Check Use Flat Catalog Category and Use Flat Catalog Product, if they are Yes it means you are using flat catalog, if they are No it means you are NOT using flat catalog.

So, if you don’t have flat catalog enabled and you want to filter all the products with status equal to disabled, you can use below code:

$products = Mage::getModel('catalog/category')->load($category_id)
->addAttributeToSelect('*') //whatever attributes you want to get here
    array('eq' => Mage_Catalog_Model_Product_Status::STATUS_DISABLED) 
        //replace DISABLED to ENABLED for products with status enabled
May 26, 2013

Magento get subcategories of a category by category ID

Get all the subcategories of any category in Magento.

If you have a category ID (current category OR any category) then you can easily get all the subcategories of that particular category.

Below code will load all the subcategories of the current category. You can even get all the subcategories of any specific category by assigning category ID to $catID.

$catID = $current_category->getId(); //or any specific category id, e.g. 5
$children = Mage::getModel('catalog/category')->getCategories($catID);
foreach ($children as $category) {
        echo $category->getId();
        echo $category->getName();
        echo $category->getRequestPath();
May 26, 2013

Magento remove index.php from URL

In Magento remove index.php from URL using below steps. It will convert your URL from


1.) In Magento Admin > System > Configuration > Web > Search Engine Optimization, change the value of Web Server Rewrites to Yes

Make sure your web server rewrite module is enabled. If you are using apache as your web server on Linux, you can check it by going to /etc/apache2/mods-enabled/rewrite.load, if rewrite.load is present there it means your rewrite module is enabled. If not, you will need to copy rewrite.load from /etc/apache2/mods-available/ and paste it at /etc/apache2/mods-enabled/ location. Then reload the apache by running service apache2 reload.

2.) Check the file permission of .htaccess, it should be present in Magento root directory and readable by server.

Welcome to my Blog

Kalpesh MehtaHelping Magento developers in their day-to-day development problems since 2011. Most of the problems and solutions here are my own experiences while working on different projects. Enjoy the blog and don't forget to throw comments and likes/+1's/tweets on posts you like. Thanks for visiting!




Magento top 50 contributors

Magento top 50 contributors