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> […]

Template Marker

Here is a collection of marker that can be used in email templates, cms pages and static blocks. Get system configuration fields {{config path=”web/unsecure/base_url”}} Customer data {{var customer}} -> print all customer data {{var customer.ID}} {{var customer.email}} {{var customer.firstname}} {{var customer.lastname}} {{var customer.name}} {{var customer.password}} {{var customer.created_in}} -> store name where customer was created in {{var […]

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();  

Magerun

Magerun is a very useful commandline tool for dealing with daily Magento development problem like: clean / flush caches reindexing the indices set configuration values in the database (core_config_data) shorthand query syntax for database accesses … It’s developed by netz98 (http://www.netz98.de/) and made my daily business so much easier. Installation (Linux) $> wget https://raw.githubusercontent.com/netz98/n98-magerun/master/n98-magerun.phar $> […]

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>