Forums / Built-in Shipping and Payment Modules / Conditional shipping option?

Conditional shipping option?

Results 1 to 20 of 64
26 Oct 2013, 22:11
#1
split63 avatar

split63

Totally Zenned

Join Date:
May 2010
Posts:
513
Plugin Contributions:
0

Conditional shipping option?

Is there a way I can control which shipping options are presented based on the shipping costs of FedEx.

Normally we only offer FedEx for International. Shipping averages around $23. However for some destinations, the shipping can be $50-70. For FedEx costs > $40, I would like the USPS first Class option to appear with the FedEx option. For FedEx costs < $40, only the FedEx option should appear.

The reason for this is that USPS FC international is slow and unreliable and we want to avoid it unless the FedEx cost is simply too high.
02 Nov 2013, 16:02
#2
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Posts:
62,757
Plugin Contributions:
1

Re: Conditional shipping option?

This is what FedEx and USPS shows at 13oz ...

[TABLE="width: 100%"]
[TR]
[TD]FedEx (1 x 0.81lbs) (International Priority)[/TD]
         [TD="class: cartTotalDisplay"]$75.18[/TD]
       [/TR]
     [TR]
         [TD]FedEx (1 x 0.81lbs) (International Economy)[/TD]
         [TD="class: cartTotalDisplay"]$71.47[/TD]
       [/TR]
     [TR]
         [TD]FedEx (1 x 0.81lbs) (Fedex Ground (2 days))[/TD]
         [TD="class: cartTotalDisplay"]$19.70[/TD]
       [/TR]
     [TR]
          [TD="class: bold"]United States Postal Service (1 Boxes)  (0 lbs, 13 oz) (First-Class Mail® International Large Envelope)[/TD]
          [TD="class: cartTotalDisplay bold"]$5.25[/TD]
        [/TR]
     [TR]
         [TD]United States Postal Service (1 Boxes)  (0 lbs, 13 oz) (First-Class Package International Service™)[/TD]
         [TD="class: cartTotalDisplay"]$9.50[/TD]
       [/TR]
     [TR]
         [TD]United States Postal Service (1 Boxes)  (0 lbs, 13 oz) (Priority Mail International® Flat Rate Envelope)[/TD]
         [TD="class: cartTotalDisplay"]$19.95[/TD]
       [/TR]
     [TR]
         [TD]United States Postal Service (1 Boxes)  (0 lbs, 13 oz) (Priority Mail International®)[/TD]
         [TD="class: cartTotalDisplay"]$27.40[/TD]
       [/TR]
     [TR]
         [TD]United States Postal Service (1 Boxes)  (0 lbs, 13 oz) (Priority Mail Express International™ Flat Rate Envelope)[/TD]
         [TD="class: cartTotalDisplay"]$34.95[/TD]
       [/TR]
     [TR]
         [TD]United States Postal Service (1 Boxes)  (0 lbs, 13 oz) (Priority Mail Express International™)[/TD]
         [TD="class: cartTotalDisplay"]$35.48[/TD]
       [/TR]
     [TR]
         [TD]United States Postal Service (1 Boxes)  (0 lbs, 13 oz) (Priority Mail International® Medium Flat Rate Box)[/TD]
         [TD="class: cartTotalDisplay"]$40.95[/TD]
       [/TR]
     [TR]
         [TD]United States Postal Service (1 Boxes)  (0 lbs, 13 oz) (Priority Mail International® Large Flat Rate Box)[/TD]
         [TD="class: cartTotalDisplay"]$53.95[/TD]
       [/TR]
     [TR]
         [TD]United States Postal Service (1 Boxes)  (0 lbs, 13 oz) (Global Express Guaranteed® (GXG))[/TD]
         [TD="class: cartTotalDisplay"]$55.41[/TD]
       [/TR]
     [TR]
         [TD]United States Postal Service (1 Boxes)  (0 lbs, 13 oz) (USPS GXG™ Envelopes)[/TD]
         [TD="class: cartTotalDisplay"]$55.41[/TD]
       [/TR]
     [TR]
         [TD]United States Postal Service (1 Boxes)  (0 lbs, 13 oz) (Priority Mail Express International™ Flat Rate Boxes)[/TD]
         [TD="class: cartTotalDisplay"]$64.95[/TD]
[/TR]
[/TABLE]


What Ship To, Ship From and Weight are you testing with?

What do you want to see differently on these costs?
02 Nov 2013, 17:35
#3
split63 avatar

split63

Totally Zenned

Join Date:
May 2010
Posts:
513
Plugin Contributions:
0

Re: Conditional shipping option?

