Magento: Get details of all Admin users
As we can get details of all the customers of the Magento store, we can also get details of all the Admin users. It may be necessary sometimes when you want to display all the admin uses either in dropdown for filtering something or just as a text or something based on requirement.
The following code will get you all the Admin users with their details:
$adminUserModel = Mage::getModel('admin/user'); | |
$userCollection = $adminUserModel->getCollection()->load(); | |
Mage::log($userCollection->getData()); |
Magento: Get category object from category name
Although this is very weird, to get category object (id, entity_type_id, attribute_set_id, children, etc.) from category name, sometimes it may be useful. Below lines of code will help you in getting it.
$cat = Mage::getResourceModel('catalog/category_collection')->addFieldToFilter('name', 'Category_Name_Here'); | |
print_r($cat->getData()); |
To get the category id from $cat object, simply use:
$cat->getFirstItem()->getEntityId(); |
Beware, the name should only return one category else the above query will return first category id no matter how many categories are retrieved.
Magento: Get product attribute’s select option id/label/value
If you have a select dropdown for any product attribute, to get the value from label or vice versa is always needed in order to display or get value for further processing, etc. Every now and then you will require this values while working on product attributes. There aer many ways you can achieve it but the best, in terms of performance and simplicity is what I will tell you here. Get product attribute’s value from label, label from value easily in Magento.
Suppose, you have an product attribute called “color” in Magento. You have the label (e.g. Red), and you want to find it’s value. The below code will help you get the value for it.
$productModel = Mage::getModel('catalog/product'); | |
$attr = $productModel->getResource()->getAttribute("color"); | |
if ($attr->usesSource()) { | |
echo $color_id = $attr->getSource()->getOptionId("Red"); | |
} |
Magento: Submitting form in admin redirects to dashboard
When trying to submit a form which is created in admin, it redirects to dashboard no matter how much you try. I faced this problem and tried many things but without any luck. Everything was running, for file upload I had enctype=”multipart/form-data” in form, checked the form action through firebug and run it directly in browser URL which was also going good. After so much frustration, googled the problem and found that I was not the only one to face this problem.
Finally, got one forum where I found the solution to this problem. In Magento, when submitting the form, you need to have one extra hidden field, with name “form_key” which should have form’s key value from session. Here is the line of code, which helped me in posting form successfully.
<input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" /> |
Hope this helps some frustrated mind 🙂
Magento: Get route name, module name, controller and action name from URL
Getting route name, module name, controller name and action name is very easy in Magento. You can get these values anywhere, in controller itself and also in template files.
Mage::app()->getRequest()->getControllerName(); | |
Mage::app()->getRequest()->getActionName(); | |
Mage::app()->getRequest()->getRouteName(); | |
Mage::app()->getRequest()->getModuleName(); |
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)