1

I have added new field to the admin form which manages the taxes but I did this by editing the core files themselves.

I would like to adapt this to a separate module so the changes remain after I would update Magento.

This is what I achieved (and what I wanted), just an extra field to have the option not to show any tax information ever "Display tax: Yes/No". (Weird this feature isn't in there by default) I found some tutorials online about how to create a module but it doesn't say how to make the config file of the module to add just one field at a particular spot.

Now I added

<displaytax>0</displaytax>

to the app/code/core/Mage/Tax/etc/config.xml file in the tag.

And added this to the app/code/core/Mage/Tax/etc/system.xml

<displaytax translate="label">
    <label>Display Tax</label>
    <frontend_type>select</frontend_type>
    <source_model>adminhtml/system_config_source_yesno</source_model>
    <sort_order>45</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>1</show_in_store>
</displaytax>

Below the

I also made some adjustments to the Block and Model files, where I added the function to call this variable.

app/code/core/Mage/Tax/Block/Checkout

class Mage_Tax_Block_Checkout_Tax extends Mage_Checkout_Block_Total_Default
{
    protected $_template = 'tax/checkout/tax.phtml';

    /**
     * Check if we have include tax
     *
     * @return bool
     */
    public function displayTax()
    {
        return Mage::getSingleton('tax/config')->displayCartTax($this->getStore());
    }
}

Added to app/code/core/Mage/Tax/Model/Config.php

const XML_PATH_DISPLAY_CART_DISPLAYTAX  = 'tax/cart_display/displaytax';
public function displayCartTax($store = null)
{
    return (bool)Mage::getStoreConfig(self::XML_PATH_DISPLAY_CART_DISPLAYTAX, $store);
}

Of course I made them HTML changes in /app/design/frontend/default/{mytemplate}/template/tax/checkout/tax.phtml

How should I convert this to a module?

How should you add a yes/no field to the admin form in the correct manner? Because this method works but will be overwritten in case of an update. I'd like a more sustainable solution.

1

Add fields to the config

Create your own module and just copy your added nodes from the XML to your config.xml and system.xml.

Model and block changes

The easiest is to rewrite the blocks and models to just add your code. A lot better is, if you find an observer, configuration change, if in a layout.xml or something similiar without killing the default magento logic.

If you rewrite the classes, then you have the problem, that the overwritten method isn't updated.

But it is not as worse as copying the whole classes to app/local/Mage - NEVER do this.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.