0

I'm building my first custom module and I think i'm almost there except there seems te be a small error in my code. I tried to overwrite two files from Magento Core.

app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Price.php

and

app/code/core/Mage/Core/Model/Store.php

I created the module folder in app/etc/modules/ With: Vendor_Module.xml

<config>
  <modules>
       <Vendor_Module>
           <active>true</active>
           <codePool>local</codePool>
       </Vendor_Module>
   </modules>
</config>

I created a directory in app/code/local/Vendor/Module With:

Block/Price.php

<?php
require_once(Mage::getModuleDir('Block','Mage_Adminhtml').DS.'/Catalog/Product/Helper/Form/Price.php');

class Vendor_Module_Block_Price extends Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Price {

/**
 * Override the required function here, 
 * e.g. createAction
 */
public function getEscapedValue($index=null)
    {
        $value = $this->getValue();

        if (!is_numeric($value)) {
            return null;
        }

        return number_format($value, 4, null, '');
    }
}

etc/config.xml

<?xml version="1.0"?>
<config>
<modules>
    <Vendor_Module>
        <version>0.0.1</version>
    </Vendor_Module>
</modules>
<global>
    <blocks>
        <Module>
            <class>Atvise_RoundPrices_Block</class>
        </Module>
    </blocks>
    <models>
        <Module>
            <class>Atvise_RoundPrices_Model</class>
        </Module>
    </models>
</global>
</config>

Model/Store.php

<?php
require_once(Mage::getModuleDir('Model','Mage_Core').DS.'Store.php');

class Vendor_Module_Model_Store extends Mage_Core_Model_Store
{
/**
 * Override the required function here, 
 * e.g. createAction
 */
public function roundPrice($price)
{
    return round($price, 4);
}
}

Can you guys help me out for the last bit of code or corrections?

Thanks

1

You will need to update your config.xml to tell Magento to use your classes and not the originals. For your example I would guess something like the following should work.

<global>
    <blocks>
        <adminhtml>
            <rewrite>
                <catalog_product_helper_form_price>Vendor_Module_Block_Price</catalog_product_helper_form_price>
            </rewrite>
        </adminhtml>
    </blocks>
</global>

For a bit more about rewriting classes in Magento 1 I would suggest there is plenty of good further reading such as Inchoo

|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.