Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2013
    Posts
    3
    Plugin Contributions
    0

    Default Custom Shipping Module returning Multiple Quotes does not forward selection to Checko

    I'm working on a custom shipping module that calculates several different quotes for: Freight, Ground, Express, Overnight. I can get everything to work just fine, and when I proceed to checkout I'm prompted with the available options for my order. However, no matter which of the options I select within the options for my shipping module, when I continue to the next step of the checkout the incorrect selection is showing up.

    Ex:

    I am presented with 3 options for my module "LTL Shipping" and I see 3 radio buttons:

    Ground Shipping - $50.00
    Two-Day Shipping - $173.68
    One-Day Shipping - $461.83

    If I select the One-Day Shipping or Two-Day shipping option and click "Continue Checkout", the next screen shows LTL Shipping (Ground Shipping) - $50.00 as my selection.

    I've tried providing unique 'id' values for each option instead of "$this->code" as in all of the example shipping modules, but that did not work either. It seems the checkout process is not designed to handle multiple quotes from a single Shipping module. This seems incredibly broken.

    Details:

    Zencart Version: v1.5.0
    Database: MySQL

    Installed Modules: Only my custom Shipping module

    Has anyone else run into this problem?

    Also, I apologize if this is the wrong place in the forums for this question. I could not find a "Developers" or "Module Developers" section.

    Thank you,
    Barry

  2. #2
    Join Date
    Jan 2007
    Location
    Australia
    Posts
    6,167
    Plugin Contributions
    7

    Default Re: Custom Shipping Module returning Multiple Quotes does not forward selection to Ch

    Quote Originally Posted by barryrowe View Post
    I've tried providing unique 'id' values for each option instead of "$this->code" as in all of the example shipping modules, but that did not work either. It seems the checkout process is not designed to handle multiple quotes from a single Shipping module. This seems incredibly broken.
    It's not broken, and there are several shipping modules available the supply multiple quotes. I suspect you have something amiss with the data arrays that your module is creating.

    Although it isn't possible to mention all of the things that could be amiss, I can tell you one thing for sure, and that is, the
    $this->quotes = array('id' => $this->code,
    is something that you *shouldn't* be changing. The $this->code variable should always be the name of your code, and not one of the methods that your module supports.

    ------------------- example ------
    $this->code = "LTL Shipping' ;
    $module = 'myModule' ;

    function quote($method = '') {
    $this->quotes = array( 'id' => $this->code,
    'module' => $module,
    'methods' => array(array( 'id' => $method, // unique method code, eg 'GS,' '1DS', '2DS', etc ....
    'title' => $title, // Text string for this method, eg 'Ground shipping', 'One-Day Shipping', ' Two-Day Shipping' .
    'cost' => $cost // shipping cost for this method.
    )
    )
    );
    return $this->quotes ; //return a single quote based on the $methodID
    }
    -----------------------------------------------------

    It seems you've already figured out how to return/display the multiple methods, so what happens above is when the customer makes a selection, this quote function is called with the $method value set, and you just need to use this to populate the 'title' (aka description) and the cost.

    If the $method variable isn't set, the array returned would be identical to the above, but just with more 'methods' added.

    Please use this as a *guide only*. It is not supposed to be executable/valid code.

    Cheers
    Rod.

    ps. If Ajeh (or any of the zencart team) offer any other (or contrary) advice, you should take their words/suggestions over mine.

  3. #3
    Join Date
    Jan 2013
    Posts
    3
    Plugin Contributions
    0

    Default Re: Custom Shipping Module returning Multiple Quotes does not forward selection to Ch

    Thanks for the reply. I see how my original statement was misleading. I am always providing the 'id' of the top level as "$this->code". And I'm doing exactly what you show, setting a unique 'id' value for each of the 'methods' array items. So something like this is what I'm doing (with more calculation of course, but this is simplified):

    Code:
    $this->quotes = array('id' => $this->code,
                                  'module' => MODULE_SHIPPING_LTL_SHIPPING_FREIGHT_TEXT_TITLE,
                                  'methods' => array());
    
    
    $this->quotes['methods'][] = array('id' =>ltlfreight,
    		   			      'title' => 'LTL Freight',
    					      'cost' => '25.00'));
    $this->quotes['methods'][] = array('id' =>ltltwoday,
    		   			      'title' => 'LTL Two Day',
    					      'cost' => '40.00'));
    $this->quotes['methods'][] = array('id' =>ltloneday,
    		   			      'title' => 'LTL One Day',
    					      'cost' => '50.00'));
    So what you're saying is I should be able to do the above and then add something like this to get the right quote at checkout:
    Code:
     
    $returnIndex = -1;
    if(strcomp($method, 'ltlfreight') == 0){
      $returnIndex = 0;
    }else if (strcomp($method, 'ltltwoday') == 0){
      $returnIndex = 1;
    }else if(strcomp($method, 'ltloneday') == 0){
       $returnIndex = 2;
    }
    
    if($returnIndex >= 0){
    //Re-write our indtended quote into method position 0
    $this->quotes['methods'][0] = $this->quotes['methods'][$returnIndex];
    }
    
    return $this->quotes;
    This makes sense, and I don't know how I didn't see it before. I guess I just missed the function signature. I'll give this a shot and see if I can make it work. Thanks.

    While I've got you on this thread, I want to ask another question:

    Is the 'quote' function called on each page of the checkout process? What if calculations need to make WebService calls or some other fairly heavy operation to produce a set of quotes?


    Barry
    Last edited by barryrowe; 17 Jan 2013 at 01:47 AM. Reason: Invalid strcmp if statements fixed.

  4. #4
    Join Date
    Jan 2013
    Posts
    3
    Plugin Contributions
    0

    Default Re: Custom Shipping Module returning Multiple Quotes does not forward selection to Ch

    The above method worked for me. Now I'll be able to use the $method value to determine which value I need to calculate and only provide a single quote, which will be great.

    Is there a way around making a WebService call every time quote is called for a single cart without a custom Database table tied to carts?

    Thanks again Rod.

  5. #5
    Join Date
    Jan 2007
    Location
    Australia
    Posts
    6,167
    Plugin Contributions
    7

    Default Re: Custom Shipping Module returning Multiple Quotes does not forward selection to Ch

    Quote Originally Posted by barryrowe View Post
    The above method worked for me. Now I'll be able to use the $method value to determine which value I need to calculate and only provide a single quote, which will be great.

    Is there a way around making a WebService call every time quote is called for a single cart without a custom Database table tied to carts?

    Thanks again Rod.
    I can tell you how I've dealt with this for my 'ozpost' shipping module, but before I do so, I feel it only fair to mention that when I originally created this module I was very new to ZenCart and its workings, and if I were to rewrite it from scratch I'd probably have done many things differently.

    1a) If the quote function is called without the $method being set, I obtain the full set of quotes, and just before the "return $this-quotes" I save them out as a session variable, along with the relevant 'parcel data' (origin/destination postcodes, parcel weight, parcel dimensions, etc).

    1b) If the function is called again (without the $method being set). I check to see if the session data is available, and if so, I then compare the saved 'parcel data' with the current quote request, and if all matches I restore the $this->quotes from the session data and return to the calling function (no need to re-request from the servers). If the parcel data doesn't match, I destroy the session data and retreive a new set of quotes.

    2) If the function is called with the $method variable set, I again check the session and parcel data (as above), and if the session data is valid for the quote, I then loop through the session data comparing the $method variable with the methodID's. If/when a match is found, I return that quote only.
    If a match isn't found (which probably should never happen) the entire process gets repeated.

    In more recent updates to the ozpost module I've added another DB table to cache the quotes from the server(s). Unlike the session saved quotes though, these ones are 'keyed' to the querystring being sent to the server. I perform a check to see if this key exists in the database. If not, the query is sent to the servers, and as long as a valid result is returned I save this 'raw' data into the DB. If the key does exist, I retrieve this 'raw' data, which is then processed in the normal manner. I expire this DB data after 1hour.
    The reason for having this additional cache is so that any given customer can add/delete products from their cart, and the module will only need to connect to the servers for 'unique' queries... IE: If they add a product, request a quote, add another product, request another quote, then for whatever reason the remove the second product and request another quote, it'll be the same as their first quote, so that'll come out of the database cache rather than having to perform another server request. The only reason *I* need to expire these entries are 1hr is because the ozpost quotes have a 'time element'... specifically it has a deadline for when overnight deliveries are possible, so any given quote is only 'valid' for up to an hour at a time. If it weren't for this the DB cache could, in theory, be used until the carriers change their prices.

    I'm sure that there are probably other/better ways of doing all of this, but like I said, when I first coded ozpost I was really new to its workings and I just used what I found worked for me. :)

    Cheers
    Rod

 

 

Similar Threads

  1. v139h USPS Shipping Module Not Returning Rates
    By WiccanWitch420 in forum General Questions
    Replies: 3
    Last Post: 10 Feb 2014, 05:23 AM
  2. v150 USPS Module not returning rate quotes
    By scubasteve in forum Addon Shipping Modules
    Replies: 6
    Last Post: 19 Apr 2013, 01:53 PM
  3. USPS Shipping Module - Not taking customer shipping selection
    By scubasteve in forum Built-in Shipping and Payment Modules
    Replies: 12
    Last Post: 5 Aug 2011, 01:20 AM
  4. custom shipping quotes
    By fakeDecoy in forum Built-in Shipping and Payment Modules
    Replies: 4
    Last Post: 20 Feb 2008, 11:26 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