1

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

Namespace_Module_Model_Sales_Quote_Address_Total_Profile_Subtotal

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 1.8.1.0

Please help.

UPDATE

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();
        $isReduction=false;
        $product->setCustomerGroupId($quoteItem->getQuote()->getCustomerGroupId());

        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);
        $isReduction=false;
        $itemId=$profileItem->getData('profile_type_id');
        if(Mage::helper('core')->isModuleEnabled('MyModule')){
            $isReduction=true;
            if(!$product->getQty())
                $qty=Mage::getModel('checkout/cart')->getQuote()->getItemsQty();
            else
                $qty=$product->getQty();
            $quantityArray=array();
            $totalOccurrence=Mage::getModel('profile/price')->getTotalOccurrence($itemId);
            $totalBags=$qty*$totalOccurrence;
            $reductionPrice=Mage::getModel('profile/price')->getReducedPrice($totalBags,$product->getId());
        }
        if($isReduction)
            $product->setPrice($reductionPrice);
        else
            $product->setPrice($profileItem->getData('regular_price'));
        $product->setPrice($reductionPrice);
        $product->setSpecialPrice(null);
        $finalPrice = $product->getFinalPrice($quoteItem->getQty());
        $item->setPrice($finalPrice);
        $item->setBaseOriginalPrice($finalPrice);
        $item->calcRowTotal();
        $this->_addAmount($item->getRowTotal());
        $this->_addBaseAmount($item->getBaseRowTotal());
        $address->setTotalQty($address->getTotalQty() + $item->getQty());
        return true;
    }

}
  • show code of Namespace_Module_Model_Sales_Quote_Address_Total_Profile_Subtotal – Amit Bera Jan 2 '15 at 5:34
  • Hello Amit, Please see my update – piyush_systematix Jan 2 '15 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. – Jonathan Hussey Jan 2 '15 at 8:30
  • Yes I want to rewrite it. And want to modify and use function _initItem – piyush_systematix Jan 2 '15 at 8:43
1

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/:

<config>
    <modules>
        <NS_Module>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Other_Extension />
            </depends>
        </NS_Module>
    </modules>
</config>

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

0

You may need to chain these rewrites.

i.e.

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. – piyush_systematix Jan 2 '15 at 8:44
0

You can override it using config.xml.

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

<?xml version="1.0"?>
<config>
    ***
    <global>
        ***
        <sales>
            <quote>
                <totals>
                    <subtotal>
                        <class>namespace_module/sales_quote_address_total_profile_subtotal</class>
                    </subtotal>
                </totals>
            </quote>
        </sales>
        ***
    </global>
    ***
</config>

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.