How to Manage the Backend Functionality of Your Magento Store?

Helper contains the necessary functions for you; you can call in a helper from anywhere. An example of helper is as below

$helper = Mage::helper(‘monhelper’);

The call can be related to

$helper = Mage::helper(‘monhelper/data’);

Let’s create a helper file
You will need to declare the helper in the config file in your Magento core. Configure your code in the <global> after the </blocks> field

<helpers>
<test>
<class>STTL_Test_Helper</class>
</test>
</helpers>

Next, you will need to create the file app/code/local/STTL/Test/Helper/data.php which will contain the function bytwo($ nbr). A number will be used as an argument here. The return value in the output will be the number multiplied by two.Helper will extend the core class Mage_Core_Helper_Abstract

<?php
class STTL_Test_Helper_Data extends Mage_Core_Helper_Abstract{
public function bytwo($nbr){
return $nbr*2;
}
}

Go to in/app/code/local/STTL/Test/Block/monblock.php and change the function here with the help of the code below

<?php
class STTL_Test_Block_Monblock extends Mage_Core_Block_Template
{
public function methodblock()
{
$helper = Mage::helper(‘test’);
return ‘2*2 = ‘.$helper->bytwo(2);
}
}

Let’s Add a New Field
Let’s say you want to create a plugin that will store information about payment card in the system>configuration.

Let’s add a sidebar <<Cards>> section with a <<cards>> group and a config tab to help store your card numbers

Let’s begin by creating a structure for the project

<?xml version=”1.0″?>
<config>
<modules>
<STTL_Ecard>
<version>1.0.0</version>
<depends>
<!– no dependencies –>
</depends>
</STTL_Ecard>
</modules>
<frontend>
<routers>
<route_ecard>
<use>standard</use>
<args>
<module>STTL_Ecard</module>
<frontName>ecard</frontName>
</args>
</route_ecard>
</routers>
</frontend>
<adminhtml>
<acl>
<resources>
<admin>
<children>
<system>
<children>
<config>
<children>
<ecard_section translate=”title”>
<title>My Section </title>
<sort_order>100</sort_order>
</ecard_section>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
</adminhtml>
</config>

Create etc/system.xml and declare the menu here.

<?xml version=”1.0″ ?>
<config>
<tabs>
<ecard_tab translate=”label”>
<label>Cartes</label>
<sort_order>100</sort_order>
</ecard_tab>
</tabs>
<sections>
<ecard_section translate=”label”>
<label>Cartes</label>
<sort_order>200</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<tab>ecard_tab</tab>
<groups>
<ecard_group translate=”label”>
<label>Config</label>
<comment>Card Configuration</comment>
<sort_order>10</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<fields>
<ecard_field translate=”label comment”>
<label>Card Number</label>
<comment>a text to help</comment>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<frontend_input>text</frontend_input>
</ecard_field>
</fields>
</ecard_group>
</groups>
</ecard_section>
</sections>
</config>

With this xml, you can add a tab to System>Configuration and then retrieve the information from the fields

Mage::getStoreConfig(‘ecard_section/ecard_group/ecard_field’);

You can test what you have created by creating a controller in controllers/IndexController.php

<?php
class STTL_Ecard_IndexController extends Mage_Core_Controller_Front_Action
{
/*
* To test Ecards functions…
*/
public function indexAction()
{
echo Mage::getStoreConfig(‘ecard_section/ecard_group/ecard_field’);
}
}

 

Conclusion
Creating a field or a helper will add functionality and new features to your store. You can even customize your store with the help of these fields. Hire Offshore Magento developers to help you create custom fields or helper.

About deeparanganathan