Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2004
    Location
    Belfast, Northern Ireland
    Posts
    2,480
    Plugin Contributions
    14

    bug [not a bug] Checkout Shipping's header_php.php

    Hi,

    When developing a new shipping module for Zen Cart I found a bug in the file:

    includes/modules/pages/checkout_shipping/header_php.php

    Although Zen Cart allows the usage of several shipping methods by each shipping module, it would appear that no-one has ever used this functionality as, when submitting the checkout shipping page, the customer's selection is ignored and the first shipping method for the selected shipping module is always chosen!

    It's a very simple bug to fix and I'm happy to include a diff patch for it below...

    I'd appreciate it if this could be updated in the next version of ZC so that I don't have to have instructions in our new shipping module on how to modify this core file!

    The patch for this is as follows, please e-mail me if you want a copy of a freshly updated ZC1.3.7 file:

    PHP Code:
    @@ -144,16 +144,26 @@
               } else {
                 
    $quote $shipping_modules->quote($method$module);
               }
               if (isset(
    $quote['error'])) {
                 
    $_SESSION['shipping'] = '';
               } else {
    -            if ( (isset(
    $quote[0]['methods'][0]['title'])) && (isset($quote[0]['methods'][0]['cost'])) ) {
    +            
    // Identify the shipping method selected by the user (some shipping modules can have
    +            // several methods/ways in their quote).
    +            $shipping_method_index 0;
    +            
    $num_shipping_methods sizeof($quote[0]['methods']);
    +            for (
    $i 0$i $num_shipping_methods$i++) {
    +              if ((
    $module '_' $quote[0]['methods'][$i]['id']) == $_SESSION['shipping']) {
    +                
    $shipping_method_index $i;
    +                break;
    +              }
    +            }
    +           if ( (isset(
    $quote[0]['methods'][$shipping_method_index]['title'])) && (isset($quote[0]['methods'][$shipping_method_index]['cost'])) ) {
                   
    $_SESSION['shipping'] = array('id' => $_SESSION['shipping'],
    -                                
    'title' => (($free_shipping == true) ?  $quote[0]['methods'][0]['title'] : $quote[0]['module'] . ' (' $quote[0]['methods'][0]['title'] . ')'),
    -                                
    'cost' => $quote[0]['methods'][0]['cost']);
    +                                
    'title' => (($free_shipping == true) ?  $quote[0]['methods'][$shipping_method_index]['title'] : $quote[0]['module'] . ' (' $quote[0]['methods'][$shipping_method_index]['title'] . ')'),
    +                                
    'cost' => $quote[0]['methods'][$shipping_method_index]['cost']);
     
                   
    zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT'''SSL'));
                 }
               }
             } else {
               
    $_SESSION['shipping'] = false
    Hope you find this helpful!

    All the best...

    Conor
    ceon

  2. #2
    Join Date
    Jan 2004
    Posts
    66,443
    Plugin Contributions
    279

    Default Re: Bug in Checkout Shipping's header_php.php

    Quote Originally Posted by conor View Post
    Although Zen Cart allows the usage of several shipping methods by each shipping module, it would appear that no-one has ever used this functionality as, when submitting the checkout shipping page, the customer's selection is ignored and the first shipping method for the selected shipping module is always chosen!
    I'm not sure I understand what you're saying.
    USPS and UPS and others offer multiple shipping choices for ground/air/express/etc, and when the customer selects one of these, it properly uses the selected choice, passing both the description and the rate over to the subtotal calculations and into the final invoice, etc.

    Or are you saying something *else* is happening?
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    Aug 2004
    Location
    Belfast, Northern Ireland
    Posts
    2,480
    Plugin Contributions
    14

    Default Re: Bug in Checkout Shipping's header_php.php

    Hi,

    Quote Originally Posted by DrByte View Post
    Or are you saying something *else* is happening?
    I can't get either of those two modules to work here but it does appear that UPS at least in theory supports multiple shipping methods.

    However, the code in header_php.php of checkout_shipping, since version 1.2.x right up to 1.3.7 discards the user's selection on progression from checkout_shipping to checkout_payment...

    This can be clearly seen by even just the following snippet:

    PHP Code:
    'cost' => $quote[0]['methods'][0]['cost']); 
    As you can see, ZC wrongly selects the first shipping method for the quote (the second [0]) regardless of which method the user may have selected.

    I'm stumped as to why no-one would have noticed this with the UPS module but upon writing the new Region Tables module it was something that I found straight away... if there are 3 shipping methods on offer by the module, no matter what one you pick at the shipping stage, ZC selects the first. Which is obvious given the [0]!

    Don't really know what else to say except that "it can't possibly work for anyone"! :)

    All the best...

    Conor

  4. #4
    Join Date
    Aug 2004
    Location
    Belfast, Northern Ireland
    Posts
    2,480
    Plugin Contributions
    14

    Default Re: Bug in Checkout Shipping's header_php.php

    Hi,

    Time to put my tail between my legs here....

    I missed the fact that the shipping class' "quote" method only retrieves the quote for the currently selected module at the submission of the checkout_shipping stage, and that at this point it passes the name of the method the chosen shipping module should return a single quote for.

    I was mistakenly returning all the quotes for the method and then using the user's selection on submission of the checkout_shipping page to extract the selected quote only.

    I should have looked into how things worked a little closer, I got blinkered by the fact that I don't tend to have methods return multiple arrays in one place and single values in another... it's not the worst thing in the world but, obviously, not intuitive for outside developers.

    As I said at the start though, my tail is between my legs, your code works just fine and I'll update the new Region Tables module to operate in the same way.

    This bug can be disregarded now. :)

    All the best...

    Conor

  5. #5
    Join Date
    Jan 2004
    Posts
    66,443
    Plugin Contributions
    279

    Default Re: Bug in Checkout Shipping's header_php.php

    No sweat ... just wanted to be sure we were both looking at the right thing ;)
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

 

 

Similar Threads

  1. Replies: 2
    Last Post: 5 Feb 2014, 04:45 PM
  2. Replies: 3
    Last Post: 10 Apr 2013, 03:46 PM
  3. productArray - not in header_php.php?
    By mdewyer in forum General Questions
    Replies: 0
    Last Post: 8 Jul 2008, 02:53 AM
  4. Replies: 4
    Last Post: 7 Apr 2008, 03:52 PM
  5. Replies: 2
    Last Post: 5 Dec 2007, 04:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg