0

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;
    }
}
0

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>
  • Well hot damn. That did not work they way I expected it to work, but thinking about it I guess it makes sense. To others coming here, the lesson is: Models that override core models that you wish to override only need to reference the top level original model in config.xml. – Squiggler Jan 11 '16 at 14:49

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.