Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1. #1
    Join Date
    May 2012
    Posts
    13
    Plugin Contributions
    0

    Default conditional shipping modules

    hi all

    i have a slight problem with setting up shipping modules.
    I am currently using advanced shipper- my client has a specific requirement which has left me scratching my head.

    basically i need the shipping modules to be conditional (i think).
    eg:- if a customer has more than one item in the cart that are different methods in advanced shipper, then it needs to not use advanced shipper at all and use a separate shipping module (uk postcodes)

    the reason for this is that the client sells beds and furniture:-

    bed a - sent on 30 day delivery as item has to be ordered from manufacturer.

    mattress b - item sent on next day service as we hold in stock.

    now the customer orders bed a and mattress b together (from cross sell box) - both will be sent on a 30 day service so that both items arrive together
    this means that mattress b will acutally have to switch delivery methods.
    the only way i thought it may be possible to do this is have some sort of conditional shipping modules, eg, advanced shipper is displayed UNLESS multiple items are in the cart with differing shipping options, then it uses table rates module ONLY.

    is this workable? or am i over complicating things?
    i have been trying to figure this out for weeks and any help would be apprecieated

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

    Default Re: conditional shipping modules

    Quote Originally Posted by bigduffeye View Post
    the only way i thought it may be possible to do this is have some sort of conditional shipping modules, eg, advanced shipper is displayed UNLESS multiple items are in the cart with differing shipping options, then it uses table rates module ONLY.

    is this workable? or am i over complicating things?
    Yes, it is certainly workable, but it will require that you perform a little bit of custom coding in both of the shipping modules.

    Somewhere near the beginning of all(?) shipping modules is a variable called "$this-enabled". This variable is initially set via the admin settings of the various modules, HOWEVER, they can be reset within the shipping module itself based on certain conditions, such as #item in the cart, the cart category, and even a specific product.

    It is just a matter of adding the check/testing needed, and if it matches, you simply enable/disable the module my changing the value of the $this-enabled variable.

    Alas, you won't find any code that you can simply cut and paste to achieve your aims, simply because no two zencart stores are the same (or have the exact same requirements as you do). That said, there are MANY threads in this forum whereby people have similar needs, such as a specific shipping method for a specific category, ans there are many examples of the code needed. You'll just need to find one similar to your needs, and adapt it to suit your zencart installation.

    When searching, take particular note of any posts from Ajeh. She has provided many good examples of how to do this over the years, and there is sure to be one that closely matches your needs.

    Cheers
    Rod

  3. #3
    Join Date
    May 2012
    Posts
    13
    Plugin Contributions
    0

    Default Re: conditional shipping modules

    That was a great help RodG - thanks for that, i managed to get a shipping module to display using the following code - so it will only show if there are 2 or more items in the cart.

    Code:
    if (!IS_ADMIN_FLAG) {
          global $cart;
          if ($_SESSION['cart']->count_contents() <= 1 ) {
            $this->enabled = false;
          }
        }
    i just need an extra conditional statement but im kind of stuggling. (hopefully you can help)
    i also want to be able to select if a module displays depending on the products in the cart and if they have a certain db field populated.

    eg - if both the items in the cart have certain data in db field in the products table, then only show the module.

    hope this makes some kind of sense

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

    Default Re: conditional shipping modules

    Quote Originally Posted by bigduffeye View Post
    i just need an extra conditional statement but im kind of stuggling. (hopefully you can help)
    i also want to be able to select if a module displays depending on the products in the cart and if they have a certain db field populated.

    eg - if both the items in the cart have certain data in db field in the products table, then only show the module.

    hope this makes some kind of sense
    How about something like:

    Code:
    $this->enabled = false;   // disable by default
    $matches = 0 ; 
     $myorder = $_SESSION['cart']->get_products();
     
     // loop through cart extracting productIDs (or whatever).   
         
         for($index = 0 ; $index < count($myorder) ; $index++ ) {
        
         $field = $myorder[$index]['id'] ;                                  // (adapt 'id' to suit the field of interest)
    
         if("$field" == "Data_To_match") $matches++ ;               // adapt "Data_To_match" to suit what you are looking for 
    }
    
    if ($matches == count($myorder)) $this->enabled = true;   // Only enable if all products in the cart have a matching $id field. IOW, the number of matches == the number of products.

    Note: This code is untested.

    Tip: If unsure of the field names, add the following line of code after the $myorder = $_SESSION['cart']->get_products() line:
    print_r($myorder) ; exit ;

    The output won't be pretty, but it should be clear enough to see exactly what is in the array.

    Cheers
    Rod

  5. #5
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,873
    Plugin Contributions
    96

    Default Re: conditional shipping modules

    Quote Originally Posted by RodG View Post
    ...
    Tip: If unsure of the field names, add the following line of code after the $myorder = $_SESSION['cart']->get_products() line:
    print_r($myorder) ; exit ;

    The output won't be pretty, but it should be clear enough to see exactly what is in the array.

    Cheers
    Rod
    ... or you could use the Super Globals plugin (http://www.zen-cart.com/downloads.php?do=file&id=524). It can display all of the PHP variables that are active in a particular page's script; I don't know how I'd debug without it. Its support thread is here: http://www.zen-cart.com/showthread.p...erglobals-Plus.

  6. #6
    Join Date
    May 2012
    Posts
    13
    Plugin Contributions
    0

    Default Re: conditional shipping modules

    well i am getting there rod - your code is working a treat!

    i have also figured out how to change the array in includes/classes/shopping_cart.php so i can edit it for my needs!

    one last thing - the code above checks to make sure that ALL items in the cart match a db field.
    is there any way to run the check so that the module will display if AT LEAST one item in the cart has a certain matching field?

    eg:- 3 items in the cart but only 2 have a matching db field, the module still shows because at least one of them match.

    you have been a great help!

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

    Default Re: conditional shipping modules

    Quote Originally Posted by bigduffeye View Post
    there any way to run the check so that the module will display if AT LEAST one item in the cart has a certain matching field?

    eg:- 3 items in the cart but only 2 have a matching db field, the module still shows because at least one of them match.
    Sure:

    Just change

    if ($matches == count($myorder)) $this->enabled = true;
    to
    if ($matches > 0) $this->enabled = true;

    Cheers
    Rod

  8. #8
    Join Date
    May 2012
    Posts
    13
    Plugin Contributions
    0

    Default Re: conditional shipping modules

    thanks very much for all your help

    i have managed to get it setup exactly as per the clients spec.

    i owe you a beer!

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

    Default Re: conditional shipping modules

    Quote Originally Posted by bigduffeye View Post
    thanks very much for all your help

    i have managed to get it setup exactly as per the clients spec.
    Glad to help.

    Quote Originally Posted by bigduffeye View Post
    i owe you a beer!
    Nah, you owe me nothing. It is my way of giving back to the Zencart community. If you insist on buying someone a beer though, please consider a donation to the ZenCart development team.
    http://www.zen-cart.com/content.php?6-donate

    Cheers
    Rod

  10. #10
    Join Date
    May 2012
    Posts
    13
    Plugin Contributions
    0

    Default Re: conditional shipping modules

    well now there is some very strange behaviour happening

    i finally managed to get the modules configured - but when i select continue on the checkout shipping page (after selecting a shipping option) the page just reloads and does not progress to the next stage.

    this is the same for all modules, anyone any ideas as to why this would happen?

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. v139h Conditional shipping option?
    By split63 in forum Built-in Shipping and Payment Modules
    Replies: 63
    Last Post: 2 Feb 2014, 08:59 PM
  2. Admin Shipping Mod Area not showing all shipping modules
    By MB1 in forum Built-in Shipping and Payment Modules
    Replies: 7
    Last Post: 18 Feb 2012, 11:08 PM
  3. conditional based attributes to calc shipping?
    By shewhorn in forum Setting Up Categories, Products, Attributes
    Replies: 3
    Last Post: 16 Feb 2010, 03:18 AM

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