Magento 1.9 – Override USPS Shipping Method Name

magento-1.9shippingshipping-methodsusps

This is a follow-up of sorts to : shipping method name alias.

The issues I found:
1) the translate.csv works like a charm for UPS shipping. it does NOT work for USPS
2) the change to
escapeHtml($_rate->getMethodTitle()) ?>

works fine, but you have to do it in 14 different locations, thus making maintenance a nightmare.
3) the change suggested in the thread will only affect what is displayed on the screen, not what is in the DB, ergo, not what is emailed to the clients, or exported in reports, etc

what I really want to do is override the value upstream, after the response from USPS is received, before it gets consumed by the application and have that updated value in the database.

I'm wondering if the below, found in app/code/core/Mage/Sales/Model/Quote/Address/Rate.php would be a good place to do it.

public function importShippingRate(Mage_Shipping_Model_Rate_Result_Abstract $rate)
{
    if ($rate instanceof Mage_Shipping_Model_Rate_Result_Error) {
        $this
            ->setCode($rate->getCarrier().'_error')
            ->setCarrier($rate->getCarrier())
            ->setCarrierTitle($rate->getCarrierTitle())
            ->setErrorMessage($rate->getErrorMessage())
        ;
    } elseif ($rate instanceof Mage_Shipping_Model_Rate_Result_Method) {
        $this
            ->setCode($rate->getCarrier().'_'.$rate->getMethod())
            ->setCarrier($rate->getCarrier())
            ->setCarrierTitle($rate->getCarrierTitle())
            ->setMethod($rate->getMethod())
            ->setMethodTitle($rate->getMethodTitle())
            ->setMethodDescription($rate->getMethodDescription())
            ->setPrice($rate->getPrice())
        ;
    }
    return $this;
}

Also, I think that once I use a standardized text, then the translate.csv actually does become active, but that's secondary.

Thanks !

Best Answer

Please replace

->setMethodTitle($rate->getMethodTitle())

with

->setMethodTitle(Mage::helper('shipping')->__($rate->getMethodTitle()))

And add appropriate translations into the Mage_Shipping.csv file.

Related Topic