Jump to content
Latest News: (loading..)
greasemonkey

FedEx - Web Services v9

Recommended Posts

@Irin

I've modified my file a lot, but you can try my change below.  I used to receive notice level errors, but never a failure error on this, so you may have something else wrong causing a problem that just shows up here.  Find starting around line 302

      foreach ($response->RateReplyDetails as $rateReply)
      {
        if (array_key_exists($rateReply->ServiceType, $this->types) && ($method == '' || str_replace('_', '', $rateReply->ServiceType) == $method))
        {
          if(MODULE_SHIPPING_FEDEX_WEB_SERVICES_RATES=='LIST')
          {
            foreach($rateReply->RatedShipmentDetails as $ShipmentRateDetail)
            {
              if($ShipmentRateDetail->ShipmentRateDetail->RateType=='PAYOR_LIST_PACKAGE')
              {
                $cost = $ShipmentRateDetail->ShipmentRateDetail->TotalNetCharge->Amount;
                $cost = (float)round(preg_replace('/[^0-9.]/', '',  $cost), 2);
              }
            }
          }
          else
          {
            $cost = $rateReply->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount;
            $cost = (float)round(preg_replace('/[^0-9.]/', '',  $cost), 2);
          }
          if (in_array($rateReply->ServiceType, array('GROUND_HOME_DELIVERY', 'FEDEX_GROUND', 'INTERNATIONAL_GROUND'))) {
      // print_r($rateReply);
            $transitTime = ' (' . str_replace(array('_', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteeen'), array(' ', 1,2,3,4,5,6,7,8,9,10,11,12,13,14), strtolower($rateReply->TransitTime)) . ')';
          }
          $methods[] = array('id' => str_replace('_', '', $rateReply->ServiceType),                                                   
                             'title' => ucwords(strtolower(str_replace('_', ' ', $rateReply->ServiceType))) . $transitTime,     
                             'cost' => $cost + (strpos($this->types[$rateReply->ServiceType]['handling_fee'], '%') ? ($cost * (float)$this->types[$rateReply->ServiceType]['handling_fee'] / 100) : (float)$this->types[$rateReply->ServiceType]['handling_fee']));
        }
      }

and change it to

            foreach ($response->RateReplyDetails as $rateReply) {
                if (in_array($rateReply->ServiceType, $this->types) && ($method == '' || str_replace('_', '', $rateReply->ServiceType) == $method)) {
                    $cost = $rateReply->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount;
                    $cost = (float) round(preg_replace('/[^0-9.]/', '', $cost), 2);
                    $methods[] = array('id' => str_replace('_', '', $rateReply->ServiceType),
                            'title' => ucwords(strtolower(str_replace('_', ' ', $rateReply->ServiceType))),
                            'cost' => $cost + $this->handling_fee);
                }
            }

 


I'm not really a dog.

Share this post


Link to post
Share on other sites
1 hour ago, John W said:

@Irin

I've modified my file a lot, but you can try my change below.  I used to receive notice level errors, but never a failure error on this, so you may have something else wrong causing a problem that just shows up here.  Find starting around line 302


      foreach ($response->RateReplyDetails as $rateReply)
      {
        if (array_key_exists($rateReply->ServiceType, $this->types) && ($method == '' || str_replace('_', '', $rateReply->ServiceType) == $method))
        {
          if(MODULE_SHIPPING_FEDEX_WEB_SERVICES_RATES=='LIST')
          {
            foreach($rateReply->RatedShipmentDetails as $ShipmentRateDetail)
            {
              if($ShipmentRateDetail->ShipmentRateDetail->RateType=='PAYOR_LIST_PACKAGE')
              {
                $cost = $ShipmentRateDetail->ShipmentRateDetail->TotalNetCharge->Amount;
                $cost = (float)round(preg_replace('/[^0-9.]/', '',  $cost), 2);
              }
            }
          }
          else
          {
            $cost = $rateReply->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount;
            $cost = (float)round(preg_replace('/[^0-9.]/', '',  $cost), 2);
          }
          if (in_array($rateReply->ServiceType, array('GROUND_HOME_DELIVERY', 'FEDEX_GROUND', 'INTERNATIONAL_GROUND'))) {
      // print_r($rateReply);
            $transitTime = ' (' . str_replace(array('_', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteeen'), array(' ', 1,2,3,4,5,6,7,8,9,10,11,12,13,14), strtolower($rateReply->TransitTime)) . ')';
          }
          $methods[] = array('id' => str_replace('_', '', $rateReply->ServiceType),                                                   
                             'title' => ucwords(strtolower(str_replace('_', ' ', $rateReply->ServiceType))) . $transitTime,     
                             'cost' => $cost + (strpos($this->types[$rateReply->ServiceType]['handling_fee'], '%') ? ($cost * (float)$this->types[$rateReply->ServiceType]['handling_fee'] / 100) : (float)$this->types[$rateReply->ServiceType]['handling_fee']));
        }
      }

and change it to


            foreach ($response->RateReplyDetails as $rateReply) {
                if (in_array($rateReply->ServiceType, $this->types) && ($method == '' || str_replace('_', '', $rateReply->ServiceType) == $method)) {
                    $cost = $rateReply->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount;
                    $cost = (float) round(preg_replace('/[^0-9.]/', '', $cost), 2);
                    $methods[] = array('id' => str_replace('_', '', $rateReply->ServiceType),
                            'title' => ucwords(strtolower(str_replace('_', ' ', $rateReply->ServiceType))),
                            'cost' => $cost + $this->handling_fee);
                }
            }

 

With this change, the error is gone but so are the FedEx rates. It's not showing any rates at all.

Share this post


Link to post
Share on other sites

You have a problem somewhere else.  I think you're not getting rates returned. Has this worked for you at all?  Are you working on a test server?  If you are working on a test server you can find this line

        $response = $client->getRates($request);

and change it to this

  var_dump($request['RequestedShipment']['RequestedPackageLineItems']);

        $response = $client->getRates($request);

  var_dump($response);

The first var_dump will show what you're sending and the second one will show you what they return.  I have a bunch of those that I experimented with when I was trying to solve a problem.


I'm not really a dog.

Share this post


Link to post
Share on other sites

This always worked fine for me until recently. The problem is with that line that I referenced above. I'm working on the production server.

Share this post


Link to post
Share on other sites

Something has changed if this just stopped working.  Maybe your host upgraded something.  You can see in recent posts a soap error cause by an OpenSSL change.

You can use the var_dump to output what's being returned so you can see it, but the line that it errors on isn't necessarily where the problem is.  You can Google "Cannot use object of type stdClass" and get a lot of info on it as it's a php error.


I'm not really a dog.

Share this post


Link to post
Share on other sites

When I run the two test below after getRates I get  true for is_array and false for is_object

  var_dump(is_array($response->RateReplyDetails));
  var_dump(is_object($response->RateReplyDetails));

You can use soem of these to see what's being returned by uncommenting them.  It's best to have a test server.

//  var_dump(property_exists('fedexwebservices','RateReplyDetails'));
//  var_dump(null !== ('RateReplyDetails'));
//  var_dump(!empty($RateReplyDetails));
//  var_dump(isset($response->RateReplyDetails));
//  var_dump(is_array($response->RateReplyDetails));
//  var_dump(is_object($response->RateReplyDetails));
//  var_dump($response);

 


I'm not really a dog.

Share this post


Link to post
Share on other sites
3 hours ago, John W said:

When I run the two test below after getRates I get  true for is_array and false for is_object


  var_dump(is_array($response->RateReplyDetails));
  var_dump(is_object($response->RateReplyDetails));

You can use soem of these to see what's being returned by uncommenting them.  It's best to have a test server.


//  var_dump(property_exists('fedexwebservices','RateReplyDetails'));
//  var_dump(null !== ('RateReplyDetails'));
//  var_dump(!empty($RateReplyDetails));
//  var_dump(isset($response->RateReplyDetails));
//  var_dump(is_array($response->RateReplyDetails));
//  var_dump(is_object($response->RateReplyDetails));
//  var_dump($response);

 

The two tests returned the following:

Quote

array(1) { [0]=> array(1) { ["Weight"]=> array(2) { ["Value"]=> float(0.5) ["Units"]=> string(2) "LB" } } } bool(true) bool(false)
Fatal error: Uncaught Error: Cannot use object of type stdClass as array in /public_html/site/includes/modules/shipping/fedexwebservices.php:318 Stack trace: #0 /public_html/site/includes/classes/shipping.php(81): fedexwebservices->quote('') #1 /public_html/site/checkout_shipping.php(185): shipping->quote() #2 {main} thrown in /public_html/site/includes/modules/shipping/fedexwebservices.php on line 318

 

Share this post


Link to post
Share on other sites
3 hours ago, John W said:

Something has changed if this just stopped working.  Maybe your host upgraded something.  You can see in recent posts a soap error cause by an OpenSSL change.

You can use the var_dump to output what's being returned so you can see it, but the line that it errors on isn't necessarily where the problem is.  You can Google "Cannot use object of type stdClass" and get a lot of info on it as it's a php error.

I did google a lot about this error, but unfortunately, I couldn't find a solution. That's why I decided to post here in hopes that maybe someone else, smarter than me in php, could help me.

Share this post


Link to post
Share on other sites

I wish I could help you more with this, but I'm sorry I don't have the answer.  However, when you find the answer, please post so we can learn.


I'm not really a dog.

Share this post


Link to post
Share on other sites

I changed the rate to List, and the error is gone. I'm getting the fedex rates now. So, the problem is somewhere in the code for the account rates:

else // For ACCOUNT Discounted Rates, calculate the cost as below
          {
            $cost = ($rateReply->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount)/MODULE_SHIPPING_FEDEX_WEB_SERVICES_CURRENCY;
            $cost = (float)round(preg_replace('/[^0-9.]/', '',  $cost), 2);
          } // For ACCOUNT Discounted Rates, END

    $transitTime = ''; // 9.4.6
          if (in_array($rateReply->ServiceType, array('GROUND_HOME_DELIVERY', 'FEDEX_GROUND', 'INTERNATIONAL_GROUND'))) {
            $transitTime = ' (' . str_replace(array('_', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteeen'), array(' ', 1,2,3,4,5,6,7,8,9,10,11,12,13,14), strtolower($rateReply->TransitTime)) . ')';
          }

          if (isset($rateReply->DeliveryTimestamp)) {
         // $transitTime = ' (Estimated Delivery on: ' . date('l, F jS Y \a\t g:ia', strtotime($rateReply->DeliveryTimestamp)) . ') ';
          $transitTime = ' (Estimated Delivery Date: ' . date('l, F jS Y', strtotime($rateReply->DeliveryTimestamp)) . ') ';
          }

                           	 $methods[] = array('id' => str_replace('_', '', $rateReply->ServiceType),
                             'title' => ucwords(strtolower(str_replace('_', ' ', $rateReply->ServiceType))) . $transitTime,
                             'cost' => $cost + (strpos($this->types[$rateReply->ServiceType]['handling_fee'], '%') ? ($cost * (float)$this->types[$rateReply->ServiceType]['handling_fee']/100) : (float)$this->types[$rateReply->ServiceType]['handling_fee']));
                      //     }

        }
      }

 

Share this post


Link to post
Share on other sites

Irin, this worked for me, i removed the code, and it fixed my OSCMAX checkout - i was getting a blank checkout with PHP 5.4 upgrade from PHP 5.3

using your code works great, no more blank page !!!

 

            foreach ($response->RateReplyDetails as $rateReply) {
                if (in_array($rateReply->ServiceType, $this->types) && ($method == '' || str_replace('_', '', $rateReply->ServiceType) == $method)) {
                    $cost = $rateReply->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount;
                    $cost = (float) round(preg_replace('/[^0-9.]/', '', $cost), 2);
                    $methods[] = array('id' => str_replace('_', '', $rateReply->ServiceType),
                            'title' => ucwords(strtolower(str_replace('_', ' ', $rateReply->ServiceType))),
                            'cost' => $cost + $this->handling_fee);
                }
            }

fedexwebservices.php

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×