Zen Cart Logo
Forums / Built-in Shipping and Payment Modules / Need to know how to set a default shipping option

Need to know how to set a default shipping option

Locked

Views: 4,538

Results 1 to 20 of 21
This thread is locked. New replies are disabled.
6 Feb 2015, 10:12 AM
#1
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Need to know how to set a default shipping option

I get that Zen Cart by default doesn't select a payment method or shipping option by default.. I don't agree with the logic behind this, but that is a whole 'nuther discussion..

In a store with only ONE payment method and only ONE shipping method, these singular options SHOULD be selected by default without requiring an intervening user action to select them.

Does anyone know HOW to accomplish this?? Has anyone done this and would care to share their solution with the class??

6 Feb 2015, 10:26 AM
#2
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: Need to know how to set a default shipping option

DivaVocals:

I get that Zen Cart by default doesn't select a payment method or shipping option by default.. I don't agree with the logic behind this, but that is a whole 'nuther discussion..

Actually it does (or should) select a default shipping method. It uses the cheapest method that isn't a local pickup.

DivaVocals:

In a store with only ONE payment method and only ONE shipping method, these singular options SHOULD be selected by default without requiring an intervening user action to select them.

Agreed.

DivaVocals:

Does anyone know HOW to accomplish this?? Has anyone done this and would care to share their solution with the class??

Shouldn't be difficult. Find the code where the payment method(s) are generated for display, and add 'checked' next to the value. EG:

<input type="radio" name=myradio value="whatever" checked>whatever

Cheers
RodG

6 Feb 2015, 2:13 PM
#3
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Re: Need to know how to set a default shipping option

RodG:

Actually it does (or should) select a default shipping method. It uses the cheapest method that isn't a local pickup.

I thought so too, but in a store where shipping UNDER $1000 is a flat rate and anything OVER $1000 is free shipping only ONE option will ever be shown to a customer, and therefore SHOULD be selected by default, but this is NOT happening. The customer is REQUIRED to have to select the radio button..

RodG:

Shouldn't be difficult. Find the code where the payment method(s) are generated for display, and add 'checked' next to the value. EG:

<input type="radio" name=myradio value="whatever" checked>whatever
Yeah.. Except I've looked at the code on the checkout shipping page,and I am at a loss on how where to do this..

6 Feb 2015, 3:35 PM
#4
rixstix avatar

rixstix

Totally Zenned

Join Date:
Aug 2009
Location:
North Idaho, USA
Posts:
2,015
Plugin Contributions:
0

Re: Need to know how to set a default shipping option

Maybe it's a bug,

