Image Grid Column Renderer

To show product image previews in Magento Backend, you have to add a image grid column renderer block first: <?php /** * * Magento * * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * It is available through the world-wide-web at this URL: * http://opensource.org/licenses/osl-3.0.php […]

Add a main menu entry in Magento

This is how you can add a main menu entry to the Magento main menu in your modules adminhtml.xml: <?xml version=”1.0″ encoding=”UTF-8″?> <config> <menu> <sheldon_wysiwyg module=”sheldon_wysiwyg”> <title>WYSIWYG</title> <sort_order>88</sort_order> <children> <test module=”sheldon_wysiwyg” translate=”title”> <title>Test</title> <sort_order>0</sort_order> <action>adminhtml/sheldon_wysiwyg/data</action> </test> </children> </sheldon_wysiwyg> </menu> <acl> <resources> <all> <title>Allow Everything</title> </all> <admin> <children> <sheldon_wysiwyg> <title></title> <sort_order>70</sort_order> <children> <posts> <title>Manage Posts</title> <sort_order>0</sort_order> […]

Widget definition for BE form fields in Magento

The general widget definition for BE form fields in Magento is: <?xml version=”1.0″?> <widgets> <widget_identifier type=”blochtype/like_in_normal_blocks” translate=”name description” module=”modulname”> <name>Widgetname</name> <description>A useful description</description> <is_email_compatible>1</is_email_compatible> <parameters> <!– field definition goes here –> </parameters> </widget_identifier> </widgets> The following snippets show how to define different form fields for the widget form: Template selector: <template translate=”label”> <label>Template</label> <visible>1</visible> <type>select</type> […]

Directly query database

To directly send queries against the database: //$read = Varien_Db_Adapter_Mysqli extends Zend_Db_Adapter_Mysqli extend Zend_Db_Adapter_Abstract $read = Mage::getSingleton(‘core/resource’)->getConnection(‘core_read’); $query = ” SELECT SUM(`grand_total`) AS `grand_total`, SUM(`subtotal`) AS `subtotal`, SUM(`tax_amount`) AS `tax_amount`, SUM(`discount_amount`) AS `discount_amount`, SUM(`shipping_amount`) AS `shipping_amount`, FROM `sns_salesreport_monthstats` WHERE `year` = $year “; $data = $read->fetchRow($query); //fetches only the first row // or multiple rows: $sql […]

Add Content In Magento Controller

If you want to add content to the rendered page inside a controller action, you can do it like that: $this->loadLayout(); $message = $this->getLayout() ->createBlock(‘core/text’, ‘ready-block’) ->setText(‘<h1>Testaction for Controller:</h1>’); $this->getLayout()->getBlock(‘content’)->insert($message); $this->renderLayout();  

Implement ACL (Access-Control-List) for own Magento modules

The following snippets show how to implement ACL (Access-Control-List) for system configuration fields and main menu entries of your own modules.  It is also shown, how to check the ACL’s in the PHP code of your Module. Implement ACL – Access control for system configuration If you had configured a system configuration (System→Configuration) like this: <?xml […]

Delete users in Magento frontend

If you need the possibility to let the users delete their own accounts, you can use the following snippet in a corresponding controller or observer to delete users in frontend: <?php $oCustomer = $this->_getSession()->getCustomer(); if(!$oCustomer->getId()){ Mage::throwException($this->__(‘Cannot load customer!’)); } //lie to mage 😉 // @todo: Check, if there is a better way Mage::register(‘isSecureArea’, true); $oCustomer->delete(); $this->_getSession()->clear(); […]

Image system configuration field

To add an image selector field to your system configuration: <image> <label>Image</label> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>0</show_in_store> <sort_order>70</sort_order> <frontend_type>image</frontend_type> <backend_model>adminhtml/system_config_backend_image</backend_model> <upload_dir config=”system/filesystem/media” scope_info=”1″>customer/responsible_contacts</upload_dir> <base_url type=”media” scope_info=”1″>customer/responsible_contacts</base_url> <show_in_default> <enabled>1</enabled> </show_in_default> </image>

System configuration fields

There are different field types for Magento’s system configuration. These are for example: Button Checkboxes Checkbox Date File Hidden Imagefile Image Label Link Multiline Multiselect Note Obscure Password Radio Radios Reset Select Submit Textarea Text Time The following snippets show you how to add them to your system.xml: Enable selection (yes/no): <?xml version=”1.0″?> <config> <sections> […]