0

I am using this extension for Extra Fees,

I did some override/rewritein this file in magento (app/code/local/Voronoy/ExtraFee/Model/Quote/Address/Total/Fee/Rule.php).

FYI -> The override/rewrite function working.

I just create Observer for this extension :

My observer :

app/etc/modules/Gta_ExtraFeesRemove.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Gta_ExtraFeesRemove>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Voronoy_ExtraFee/>
            </depends>
        </Gta_ExtraFeesRemove>
    </modules>
</config>

app/code/local/Gta/ExtraFeesRemove/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Gta_ExtraFeesRemove>
        <version>0.1.0</version>
        </Gta_ExtraFeesRemove>
    </modules>
    <global>
        <models>
            <voronoy_extrafee>
                <rewrite>
<quote_address_total_fee_rule>Gta_ExtraFeesRemove_Model_Quote_AddressTotal_Fee_Rule</quote_address_total_fee_rule>
                </rewrite>
            </voronoy_extrafee>
        </models>
    </global>
</config>

app/code/local/Gta/ExtraFeesRemove/Model/Quote/AddressTotal/Fee/Rule.php

<?php


class Gta_ExtraFeesRemove_Model_Quote_AddressTotal_Fee_Rule extends Voronoy_ExtraFee_Model_Quote_Address_Total_Fee_Rule
{
    /**
     * Discount calculation object
     *
     * @var Mage_SalesRule_Model_Validator
     */
    protected $_calculator;
    /**
     * Initialize discount collector
     */
    public function __construct()
    {
        $this->_calculator = Mage::getSingleton('voronoy_extrafee/salesRule_validator');
    }
    /**
     * @param Mage_Sales_Model_Quote_Address $address
     *
     * @return Mage_Sales_Model_Quote_Address_Total_Abstract
     */
    public function collect(Mage_Sales_Model_Quote_Address $address)
    {
        if (!Mage::helper('voronoy_extrafee')->isRuleExtraFeeEnabled()) {
            return $this;
        }
        parent::collect($address);
        $quote = $address->getQuote();
        $shipping_method = $quote->getShippingAddress()->getShippingMethod();
        $current_website = Mage::app()->getWebsite()->getId();

        ### log ###
        Mage::log("ExtraFeesWebsite -".$current_website." website checking part");
        ### log ###


        /* Flat Rate Condition Start*/
        if ($shipping_method != 'flatrate' && $current_website != 2) :
            $store = Mage::app()->getStore($quote->getStoreId());
            $this->_calculator->reset($address);

            $items = $this->_getAddressItems($address);
            if (!count($items)) {
                return $this;
            }

            ### log ###
            Mage::log("FlatRateCondition - ".$items."Flat Rate Condition ");
            ### log ###

            $this->_calculator->init($store->getWebsiteId(), $quote->getCustomerGroupId(), $quote->getCouponCode());
            $this->_calculator->initTotals($items, $address);

            $items = $this->_calculator->sortItemsByPriority($items);
            foreach ($items as $item) {
                if ($item->getParentItemId()) {
                    continue;
                }
                if ($item->getHasChildren() && $item->isChildrenCalculated()) {
                    foreach ($item->getChildren() as $child) {
                        $this->_calculator->process($child);
                        $this->_addAmount($child->getExtraFeeRuleAmount());
                        $this->_addBaseAmount($child->getBaseExtraFeeRuleAmount());
                    }
                } else {
                    $this->_calculator->process($item);
                    $this->_addAmount($item->getExtraFeeRuleAmount());
                    $this->_addBaseAmount($item->getBaseExtraFeeRuleAmount());
                }
            }
            $this->_calculator->prepareDescription($address);

            ### log ###
            Mage::log("FlatRateCondition - ".$items."Flat Rate Condition ");
            ### log ###

        endif;
        // / Flat Rate Condition End /
    }
    /**
     * Fetch Totals
     *
     * @param Mage_Sales_Model_Quote_Address $address
     *
     * @return Voronoy_ExtraFee_Model_Quote_Address_Total_Fee_Rule
     */
    public function fetch(Mage_Sales_Model_Quote_Address $address)
    {
        if (!Mage::helper('voronoy_extrafee')->isRuleExtraFeeEnabled()) {
            return $this;
        }
        $amount = $address->getExtraFeeRuleAmount();
        if ($address->getExtraFeeRuleDescription()) {
            $discountLabel = Mage::helper('voronoy_extrafee')->__(
                '%s (%s)',
                Mage::helper('voronoy_extrafee')->getExtraFeeRuleLabel(),
                $address->getExtraFeeRuleDescription()
            );
        } else {
            $discountLabel = Mage::helper('voronoy_extrafee')->getExtraFeeRuleLabel();
        }
        if ($amount > 0) {
            $address->addTotal(array(
                'code' => $this->getCode(),
                'title' => $discountLabel,
                'value' => $amount
            ));
        }
        return $this;
    }


}

The observer for third party module not working.

FYI -> The changes in core working.

8
  • I think your config.xml file problem. You can replace <model>Gta_ExtraFeesRemove_Model_Quote_AddressTotal_Fee_Rule</model> to <rule>Gta_ExtraFeesRemove_Model_Quote_AddressTotal_Fee_Rule</rule>. After that change please check. I hope it will help you. Commented Aug 20, 2019 at 11:09
  • not working, here is my updated code : paste.ofcode.org/aSSeJ9eiSUirVmyN6pD5mZ
    – zus
    Commented Aug 20, 2019 at 11:15
  • @MonarkBhawani Before that how can i self test my observer class working?
    – zus
    Commented Aug 20, 2019 at 11:18
  • You can die() in your public function of the observer file. If Voronoy_ExtraFee_Model_Quote_Address_Total_Fee_Rule successfully override then you showing your die in that page. Commented Aug 20, 2019 at 11:21
  • How can i add die in my function? paste.ofcode.org/M4hG3ruK9ZkUK9a6WrzCEp
    – zus
    Commented Aug 20, 2019 at 11:44

1 Answer 1

0

The correct way to override the Voronoy_ExtraFee_Model_Quote_Address_Total_Fee_Rule class in config.xml is

<?xml version="1.0"?>
<config>
    <modules>
        <Gta_ExtraFeesRemove>
        <version>0.1.0</version>
        </Gta_ExtraFeesRemove>
    </modules>
    <global>
        <models>
            <voronoy_extrafee>
                <rewrite>
<quote_address_total_fee_rule>Gta_ExtraFeesRemove_Model_Quote_AddressTotal_Fee_Rule</quote_address_total_fee_rule>
                </rewrite>
            </voronoy_extrafee>
        </models>
    </global>
</config>
2
  • Not wokring, pls check my updated post
    – zus
    Commented Aug 21, 2019 at 5:03
  • FYI -> Mage::log("ExtraFeesWebsite -".$current_website." website checking part"); return log message, other logs not return any values
    – zus
    Commented Aug 21, 2019 at 5:09

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.