a
d

WE ARE BRUNN

Let’s Work Together

Image Alt

Creatuity

UPS Negotitated Rates and Magento

We’re in the process of implementing Magento for another client and throughout the process I’ve been finding information scattered here and there about various pitfalls and problems that may come up when migrating an e-commerce site to Magento. I’m going to start posting them to the blog so that not only can our team find the answers, workarounds and fixes for these Magento issues quickly and easily in the future, but hopefully it’ll save someone else out there quite a bit of time banging their head on their keyboard trying to diagnose these problems!

We’re having trouble getting UPS rates to work via the XML interface; they worked great via Magento’s default UPS integration, but this particular customer needed integration via the XML interface so that they could pull their negotiated rates from UPS.

To do this, you change the API type to UPS XML in the Config section of Magento. However, there’s a few “gotchas”, as documented in this forum post – first of all, the URL’s that Magento uses by default are old and deprecated. The new URL’s should be:

Rates: https://onlinetools.ups.com/ups.app/xml/Rate

Tracking: https://onlinetools.ups.com/ups.app/xml/Track

Second, according to that post, there may be issues with the UPS SSL certificate on that server. I don’t see any issues here, but if you encounter problems, the workaround recommended by that developer is to add the following two lines just about both places “$xmlResponse = curl_exec($ch);” appears in app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups.php” – the lines to add are:

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

I am NOT a fan of this workaround, since it disables the checks to ensure the SSL certificate the server you have connected to is valid and you haven’t been connected to an imposter.

Finally, after changing the XML URLs, we were still having trouble. By default, Magento does very little logging, but if you have logging enabled and the directory var/log exists and is writeable by your webserver’s user, you can send your own output to the Magento log with the command Mage::log(); i.e., Mage::log(“This is an error! ” . $error);

We added Mage::log($xmlResponse); after the call to curl in app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups.php and discovered the following response from UPS in our log:

<ErrorDescription>Packages must weigh more than zero pounds.</ErrorDescription>

Apparently the items in the user’s cart had a weight of 0.01, which Magento was sending as 0.01 but UPS wasseeing as 0. A quick hack in app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups.php fixed this, by defaulting any package weighing less than 1 pound to a weight of 1 pound.

Specifically, we changed this code:

protected function _getXmlQuotes()
{
$url = $this->getConfigData(‘gateway_xml_url’);

$this->setXMLAccessRequest();
$xmlRequest=$this->_xmlAccessRequest;

$r = $this->_rawRequest;
$params = array(
‘accept_UPS_license_agreement’ => ‘yes’,
’10_action’      => $r->getAction(),
’13_product’     => $r->getProduct(),
’14_origCountry’ => $r->getOrigCountry(),
’15_origPostal’  => $r->getOrigPostal(),
‘origCity’       => $r->getOrigCity(),
‘origRegionCode’ => $r->getOrigRegionCode(),
’19_destPostal’  => $r->getDestPostal(),
’22_destCountry’ => $r->getDestCountry(),
‘destRegionCode’ => $r->getDestRegionCode(),
’23_weight’      => $r->getWeight(),
’47_rate_chart’  => $r->getPickup(),
’48_container’   => $r->getContainer(),
’49_residential’ => $r->getDestType(),
);

To this (changes in bold)…

protected function _getXmlQuotes()
{
$url = $this->getConfigData(‘gateway_xml_url’);

$this->setXMLAccessRequest();
$xmlRequest=$this->_xmlAccessRequest;

$r = $this->_rawRequest;
$weight = $r->getWeight();
if ( ($weight < 1) OR (is_null($weight)) )
$weight = 1;

$params = array(
‘accept_UPS_license_agreement’ => ‘yes’,
’10_action’      => $r->getAction(),
’13_product’     => $r->getProduct(),
’14_origCountry’ => $r->getOrigCountry(),
’15_origPostal’  => $r->getOrigPostal(),
‘origCity’       => $r->getOrigCity(),
‘origRegionCode’ => $r->getOrigRegionCode(),
’19_destPostal’  => $r->getDestPostal(),
’22_destCountry’ => $r->getDestCountry(),
‘destRegionCode’ => $r->getDestRegionCode(),
’23_weight’      => $weight,
’47_rate_chart’  => $r->getPickup(),
’48_container’   => $r->getContainer(),
’49_residential’ => $r->getDestType(),
);

Hope you found this helpful! If you still have trouble, leave a question in the comments and we’ll try to help out as best we can.

Comments

  • J Batteas

    June 16, 2009

    How do you use the core UPS module to calculate Dimensional Weight? I see where you can choose ‘Customer Packaging’ in the configuration, but is there anywhere/way to assign H/W/L to the packaging so you are sure to get accurate shipping rates before automatically charging your customers with potentially wrong shipping rates? Any help or insight would be VERY much appreciated

  • Garrett

    August 7, 2009

    Not only can I not get the xml module to work, but the UPS calculator (which up until today worked for Canada) will only calculate shipping prices in the United States.

  • Don

    September 3, 2009

    Can you pass along any tips on how to use specific UPS shipping methods during US Summer months? I only want to allow 1 and 2 day air during warm months, due to possible product meltage. Any help would be greatly appreciated.

  • September 14, 2009

    We are having the same problem as Garret, store is located in Spain and the only way we get the ups to work is setting the Origin to USA!!

  • November 2, 2009

    This was exactly what I was looking for.All my client’s products were less than a pound so nothing was going through. Thanks for posting this.

  • November 5, 2009

    Hello all, after several days configuring ups, usps and paypal standar I finally had success, but I have a little problem:

    What is the process to registre the ship on UPS and USPS?
    How to and where to print the label for the box?
    Where I get the shipping tracking ID?
    Does the system automatically sends the tracking ID to the customer?

    Well, for this question there aren’t currently manual on the internet forums or I have not found any, please can you help me with this. this is very important for all that no have experience with magento commerce.

  • Gil

    March 5, 2010

    Josh,

    It worked successfully and thank you for posting the tip. Your instructions very clear which is great.

  • Passatb5

    March 5, 2010

    josh im having trouble inputting the curls, where is it that i plug in those codes?

  • creatuity

    March 5, 2010

    All of those edits should be made in app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups.php

  • Passatb5

    March 5, 2010

    how do i get to “app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups.php” ??

    thank you.

  • creatuity

    March 5, 2010

    You'll need to use your FTP program to download that file and edit it, or edit it directly on the server via SSH if you're familiar with that.

  • Passatb5

    March 5, 2010

    where do i go to edit? how do i get to
    app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups.php ? thank you

  • Passatb5

    March 5, 2010

    no im not very familiar with any of this lol. its very frustrating ive been
    here all day trying to do this.

  • IBDuser

    March 5, 2010

    You have to get into web hosting account. Go to “File Manager”. Search for the app/code/core/Mage/Usa/Model/Shipping/Carrier/path. Once, you have found it, find “ups.php”.

    Download the file to your local machine.

    Using an editor on your local machine, find the locations shown on referenced document. Cut/paste exact code into locations.
    After you have completed all changes, Save.

    Go back to File Manager, rename “ups.php” to “upsOriginal.php”.

    Now upload changed ups.php from local machine up to your server.
    Save the file.

    Now, go to your website and test the operation of your UPS rating interface.

    If it works, you are golden. Otherwise, if it does not work, really examine the changes to ensure you've done it properly. Make corrections as necessary.

  • creatuity

    March 5, 2010

    Thank you so much for the detailed instructions – I'm sure that'll help a ton of people! Thanks for taking the time to type those up!

  • IBDuser

    March 5, 2010

    You have to get into web hosting account. Go to “File Manager”. Search for the app/code/core/Mage/Usa/Model/Shipping/Carrier/path. Once, you have found it, find “ups.php”.

    Download the file to your local machine.

    Using an editor on your local machine, find the locations shown on referenced document. Cut/paste exact code into locations.
    After you have completed all changes, Save.

    Go back to File Manager, rename “ups.php” to “upsOriginal.php”.

    Now upload changed ups.php from local machine up to your server.
    Save the file.

    Now, go to your website and test the operation of your UPS rating interface.

    If it works, you are golden. Otherwise, if it does not work, really examine the changes to ensure you've done it properly. Make corrections as necessary.

  • creatuity

    March 5, 2010

    Thank you so much for the detailed instructions – I'm sure that'll help a ton of people! Thanks for taking the time to type those up!

  • Passatb5

    March 5, 2010

    josh im having trouble inputting the curls, where is it that i plug in those codes?

  • creatuity

    March 5, 2010

    All of those edits should be made in app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups.php

  • Passatb5

    March 5, 2010

    how do i get to “app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups.php” ??

    thank you.

  • creatuity

    March 5, 2010

    You'll need to use your FTP program to download that file and edit it, or edit it directly on the server via SSH if you're familiar with that.

  • Passatb5

    March 5, 2010

    where do i go to edit? how do i get to
    app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups.php ? thank you

  • Passatb5

    March 5, 2010

    no im not very familiar with any of this lol. its very frustrating ive been
    here all day trying to do this.

  • IBDuser

    March 6, 2010

    You have to get into web hosting account. Go to “File Manager”. Search for the app/code/core/Mage/Usa/Model/Shipping/Carrier/path. Once, you have found it, find “ups.php”.

    Download the file to your local machine.

    Using an editor on your local machine, find the locations shown on referenced document. Cut/paste exact code into locations.
    After you have completed all changes, Save.

    Go back to File Manager, rename “ups.php” to “upsOriginal.php”.

    Now upload changed ups.php from local machine up to your server.
    Save the file.

    Now, go to your website and test the operation of your UPS rating interface.

    If it works, you are golden. Otherwise, if it does not work, really examine the changes to ensure you've done it properly. Make corrections as necessary.

  • creatuity

    March 6, 2010

    Thank you so much for the detailed instructions – I'm sure that'll help a ton of people! Thanks for taking the time to type those up!

  • August 16, 2011

    do you have a fix for negotiated rates?  It’s not pulling the proper rates.

  • August 16, 2011

    We’d have to take a look at your site, but if it’s not pulling negotiated rates make sure you’ve entered your UPS account info correctly. 

Add Comment