The weight is always 2lbs or less, and typically 13 oz.
The from is USA, the to is any international destination.
If price > $40, show USPS first class and FedEx option, else show FedEx option on the shopping cart page and on the checkout page.
Said differently, if price <=$40, only show FedEx option
02 Nov 2013, 18:58
#4
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Posts:
62,757
Plugin Contributions:
1

Re: Conditional shipping option?

Try this ...

Customize the file:
/includes/modules/shipping/fedexwebservices.php

with the code in RED:
        $methods = array();
// bof: check FedEx for > 40.00
        $_SESSION['usps_first_class'] = 0;
        foreach ($response->RateReplyDetails as $rateReply) {


              $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']));
$chk_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']));
if ($_SESSION['usps_first_class'] == 0 || $chk_cost < $_SESSION['usps_first_class']) {
  $_SESSION['usps_first_class'] = $chk_cost;
}
//echo 'FedEx Cost Calc: ' . $chk_cost . ' $_SESSION[usps_first_class]: ' . $_SESSION['usps_first_class'] . '<br><br>';
// bof: check FedEx for > 40.00
            }
          }
        }
        $this->quotes['methods'] = $methods;


Then customize the file:
/includes/modules/shipping/usps.php
          if ($this->usps_countries == 'US' && MODULE_SHIPPING_USPS_FIRST_CLASS_FILTER_US == 'True' && preg_match('#First\-Class#i', $type) && $cnt_first > 1) continue;
// bof: check FedEx for > 40.00
//echo 'USPS FedEx $_SESSION[usps_first_class]: ' . $_SESSION['usps_first_class'] . ' $type: ' . $type . '<br>';
//echo 'USPS $type_rebuilt: ' . $type_rebuilt . '<br>';
if (preg_match('#(first-class)#i', $type_rebuilt) && $_SESSION['usps_first_class'] > 40) {
          $methods[] = array('id' => $type_rebuilt,
                             'title' => $title,
                             'cost' => $cost,
                            );
}
// eof: check FedEx for > 40.00
        } else {
//echo 'MISSING! USPS $type: ' . $type . (in_array($type, $this->typeCheckboxesSelected) ? ' YES' : ' NO') . ' $method: ' . $method . ' $usps_shipping_weight: ' . $usps_shipping_weight . ' $minweight: ' . $minweight . ' $maxweight: ' . $maxweight . '<br>';
        }
      }  // end for $i to $PackageSize

      if (sizeof($methods) == 0) return false;


Be sure that on the Modules ... Shipping ... that you set a Sort Order on FedEx such as 10 and on USPS a Sort Order of 20 so that FedEx runs before USPS for this to work ...
03 Nov 2013, 16:32
#5
split63 avatar

split63

Totally Zenned

Join Date:
May 2010
Posts:
513
Plugin Contributions:
0

Re: Conditional shipping option?

Ajeh,

That seems to work...thanks.

When both FedEx and USPS options show, the USPS option is by default selected. Is there a way I can make FedEx the default, or better yet, neither checked?


Also, the message for USPS is:
United States Postal Service (First-Class Package International Service™)

How can I change this to:
United States Postal Service (First-Class 7-20 days)

Can a hyperlink be inserted into that text?
03 Nov 2013, 16:41
#6
split63 avatar

split63

Totally Zenned

Join Date:
May 2010
Posts:
513
Plugin Contributions:
0

Re: Conditional shipping option?

I spoke to soon.
For the US, we offer only USPS priority. When I checked a US location, the shopping cart no longer listed a value for USPS priority....it was just missing with no rate estimate at all.

This is most likely my fault for lack of full disclosure

USA locations: USPS priority only
International locations: FedEx<$40, then FedEx only. FedEx>=$40, USPS FC and FedEx
03 Nov 2013, 16:53
#7
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Posts:
62,757
Plugin Contributions:
1

Re: Conditional shipping option?

You could use the CUSTOM setting:
USPS Domestic Transit Time Calculation Mode
Select from the following the USPS options.
note: NEW and OLD will add additional time to quotes. CUSTOM allows your custom shipping days.

CUSTOM
NEW
OLD


and show the days by turning on the:
Display transit time


Then, in the function parseIntlTransitTimeResults($Package, $service) you will see where the days can be customized ...
03 Nov 2013, 17:02
#8
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Posts:
62,757
Plugin Contributions:
1

Re: Conditional shipping option?

split63:

I spoke to soon.
For the US, we offer only USPS priority. When I checked a US location, the shopping cart no longer listed a value for USPS priority....it was just missing with no rate estimate at all.

This is most likely my fault for lack of full disclosure

