Magento - How override admin Sales Totals block (M

2019-09-09 14:05发布

问题:

I am trying to override the admin Sales Totals block (Mage_Adminhtml_Block_Sales_Totals) situated under "/app/code/core/Mage/Adminhtml/Block/Sales/Totals.php"

I declare my module like this:

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <CompanyName_Adminhtml>
            <version>0.1.0</version>
        </CompanyName_Adminhtml>
    </modules>

    <global>
        <blocks>

            <companyname_adminhtml>
                <class>CompanyName_Adminhtml_Block_Adminhtml_Sales_Totals</class>
            </companyname_adminhtml>

            <adminhtml>
                <rewrite>
                    <sales_totals>CompanyName_Adminhtml_Block_Adminhtml_Sales_Totals</sales_totals>
                </rewrite>
            </adminhtml>

        </blocks>
    </global>
</config>

My module class path is like this: local/CompanyName_Adminhtml/Block/Adminhtml/Sales/Totals.php

and My class code start like this:

class CompanyName_Adminhtml_Block_Adminhtml_Sales_Totals extends Mage_Adminhtml_Block_Sales_Totals   {
        // block methods goes here..
    }           

Unfortunately the class override don't works and I don't get any errors in the log files. I am using Magento Version 1.7.0.2

In the magento backoffice I can see my module as enabled.

Any help?

回答1:

Try Overriding the individual Totals.php block which is at the location Mage/AdminHtml/Block/Sales/Order/ file rather than the main Totals.php under the Mage/AdminHtml/Block/Sales/ folder.

It worked for me. As i wanted to show one more row in the order-totals block.



回答2:

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <CompanyName_Adminhtml>
            <version>0.1.0</version>
        </CompanyName_Adminhtml>
    </modules>

    <global>
        <blocks>
           <companyName_adminhtml>
                <class>CompanyName_Adminhtml_Block</class>
            </companyName_adminhtml>
            <companyname_adminhtml>
                <class>CompanyName_Adminhtml_Block_Adminhtml_Sales_Totals</class>
            </companyname_adminhtml>

            <adminhtml>
                <rewrite>
                    <sales_order_totals>CompanyName_Adminhtml_Block_Adminhtml_Sales_Totals</sales_totals>
                </rewrite>
            </adminhtml>

        </blocks>
    </global>
</config>


then class 
class CompanyName_Adminhtml_Block_Adminhtml_Sales_Order_Totalsextends Mage_Adminhtml_Block_Sales_Order_Totals {

    protected function _initTotals() {
        parent::_initTotals();

        $this->_totals['foo_total'] = new Varien_Object(array(
            'code'      => 'purchasewrapping_total',
            'value'     => $this->getSource()->getFooTotal(),
            'base_value'=> $this->getSource()->getBaseFooTotal(),
            'label'     => $this->helper('sales')->__('Foo'),
        ));
        return $this;
    }

}`enter code here`
Mage_Adminhtml_Block_Sales_Order_Totals  is extends at Mage_Adminhtml_Block_Sales_Totals
and here you can extend and write your changes