Browsing articles tagged with "magento Archives - Page 10 of 21 - Kalpesh Mehta"
Jul 13, 2013

Magento system config 404 error

Magento gives 404 error / Forbidden error / Access denied error when you try to open the screen of your newly written config/system XML code because either of 2 reasons.

1.) You have written the code CORRECTLY, but Magento needs to write permissions for that module in session to show it.
– Just logout and login again and you should see your newly developed screen.

2.) You have some error in your ACL role code. Magento needs the ACL role information to allow admin view the admin module.
– Check your ACL code definition again and make sure everything there is correct.

Sample code of ACL to display custom menu item in navigation:

                <title>Allow everything</title>
                    <mycustommenu translate="title" module="modulename">
                        <title>Custom MENU</title>
                            <!-- child items go here -->
                            <submenuitem translate="title" module="modulename">
                                <title>Custom SUB MENU</title>

Continue reading »

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.

Jun 15, 2013

Magento get attribute options

Get attribute options list i.e. label and value, if the attribute type is dropdown.

This post will show you how to get all the options of attribute with dropdown type in Magento. If your attribute has options, below code will give all the attribute options labels and values in an array format.

$attribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'shirt_size'); //change shirt_size to your attribute code
if ($attribute->usesSource()) {
    $options = $attribute->getSource()->getAllOptions(false);
    foreach($options as $option) {

In the above code, first line will initialize the attribute. Then we are checking if the attribute is using source model or not, if using then get all the options of that attribute.

It will output this for attribute shirt_size:

    [value] => 100
    [label] => Small
    [value] => 99
    [label] => Medium
    [value] => 98
    [label] => Large

If you are here to get attribute option’s label from value OR get attribute option’s value from label, just check out this post:

Jun 15, 2013

Magento get attribute value

To get product attribute value in Magento is very common. You will need it everytime when dealing with catalog products in your development. Attributes have different types, which can be any of Text Field, Text Area, Date, Yes/No, Multiple Select, Dropdown, Price, Gallery, Media Image, Fixed Product Tax (as you can see in backend Manage Attributes > New Attribute > Catalog Input Type for Store Owner). To get the value for these different types of attributes there is no one straight line of code, you will need to use different code for getting values from plain attributes, while different code to get values from select and multiselect attributes.

Get attribute value for PLAIN TEXT, TEXTAREA or DATE type attribute:

$attribute_value = $product->getShirtSize(); //for shirt_size attribute

Get value from SELECT, MULTISELECT, DROPDOWN or YES/NO attributes:

$attribute_value = $product->getAttributeText($attribute_code);


$attribute_value = $product->getResource()->getAttribute($attribute_code)->getFrontend()->getValue($product);

Get value from PRICE attributes:

$attribute_value = $product->getNew_price(); //for attribute code "new_price"

and in product list page,

$attribute_value = $product->getNewPrice();

Get attribute value by attribute code and productID WITHOUT loading whole product

$attribute_value = Mage::getResourceModel('catalog/product')->getAttributeRawValue($product_id, $attribute_code, $store_id);

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