USA locations: USPS priority only
International locations: FedEx<$40, then FedEx only. FedEx>=$40, USPS FC and FedEx


The name to allow can be changed in the:
/includes/modules/shipping/usps.php
if (preg_match('#Priority Mail International#i', $type_rebuilt) && $_SESSION['usps_first_class'] > 40) {


while the session variable is reading usps_first_class it is just a marker so its name is not important, but for clarity you might change it in both files to:
$_SESSION['usps_priority']

that is up to you ...
03 Nov 2013, 17:03
#9
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Posts:
62,757
Plugin Contributions:
1

Re: Conditional shipping option?

Are you wanting USPS to show when the Ship to is to a US address? Or just on those Ship to for International addresses?
03 Nov 2013, 17:07
#10
split63 avatar

split63

Totally Zenned

Join Date:
May 2010
Posts:
513
Plugin Contributions:
0

Re: Conditional shipping option?

Ajeh:

Are you wanting USPS to show when the Ship to is to a US address? Or just on those Ship to for International addresses?


USA locations: USPS priority only
International locations: FedEx<$40, then FedEx only. FedEx>=$40, USPS FC and FedEx
03 Nov 2013, 17:39
#11
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Posts:
62,757
Plugin Contributions:
1

Re: Conditional shipping option?

To change the USPS shipping module to show for ALL of the Ship To US and filter on the FedEx conditions, change the IF to read:
if ($this->usps_countries == 'US' || preg_match('#Priority Mail International#i', $type_rebuilt) && $_SESSION['usps_first_class'] > 40) {
03 Nov 2013, 22:08
#12
split63 avatar

split63

Totally Zenned

Join Date:
May 2010
Posts:
513
Plugin Contributions:
0

Re: Conditional shipping option?

Ajeh:

To change the USPS shipping module to show for ALL of the Ship To US and filter on the FedEx conditions, change the IF to read:
if ($this->usps_countries == 'US' || preg_match('#Priority Mail International#i', $type_rebuilt) && $_SESSION['usps_first_class'] > 40) {



Ajeh,

I replaced the if statement in usps.php with the statement above and the USPS First Class is never displayed and no error is displayed.

Also, in the fedexwebservices.php, there is an extra } after the added code.
03 Nov 2013, 22:36
#13
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Posts:
62,757
Plugin Contributions:
1

Re: Conditional shipping option?

I think I mis-understood you on what your were saying on Priority ...

If you want USPS International First Class only when FedEx is > 40.00 and for Domestic to show all USPS that you have selected, then use:
if ($this->usps_countries == 'US' || (preg_match('#(first-class)#i', $type_rebuilt) && $_SESSION['usps_first_class'] > 40)) {


I am not understanding what you are saying about the extra } in the FedEx code ... :lookaroun
03 Nov 2013, 23:13
#14
split63 avatar

split63

Totally Zenned

Join Date:
May 2010
Posts:
513
Plugin Contributions:
0

Re: Conditional shipping option?

It seems to be working now. Thanks for hanging on with me here.

On the other issue:

the message for USPS is:
United States Postal Service (First-Class Package International Service™)

How can I change this to:
United States Postal Service (First-Class 7-20 days)

Can a hyperlink be inserted into that text?


I just want a fixed text string as shown. The USPS international estimation is never right, since once it leaves the US, it takes on a whole new schedule governed by the destination country
04 Nov 2013, 02:17
#15
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Posts:
62,757
Plugin Contributions:
1

Re: Conditional shipping option?

If you have the days set to Custom, you can set your own number of days for it on the First Class ...
04 Nov 2013, 03:20
#16
split63 avatar

split63

Totally Zenned

Join Date:
May 2010
Posts:
513
Plugin Contributions:
0

Re: Conditional shipping option?

Ajeh:

You could use the CUSTOM setting:


and show the days by turning on the:


Then, in the function parseIntlTransitTimeResults($Package, $service) you will see where the days can be customized ...


Oddly enough it is already set to Custom and the "Display Transit time" is checked.
I searched and found the function mentioned in the usps.php file. But it was not obvious how to customize it.

function parseIntlTransitTimeResults($Package, $service) {
    global $logfilename;
    if (MODULE_SHIPPING_USPS_DEBUG_MODE == 'Logs') {
      $fp = @fopen($logfilename, 'a');
    }
    if (isset($this->transittime[$service]) && $this->transittime[$service] == '' && preg_match('#(GXG|International)#i' , $service)) {
      $time = $Package['SvcCommitments'];
      $time = preg_replace('/Weeks$/', MODULE_SHIPPING_USPS_TEXT_WEEKS, $time);
      $time = preg_replace('/Days$/', MODULE_SHIPPING_USPS_TEXT_DAYS, $time);
      $time = preg_replace('/Day$/', MODULE_SHIPPING_USPS_TEXT_DAY, $time);
      $this->transittime[$service] = $time == '' ? '' : ' (' . $time . ')';
    }
    // do logging if the file was opened earlier by the config switch
    if ($fp) {
      fwrite($fp, date('M d Y G:i:s') . ' -- Transit Time (Intl)' . "\nService:                    " . $service . "\nSvcCommitments (from USPS): " . $Package['SvcCommitments'] . "\n" . '$time (calculated):         ' . $time . "\nTranslation:               " . $this->transittime[$service] . "\n\n");
      fclose($fp);
    }
  }


What is odd, is that the Priority mail transit time is shown, but the first class is not shown.
04 Nov 2013, 03:28
#17
split63 avatar

split63

Totally Zenned

Join Date:
May 2010
Posts:
513
Plugin Contributions:
0

Re: Conditional shipping option?

Found this section. It does not seem to differentiate between Domestic and International.
First Class International shows no estimate.

      /********************* CUSTOM START:  IF YOU HAVE CUSTOM TRANSIT TIMES ENTER THEM HERE ***************/
      switch (TRUE) {
        case (preg_match('#Priority Mail Express#i', $service)):
            $time = '1 - 2 ' . MODULE_SHIPPING_USPS_TEXT_DAYS;
          break;
        case (preg_match('#Priority MailTM#i', $service)):
            $time = '2 - 3 ' . MODULE_SHIPPING_USPS_TEXT_DAYS;
          break;
        case (preg_match('#Standard PostRM#i', $service)):
            $time = '4 - 7 ' . MODULE_SHIPPING_USPS_TEXT_DAYS;
          break;
        case (preg_match('#First\-Class#i', $service)):
          $time = '2 - 5 ' . MODULE_SHIPPING_USPS_TEXT_DAYS;
          break;
        case (preg_match('#Media MailRM#i', $service)):
        default:
          $time = '';
      /********************* CUSTOM END:  IF YOU HAVE CUSTOM TRANSIT TIMES ENTER THEM HERE ***************/
04 Nov 2013, 03:32
#18
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Posts:
62,757
Plugin Contributions:
1

Re: Conditional shipping option?

You might look for the International function for the displayed days:
function parseIntlTransitTimeResults($Package, $service) {
04 Nov 2013, 04:05
#19
split63 avatar

split63

Totally Zenned

Join Date:
May 2010
Posts:
513
Plugin Contributions:
0

Re: Conditional shipping option?

I could be wrong, but maybe the problem is that there is no international equivalent of the custom replacement above.

The closest thing I could find is this, and I'm at a loss to understand what this even does.

    if (isset($this->transittime[$service]) && $this->transittime[$service] == '' && preg_match('#(GXG|International)#i' , $service)) {
      $time = $Package['SvcCommitments'];
      $time = preg_replace('/Weeks$/', MODULE_SHIPPING_USPS_TEXT_WEEKS, $time);
      $time = preg_replace('/Days$/', MODULE_SHIPPING_USPS_TEXT_DAYS, $time);
      $time = preg_replace('/Day$/', MODULE_SHIPPING_USPS_TEXT_DAY, $time);
      $this->transittime[$service] = $time == '' ? '' : ' (' . $time . ')';
    }
04 Nov 2013, 04:10
#20
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Posts:
62,757
Plugin Contributions:
1

Re: Conditional shipping option?

And if you just add the text in RED what happens:
      switch (TRUE) {
        /********************* CUSTOM START:  IF YOU HAVE CUSTOM TRANSIT TIMES ENTER THEM HERE ***************/
        case (preg_match('#Priority Mail Express#i', $service)):
          $time = '3 - 5 business ' . MODULE_SHIPPING_USPS_TEXT_DAYS;
          break;
        case (preg_match('#Priority Mail#i', $service)):
          $time = '6 - 10 business ' . MODULE_SHIPPING_USPS_TEXT_DAYS;
          break;
        case (preg_match('#Global Express Guaranteed#i', $service)):
          $time = '1 - 3 business ' . MODULE_SHIPPING_USPS_TEXT_DAYS;
          break;
        case (preg_match('#USPS GXG.* Envelopes#i', $service)):
          $time = '1 - 3 business ' . MODULE_SHIPPING_USPS_TEXT_DAYS;
          break;
        case (preg_match('#First\-Class#i', $service)):
          $time = 'Varies by destination 7-12 days'; // '' . MODULE_SHIPPING_USPS_TEXT_DAYS;
          break;
        default:
          $time = '';