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:
<config> | |
<acl> | |
<resources> | |
<all> | |
<title>Allow everything</title> | |
</all> | |
<admin> | |
<children> | |
<mycustommenu translate="title" module="modulename"> | |
<title>Custom MENU</title> | |
<sort_order>500</sort_order> | |
<children> | |
<!-- child items go here --> | |
<submenuitem translate="title" module="modulename"> | |
<title>Custom SUB MENU</title> | |
<sort_order>10</sort_order> | |
</submenuitem> | |
</children> | |
</mycustommenu> | |
</children> | |
</admin> | |
</resources> | |
</acl> | |
</config> |
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:
<global> | |
<!--convert your custom product attribute "myattribute" from quote item to order item--> | |
<fieldsets> | |
<sales_convert_quote_item> | |
<myattribute> | |
<to_order_item>*</to_order_item> | |
</myattribute> | |
</sales_convert_quote_item> | |
</fieldsets> | |
<!--add your custom product attribute "myattribute" to quote item--> | |
<sales> | |
<quote> | |
<item> | |
<product_attributes> | |
<myattribute></myattribute> | |
</product_attributes> | |
</item> | |
</quote> | |
</sales> | |
<!--convert product attribute to quote item through event observer--> | |
<events> | |
<sales_quote_item_set_product> | |
<observers> | |
<mymodule> | |
<class>mymodule/observer</class> | |
<method>convertAttribute</method> | |
</mymodule> | |
</observers> | |
</sales_quote_item_set_product> | |
</events> | |
</global> |
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.
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) { | |
print_r($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:
Array | |
( | |
[value] => 100 | |
[label] => Small | |
) | |
Array | |
( | |
[value] => 99 | |
[label] => Medium | |
) | |
Array | |
( | |
[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: http://ka.lpe.sh/2012/09/13/magento-get-product-attribute-select-option-idlabelvalue/
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); |
OR
$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
Certifications
Honor
Recognition
Contributions
Categories
- Apache (2)
- ChatGPT (1)
- Domain name (2)
- eCommerce (2)
- htaccess (1)
- Humor (3)
- Instagram API (1)
- jQuery (4)
- JSON (1)
- Linux (10)
- Magento (142)
- Magento admin (58)
- Magento Certification (5)
- Magento error (13)
- Magento frontend (68)
- Magento Imagine (2)
- Magento Interview (5)
- Magento Master (2)
- Magento2 (10)
- Mobile (1)
- MySQL (7)
- OpenAI (1)
- OroCRM (2)
- Performance (2)
- PHP (8)
- Prototype JS (3)
- Security (4)
- Wordpress (3)
- XML (2)