Extending Shopping Cart Price Rules form magento

You might need to add a new field on “Shopping Cart Price Rules” form so this tutorial will help you to achieve this goal.

Goal: Extending “Shopping Cart Price Rules” and Add a new text field under “General Information” tab.

Strategy to achieve this Goal :

If you go into the code then we can see that current form is being created by file that is available at

“app\code\core\Mage\Adminhtml\Block\Promo\Quote\Edit\Tab\Main.php”

Here in this script I need to add a new text field. That says

Enter your reference id: –Text box— come here

So basically I need to add this text field by writing something like below code

  $fieldset->addField('refid', 'text', array(
            'name' => 'refid',
            'label' => Mage::helper('salesrule')->__('Ref Id'),
            'title' => Mage::helper('salesrule')->__('Ref Id'),
            'required' => true,
        ));

But we can’t make this change to magento core file. So in order to implement this change we must need to override this file.

Below are the way to override this:

Way 1:

Copy this file to app\code\core\Mage\Adminhtml\Block\Promo\Quote\Edit\Tab\Main.php to

app\code\local\Mage\Adminhtml\Block\Promo\Quote\Edit\Tab\Main.php to

But here we are just getting benefit of load code pool sequence. We are just preventing magento to go to core files. Instead of that you want your local file should be get loaded there. So this is not the correct way to handle (as per magento guideline)

Way 2: (Best Way)

Create new magento module by creating your namespace (or use existing namespace) and create 3 files there to handle the rewrite

app/code/local/NameSpaceName/Adminhtml/Block/Promo/Quote/Edit/Tab/Main.php
app/code/local/NameSpaceName/Adminhtml/etc/config.xml
app/etc/modules/NameSpaceName_Adminhtml.xml

Code for app/etc/modules/NameSpaceName_Adminhtml.xml

<?xml version="1.0"?>
<config>
     <modules>

        < NameSpaceName_Adminhtml>
            <active>true</active>
            <codePool>local</codePool>
        </ NameSpaceName_Adminhtml>

     </modules>
</config>

Code for app/code/local/NameSpaceName/Adminhtml/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        < NameSpaceName_Adminhtml>
            <version>0.1.0</version>
        < NameSpaceName_Adminhtml>
    </modules>
    <global>
        <blocks>
            <adminhtml>
                <rewrite>
                    <promo_quote_edit_tab_main> NameSpaceName_Adminhtml_Block_Edit_Tab_Main
</promo_quote_edit_tab_main>
                </rewrite>
            </adminhtml>
        </blocks>
    </global>
</config>

Code for app/code/local/NameSpaceName/Adminhtml/Block/Promo/Quote/Edit/Tab/Main.php

Copy whole class of main.php here . The only thing that is notable that instead of class name “Mage_Adminhtml_Block_Promo_Quote_Edit_Tab_Main” we need to have new class name that is “NameSpaceName_Adminhtml_Block_Edit_Tab_Main”

Now make whatever change you whatever you want to make into this script.

Way 3:

app/code/local/NameSpaceName/ModuleName/Adminhtml/Block/Promo/Quote/Edit/Tab/Main.php
app/code/local/NameSpaceName/ModuleName /Adminhtml/etc/config.xml
app/etc/modules/NameSpaceName_ModuleName.xml

 

Code for app/etc/modules/NameSpaceName_ModuleName.xml

<?xml version="1.0"?>
<config>
     <modules>

        < NameSpaceName_ModuleName>
            <active>true</active>
            <codePool>local</codePool>
        </ NameSpaceName_ModuleName >

     </modules>
</config>

Code for app/code/local/NameSpaceName/ModuleName/Adminhtml/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <NameSpaceName_ModuleName>
            <version>1.0.0</version>
        </ NameSpaceName_ModuleName >
    </modules>
    <global>
        <blocks>
            <adminhtml>
                <rewrite>
                    <promo_quote_edit_tab_main>
NameSpaceName_ModuleName_Adminhtml_Block_Edit_Tab_Main
</promo_quote_edit_tab_main>
                </rewrite>
            </adminhtml>
        </blocks>
    </global>
</config>

Now copy your file to app\code\local\ NameSpaceName \ ModuleName \Adminhtml\Block\Edit\Tab\Main.php

And make whatever changes you want to make for example

Here the code would be

class NameSpaceName_ ModuleName_Adminhtml_Block_Edit_Tab_Main
    extends Mage_Adminhtml_Block_Widget_Form
    implements Mage_Adminhtml_Block_Widget_Tab_Interface
{
//make your changes in any of the core fuction
}
The following two tabs change content below.

Chandra Shekhar

GCP Architect
Chandra Shekhar Pandey is Google certified Cloud engineer, I am Magento2 Trained developer. Having huge experience in designing cloud solution. I have around 12 years of experience with world enterprise IT companies and fortune 500 clients. During my architecture design I am always caring about high availability, fast performance and resilient system. From the programmer background I have huge experience in LAMP stack as well. Throughout my carrier I have worked on Retail, E-Learning, Video Conferencing and social media domain. The motive of creating cutehits was just to share the knowledge/solutions I get to know during my day to day life so that if possible I can help someone for same problems/solutions. CuteHits.com is a really a very effort for sharing knowledge to rest of the world. For any query/suggestion about same you can contact me on below details:- Email: shekharmca2005 at gmail.com Phone: +91-9560201363

Latest posts by Chandra Shekhar (see all)

You may also like...