Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Problem when trying to overload method (new module)
 
Gabriel Queiroz
Sr. Member
 
Total Posts:  135
Joined:  2008-05-28
Brasília, Brazil
 

I’m creating a new module for Cash on Delivery.

This module will only take the shipping info from the customer, so, the payment part is easy, there’s no form at all on the payment info step of checkout.

The tricky part is: It will be more expensive for the customer to get the product using this way (usually the shipping with COD is more expensive). So, when the user selects COD i have to add an user-defined ammount to the grand total of the order.

I’ve looked through the code, and found that one of the methods which calculates this grand total is: Mage_Sales_Model_quote->getTotals(). So I need to overload this method by creating a new class inside my module and declaring it on config.xml.

I did it, but it made no difference at all. I’ve created a class called Mage_Cashondelivery_Model_Quote and created the getTotals() method inside it. Also, I’ve added these lines to config.xml:

...
    <global>
        <
models>
            <
cashondelivery>
                <class>
Mage_Cashondelivery_Model</class>
            </
cashondelivery>
            <
quote>
                <
rewrite>
                    <
quote>Mage_Cashondelivery_Model_Quote</quote>
                </
rewrite>
            </
quote>
        </
models>
...
    </global>
...

Am I doing anything wrong here? Also, will the method always be overloaded, or only when it is enabled?

Many thanks and best regards,

 
Magento Community Magento Community
Magento Community
Magento Community
 
mzentrale1
Guru
 
Total Posts:  731
Joined:  2007-12-06
Stuttgart, Germany
 

Hi,

this:

<quote>
                <
rewrite>
                    <
quote>Mage_Cashondelivery_Model_Quote</quote>
                </
rewrite>
            </
quote>

should be

<sales>
                <
rewrite>
                    <
quote>Mage_Cashondelivery_Model_Quote</quote>
                </
rewrite>
            </
sales>

cheers

Stefan

 
Magento Community Magento Community
Magento Community
Magento Community
 
Gabriel Queiroz
Sr. Member
 
Total Posts:  135
Joined:  2008-05-28
Brasília, Brazil
 

Hi Stefan,

Thanks a lot for your reply, it works now.

So, just to make sure i’ve got the logic on this: on config.xml, the children of the <models> tag are actually modules and not models?
Is there any documentation on this?

Cheers,

 
Magento Community Magento Community
Magento Community
Magento Community
 
mzentrale1
Guru
 
Total Posts:  731
Joined:  2007-12-06
Stuttgart, Germany
 

Hi,

yes you are right. first node is the module and than within rewrite node you declare the model, f.e. to overwrite Mage_Sales_Model_Order_Address you have to set follwoing to your config.xml.

<sales>
                <
rewrite>
                    <
order_address>MyModel</order_address>
                </
rewrite>
 </
sales>

cheers

Stefan

 
Magento Community Magento Community
Magento Community
Magento Community
 
Gabriel Queiroz
Sr. Member
 
Total Posts:  135
Joined:  2008-05-28
Brasília, Brazil
 

Ok, thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Mik3e
Jr. Member
 
Avatar
Total Posts:  27
Joined:  2007-09-29
 

Hi Garbiel,

I’m also working on a COD Module.
My question: In wich method do you add the COD costs?

Thanks & Bye,
Mike

 
Magento Community Magento Community
Magento Community
Magento Community
 
Gabriel Queiroz
Sr. Member
 
Total Posts:  135
Joined:  2008-05-28
Brasília, Brazil
 

Hi,

I got it by overloading the method Mage_Cashondelivery_Model_Quote_Address->getGrandTotal().

I’ve got some strange results, though. But it works. =)

By some strange reason i can’t attach my module to this forum, so, if you need it, give me your e-mail address and I’ll send it to you.

Cheers,

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top