I have installed a module which overrides a core class of magento.

class Namespace_Module_Model_Sales_Quote_Address_Total_Profile_Subtotal
    extends Mage_Sales_Model_Quote_Address_Total_Subtotal

As you can see the Subtotal class of sales module is extended. Now I want to extend


I tried some solutions from google but nothing is working.

My main motive is to override function _initItem of class app/code/core/Mage/Sales/Model/Quote/Address/Total/Subtotal.php

And want override/remove functionality of function _initItem of Namespace_Module_Model_Sales_Quote_Address_Total_Profile_Subtotal

I am using Magento

Please help.


class Namespace_Module_Model_Sales_Quote_Address_Total_Profile_Subtotal
    extends Mage_Sales_Model_Quote_Address_Total_Subtotal
    protected $_canAddAmountToAddress = false;
    protected $_itemRowTotalKey = 'rt';
    private $_originalProductPrice = null;

    protected function _initItem($address, $item)
        if ($item instanceof Mage_Sales_Model_Quote_Address_Item) {
            $quoteItem = $item->getAddress()->getQuote()->getItemById($item->getQuoteItemId());
        } else {
            $quoteItem = $item;
        $product = $quoteItem->getProduct();

        if ($item->getQuote()->getIsSuperMode()) {
            if (!$product) {
                return false;
        } else {
            if (!$product || !$product->isVisibleInCatalog()) {
                return false;

        if (null === $this->_originalProductPrice) {
            $this->_originalProductPrice = $product->getPrice();

        $profileTypeOption = Mage::helper('module/quote')->getProfileTypeOptionFromQuoteItem($item);
        $profileItem = Mage::getModel('module/profile_item')->load($profileTypeOption);
        $finalPrice = $product->getFinalPrice($quoteItem->getQty());
        $address->setTotalQty($address->getTotalQty() + $item->getQty());
        return true;

  • show code of Namespace_Module_Model_Sales_Quote_Address_Total_Profile_Subtotal
    – Amit Bera
    Jan 2, 2015 at 5:34
  • Hello Amit, Please see my update Jan 2, 2015 at 5:53
  • When you say you want to extend the class, do you mean you want to rewrite it? It's not clear from the question. Jan 2, 2015 at 8:30
  • Yes I want to rewrite it. And want to modify and use function _initItem Jan 2, 2015 at 8:43

3 Answers 3


To rewrite a rewrite you must define a rewrite of the original class in your module and make your module depend on the module with the existing rewrite. This way, your rewrite definition overrides the original rewrite definition when the config.xml files are merged.

To define the dependency, edit your file in app/etc/modules/:

                <Other_Extension />

And then let your rewritten class extend the rewritten class from Other_Extension.


You may need to chain these rewrites.


Create new module, create a class that inherits from the Original Module's class, e.g.

    class Newmodule_Module_Model_Sales_Quote_Address_Total_Profile_Subtotal 
        extends Namespace_Module_Model_Sales_Quote_Address_Total_Profile_Subtotal{


Then remove the rewrite from the original module's config.xml file.

Now add a new rewrite to your new module's config xml file that overwrites the Mage_Sales_Model_Quote_Address_Total_Subtotal class

  • I don't want to edit original module files. That's why need a rewrite logic. Jan 2, 2015 at 8:44

You can override it using config.xml.

Specify your custom subtotal class by path global>sales>total>subtotal.

<?xml version="1.0"?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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