includes/classes/payment.php ~ line 83

 $include_modules = array_values($include_modules);
    [B]  // if there is only one payment method, select it as default because in
      // checkout_confirmation.php the $payment variable is being assigned the
      // $_POST['payment'] value which will be empty (no radio button selection possible)[/B]
      if ( (zen_count_payment_modules() == 1) && (!isset($_SESSION['payment']) || (isset($_SESSION['payment']) && !is_object($_SESSION['payment']))) ) {

I have seen this happen after selecting PayPal Express Checkout, redirected to PP for login, return to ZC, then step 2 of checkout has no option to select payment method since PP has been selected prior to beginning the checkout process.

For me, shipping method preselected appears to only occur IF USPS is an option. If filters remove USPS options, then no option of the remaining shipping methods is preselected

6 Feb 2015, 3:56 PM
#5
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Need to know how to set a default shipping option

DivaVocals:

In a store with only ONE payment method and only ONE shipping method, these singular options SHOULD be selected by default without requiring an intervening user action to select them.
Actually, for payment it does. I just checked again to be sure.

So, which specific payment module are you having this problem with?

6 Feb 2015, 5:35 PM
#6
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Re: Need to know how to set a default shipping option

DrByte:

Actually, for payment it does. I just checked again to be sure.

So, which specific payment module are you having this problem with?

Zone payments.. It's the ONLY one available when the cart total is under $1000.. and it's definitely NOT selected by default..

BUT I was looking at the includes/templates/YOUR_TEMPLATE/templates/tpl_checkout_shipping_default.php file and (starting at around line 76) found this block of code:

<?php
        } else {
          for ($j=0, $n2=sizeof($quotes[$i]['methods']); $j<$n2; $j++) {
// set the radio button to be checked if it is the method chosen
            $checked = FALSE;
            if (isset($_SESSION['shipping']) && isset($_SESSION['shipping']['id'])) {
              $checked = ($quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id'] == $_SESSION['shipping']['id']);
            }
            if ( ($checked == true) || ($n == 1 && $n2 == 1) ) {
              //echo '      <div id="defaultSelected" class="moduleRowSelected">' . "\n";
            //} else {
              //echo '      <div class="moduleRow">' . "\n";
            }
?>

If I change the $checked variable to = TRUE, THEN the Zone shipping is checked by default.. But honestly because I am not FULLY clear on each piece of this code, I don't know whether this impacts something else in a negative way..

6 Feb 2015, 9:05 PM
#7
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Need to know how to set a default shipping option

DivaVocals:

If I change the $checked variable to = TRUE, THEN the Zone shipping is checked by default.. But honestly because I am not FULLY clear on each piece of this code, I don't know whether this impacts something else in a negative way..
Ya, that'd be bad since now it's gonna mark all modules as "checked" and that'll give unexpected results when you've got more than one module.
There's code on the page to handle when there's only 1 payment module available ... in which case it doesn't give a radio button at all, and "pre-checks" the only-available module via a hidden field.

Edit:
Sorry, I keep answering in the context of PAYMENT modules because that's the title of this thread (or at least the visible part before opening the thread), and yet you keep posting about shipping modules.

6 Feb 2015, 10:08 PM
#8
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Re: Need to know how to set a default shipping option

DrByte:

Ya, that'd be bad since now it's gonna mark all modules as "checked" and that'll give unexpected results when you've got more than one module.
There's code on the page to handle when there's only 1 payment module available ... in which case it doesn't give a radio button at all, and "pre-checks" the only-available module via a hidden field.

Edit:
Sorry, I keep answering in the context of PAYMENT modules because that's the title of this thread (or at least the visible part before opening the thread), and yet you keep posting about shipping modules.

Yeah I shoulda led with the SHIPPING.. It was late last night and I was sleep deprived and aggravated.. Upon further reflection, I have realized that this could NEVER apply to payments.. Anyway I can't fix the original post now.. right now my IMMEDIATE concern is the fact that the only shipping module available isn't selected by default, and I cannot figure out WHY..

6 Feb 2015, 11:07 PM
#9
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Need to know how to set a default shipping option

I totally understand the frustration thing!

I've updated the thread title.

6 Feb 2015, 11:09 PM
#10
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Need to know how to set a default shipping option

Shipping modules are a little different from payment modules, in that there are 2 parts to them: the module itself, plus the "selected quote".

Even modules which don't "retrieve live quotes from external sources" still have a list of quotes, even if that list is only a single entry.

I was talking with Ajeh about this issue, and she said that maybe v1.5.0 and v1.5.1 worked a bit differently than v1.5.4. I haven't had time to look into any relevant code changes to see what behavior changes might have been introduced and why:

ajeh:

In v1.5 and v1.5.1 if only Flat and Free Options is installed and Free Options is set for Total >= 1000.00 the default shipping is selected ...In v1.5.4 and v1.6 with only Flat and Free Options intalled and Free Options set for Total >=1000.00 the default shipping is NOT set ...
Also in v1.5.4 and v1.6 if ONLY Flat is installed the default shipping is NOT set, even though, again, Flat is the only shipping option showing ...
Note: in v1.5.4 and v1.6 if Store Pickup is installed then the default is set ...

6 Feb 2015, 11:47 PM
#11
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Re: Need to know how to set a default shipping option

DrByte:

I totally understand the frustration thing!It's worse when you're sleep deprived and have a BIG presentation to lead the next day or later that morning (as was my case)!!

DrByte:

I've updated the thread title.Thanks.. :smile:

DrByte:

Shipping modules are a little different from payment modules, in that there are 2 parts to them: the module itself, plus the "selected quote".

Even modules which don't "retrieve live quotes from external sources" still have a list of quotes, even if that list is only a single entry.

I was talking with Ajeh about this issue, and she said that maybe v1.5.0 and v1.5.1 worked a bit differently than v1.5.4. I haven't had time to look into any relevant code changes to see what behavior changes might have been introduced and why:

Okay.. well if this changed, as Ajeh has stated, then from a usability POV, this REALLY isn't a good user experience.. Making a shopper click the ONLY option available doesn't make a lot of sense.. Not sure what problem this change was supposed to solve, but outcome is truly an undesirable consequence. I would say that this should be re-examined. Please keep me posted if you have more info on this..

7 Feb 2015, 3:08 PM
#12
ajeh avatar

ajeh

Oba-san

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

Re: Need to know how to set a default shipping option

The change was not intentional but rather the result of cleaning up other code ...

I have a few different solutions that appear to work and when we are done testing, we will post the best solution ...

7 Feb 2015, 4:54 PM
#13
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Need to know how to set a default shipping option

Ajeh and I looked at this section of code, and I think the following should restore the expected functionality:

/includes/modules/pages/checkout_shipping/header_php.php, line 212:

Change this:```
if ( !isset($_SESSION['shipping']) && (zen_count_shipping_modules() > 1) ) $_SESSION['shipping'] = $shipping_modules->cheapest();


to this:
if ((!isset($_SESSION['shipping']) || (!isset($_SESSION['shipping']['id']) || $_SESSION['shipping']['id'] == '') && zen_count_shipping_modules() >= 1)) $_SESSION['shipping'] = $shipping_modules->cheapest();



.
7 Feb 2015, 5:51 PM
#14
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Re: Need to know how to set a default shipping option

Ajeh:

The change was not intentional but rather the result of cleaning up other code ...I figured as much.. Didn't mean to imply it was intentional at all..:smile: still sleep deprived.. :laugh:

Ajeh:

I have a few different solutions that appear to work and when we are done testing, we will post the best solution ...I KNEW you would!! :smile:

7 Feb 2015, 5:58 PM
#15
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Re: Need to know how to set a default shipping option

DrByte:

Ajeh and I looked at this section of code, and I think the following should restore the expected functionality:

/includes/modules/checkout_shipping/header_php.php, line 212:

Change this:```
if ( !isset($_SESSION['shipping']) && (zen_count_shipping_modules() > 1) ) $_SESSION['shipping'] = $shipping_modules->cheapest();

> 
> to this:
> ```
  if ((!isset($_SESSION['shipping']) || !isset($_SESSION['shipping']['id']) || $_SESSION['shipping']['id'] == '') && zen_count_shipping_modules() > 1)  $_SESSION['shipping'] = $shipping_modules->cheapest();

I presume you meant includes/modules/pages/checkout_shipping/header_php.php

and made this change.. but nope.. the shipping is still not selecting the cheapest (or in this case ONLY) shipping option..

8 Feb 2015, 1:39 AM
#16
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Need to know how to set a default shipping option

Oops. Too many versions being tested.
I ended up pasting the one with parentheses in the wrong places :blush:

It should be this:

    if ((!isset($_SESSION['shipping']) || (!isset($_SESSION['shipping']['id']) || $_SESSION['shipping']['id'] == '') && zen_count_shipping_modules() >= 1)) $_SESSION['shipping'] = $shipping_modules->cheapest();
8 Feb 2015, 2:30 AM
#17
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Re: Need to know how to set a default shipping option

DrByte:

Oops. Too many versions being tested.
I ended up pasting the one with parentheses in the wrong places :blush:

It should be this:

if ((!isset($_SESSION['shipping']) || (!isset($_SESSION['shipping']['id']) || $_SESSION['shipping']['id'] == '') && zen_count_shipping_modules() >= 1)) $_SESSION['shipping'] = $shipping_modules->cheapest();

EUREKA!!! You guys rock!!!:hug:
(so do naps.. a little food and a nap, and I think I can re-focus now!:laugh:)
16 Feb 2015, 3:41 PM
#18
delia avatar

delia

Totally Zenned

Join Date:
May 2006
Location:
Gardiner, Maine
Posts:
2,383
Plugin Contributions:
7

Re: Need to know how to set a default shipping option

Will this make the store pickup be default if there are no other choices? If not, how do I make that happen. The buyers miss selecting that option and can't checkout.

16 Feb 2015, 3:58 PM
#19
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: Need to know how to set a default shipping option

delia:

Will this make the store pickup be default if there are no other choices? .

No. (Well, I'm pretty sure it won't).

delia:

If not, how do I make that happen. The buyers miss selecting that option and can't checkout.

/includes/classes/shipping.php

The relevant code reads

 $cheapest = false;
      $size = sizeof($rates);
      for ($i=0; $i<$size; $i++) {
        if (is_array($cheapest)) {
          // never quote storepickup as lowest - needs to be configured in shipping module
[B]          if ($rates[$i]['cost'] < $cheapest['cost'] and $rates[$i]['module'] != 'storepickup') {[/B]
            $cheapest = $rates[$i];
[B]          }[/B]
        } else {
[B]          if ($rates[$i]['module'] != 'storepickup') {[/B]
            $cheapest = $rates[$i];
[B]          }[/B]
        }
      }
      $this->notify('NOTIFY_SHIPPING_MODULE_CALCULATE_CHEAPEST', $cheapest);
      return $cheapest;

As you can see, the storepickup is explicitly excluded from being selected as the cheapest (generally a good thing since this is often $0.00, which will make it the default even if other methods are available).

I'm assuming that if you remove the lines I've highlighted in blue then you should achieve what you want. (I've not tested it)

Cheers
RodG

16 Feb 2015, 4:33 PM
#20
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Re: Need to know how to set a default shipping option

RodG:

No. (Well, I'm pretty sure it won't).

/includes/classes/shipping.php

The relevant code reads

$cheapest = false;
$size = sizeof($rates);
for ($i=0; $i<$size; $i++) {
if (is_array($cheapest)) {
[B]// never quote storepickup as lowest - needs to be configured in shipping module[/B]
[B] if ($rates[$i]['cost'] < $cheapest['cost'] and $rates[$i]['module'] != 'storepickup') {[/B]
$cheapest = $rates[$i];
[B] }[/B]
} else {
[B] if ($rates[$i]['module'] != 'storepickup') {[/B]
$cheapest = $rates[$i];
[B] }[/B]
}
}
$this->notify('NOTIFY_SHIPPING_MODULE_CALCULATE_CHEAPEST', $cheapest);
return $cheapest;

> 
> As you can see, the storepickup is explicitly excluded from being selected as the cheapest (generally a good thing since this is often $0.00, which will make it the default even if other methods are available).  
> 
> I'm assuming that if you remove the lines I've highlighted in blue then you should achieve what you want. (I've not tested it)
> 
> Cheers
> RodGBut I think it will only exclude store pickup if it is available with other options.. Looks like you need additional configurations when store pickup is the ONLY option.. In any case I would TEST this code as is, and look at the admin options for store pickup before simply removing this code..