Question

I've followed some tutorials and referenced some questions on here yet my problem still festers.

Magento version is CE 1.9.1.1

The company I work for has purchased an extension that overrides Mage_Usa's shipping models. To do things the "right way" I want to override that extension to modify a function.

If I disable the extension that overrides Mage_Usa and just override "usa" model with the appropriate depends, my override works just fine. I'm super stumped.

Here's the extension pertinants (snipped sections) I want to override


/app/etc/modules/Webshopapps_Shipusa.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Webshopapps_Shipusa>
            <active>true</active>
            <codePool>community</codePool>
            <depends>
               <Mage_Shipping />
               <Mage_Usa />
               <Webshopapps_Wsacommon />
           </depends>
        </Webshopapps_Shipusa>
    </modules>
</config>

/app/code/community/Webshopapps/Shipusa/etc/config.xml

<global>
    <models>
        <shipusa>
            <class>Webshopapps_Shipusa_Model</class>
            <resourceModel>shipusa_resource</resourceModel>
        </shipusa>
        <usa>
            <rewrite>
                <shipping_carrier_ups>Webshopapps_Shipusa_Model_Shipping_Carrier_Ups</shipping_carrier_ups>
                <shipping_carrier_usps>Webshopapps_Shipusa_Model_Shipping_Carrier_Usps</shipping_carrier_usps>
                <shipping_carrier_fedex>Webshopapps_Shipusa_Model_Shipping_Carrier_Fedex</shipping_carrier_fedex>
            </rewrite>
        </usa>
    </models>
</global>

/app/code/community/Webshopapps/Shipusa/Model/Shipping/Carrier/Ups.php

class Webshopapps_Shipusa_Model_Shipping_Carrier_Ups
    extends Mage_Usa_Model_Shipping_Carrier_Ups
    implements Mage_Shipping_Model_Carrier_Interface
{
    public function getFinalPriceWithHandlingFee($cost)
    {
        //snip
    }
}

My code that I'm trying to write to override the function getFinalPriceWithHandlingFee


/app/etc/modules/Namespace_Shipusa.xml

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

/app/code/local/Namespace/Shipusa/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Namespace_Shipusa>
            <version>0.1.0</version>
        </Namespace_Shipusa>
    </modules>
    <global>
        <models>
            <namespace_shipusa>
                <class>Namespace_Shipusa_Model</class>
            </namespace_shipusa>
            <shipusa>
                <rewrite>
                  <shipping_carrier_ups>Namespace_Shipusa_Model_Shipping_Carrier_Ups</shipping_carrier_ups>
                </rewrite>
            </shipusa>
        </models>
    </global>
</config>

/app/code/local/Namespace/Shipusa/Model/Shipping/Carrier/Ups.php

<?php

class Namespace_Shipusa_Model_Shipping_Carrier_Ups extends Webshopapps_Shipusa_Model_Shipping_Carrier_Ups
{

    public function getFinalPriceWithHandlingFee($cost)
    {
        file_put_contents('/tmp/muh', 'bye', FILE_APPEND);
        $old_cost = parent::getFinalPriceWithHandlingFee($cost);

        return $old_cost;
    }
}
Was it helpful?

Solution

You were very close. You need to change this in your config.xml

<shipusa>
    <rewrite>
      <shipping_carrier_ups>Namespace_Shipusa_Model_Shipping_Carrier_Ups</shipping_carrier_ups>
    </rewrite>
</shipusa>

to

<usa>
    <rewrite>
      <shipping_carrier_ups>Namespace_Shipusa_Model_Shipping_Carrier_Ups</shipping_carrier_ups>
    </rewrite>
</usa>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top