Page 1 of 2 12 LastLast
Results 1 to 10 of 15
  1. #1
    Join Date
    Jun 2009
    Posts
    42
    Plugin Contributions
    0

    cart error Setting Shipping Methods Based on Weight

    Setting Shipping Methods Based on Weight

    Hello all,
    So I have searched around for this but I have mainly found people wanting to restrict certain carriers based on things such as individual items, weight, cost, etc. What I have not found is where change the usps.php file so that I can do the following scenario (ONLY for International shipments):

    When the total weight is <0.99lbs, then show the options:
    USPS Priority Mail Int Flat Rate Env
    USPS Express Mail Int Flat Rate Env

    and NOT show:
    USPS Priority Mail International
    USPS Express Mail Int


    The reason is to reduce the shipping cost to my customers since the items that are the least amount of weight (which you would have to buy a ton of to get to 0.99lbs total weight) are small and can be shipped via an envelope and dont need a box.

    Please let me know what php lines are needed to solve this, thanks
    -Nolan

  2. #2
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: Setting Shipping Methods Based on Weight

    You would need to test the shipping method $type in the: function quote

    And mask/hide/skip the results when the $usps_shipping_weight is <= 0.99 ...
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  3. #3
    Join Date
    Jun 2009
    Posts
    42
    Plugin Contributions
    0

    Default Re: Setting Shipping Methods Based on Weight

    Ok so I think this is the part of the usps.php file you are saying I should change:
    PHP Code:
           // BOF: UPS USPS
            
    $this->quotes = array('id' => $this->code,
            
    'module' => $this->title $show_box_weight);
            
    // EOF: UPS USPS

            
    $methods = array();
            
    $size sizeof($uspsQuote);
            for (
    $i=0$i<$size$i++) {
              list(
    $type$cost) = each($uspsQuote[$i]);

              
    // BOF: UPS USPS
              
    $title = ((isset($this->types[$type])) ? $this->types[$type] : $type);
              if(
    in_array('Display transit time'explode(', 'MODULE_SHIPPING_USPS_OPTIONS)))    $title .= $transittime[$type];
              
    /*
              $methods[] = array('id' => $type,
              'title' => ((isset($this->types[$type])) ? $this->types[$type] : $type),
              'cost' => ($cost + MODULE_SHIPPING_USPS_HANDLING) * $shipping_num_boxes);
              */
              
    $methods[] = array('id' => $type,
                                 
    'title' => $title,
                                 
    'cost' => ($cost MODULE_SHIPPING_USPS_HANDLING) * $shipping_num_boxes);
            } 
    So how do I set up the "if else" statement so that one of the types is allowed only when less than 0.99 lbs. I dont see anything about the different types, so is it in whatever the MODULE_SHIPPING_USPS_OPTIONS is referring to?
    Sorry this is my first time with PHP, and though related to html I am still in the learning stage.

  4. #4
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: Setting Shipping Methods Based on Weight

    Add this echo below the list:
    Code:
              list($type, $cost) = each($uspsQuote[$i]);
    echo 'I SEE usps type: ' . $type . '<br>';
    Based on the results of the $type you can add an IF condition or a CASE condition to control the building of the:
    Code:
              $methods[] = array('id' => $type,
                                 'title' => $title,
                                 'cost' => ($cost + MODULE_SHIPPING_USPS_HANDLING) * $shipping_num_boxes);
    If nothing is added to the $methods[] based on the $type then it will be excluded from the shipping options ...
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  5. #5
    Join Date
    Jun 2009
    Posts
    42
    Plugin Contributions
    0

    Default Re: Setting Shipping Methods Based on Weight

    Ok so something like this?

    PHP Code:
    // BOF: UPS USPS
            
    $this->quotes = array('id' => $this->code,
            
    'module' => $this->title $show_box_weight);
            
    // EOF: UPS USPS

            
    $methods = array();
            
    $size sizeof($uspsQuote);
            for (
    $i=0$i<$size$i++) {
              list(
    $type$cost) = each($uspsQuote[$i]);

           echo 
    'I SEE usps type: ' $type '<br>';

              
    // BOF: UPS USPS
              
    $title = ((isset($this->types[$type])) ? $this->types[$type] : $type);
              if(
    in_array('Display transit time'explode(', 'MODULE_SHIPPING_USPS_OPTIONS)))    $title .= $transittime[$type];
              
    /*
              $methods[] = array('id' => $type,
              'title' => ((isset($this->types[$type])) ? $this->types[$type] : $type),
              'cost' => ($cost + MODULE_SHIPPING_USPS_HANDLING) * $shipping_num_boxes);
              */

          
    if($usps_shipping_weight is <= 0.99){

              
    $methods[] = array('id' => $type,
                                 
    'title' => $title,
                                 
    'cost' => ($cost MODULE_SHIPPING_USPS_HANDLING) * $shipping_num_boxes);

          } else{

          
    $methods[] = array('id' => $type,
                                 
    'title' => $title,
                                 
    'cost' => ($cost MODULE_SHIPPING_USPS_HANDLING) * $shipping_num_boxes);
          }

            } 
    But how do I specify which type to filter for?

  6. #6
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: Setting Shipping Methods Based on Weight

    Note: on the IF you might use:
    Code:
          if($usps_shipping_weight <= 0.99){
    Look at the output of the echo for the $type when you are looking at shipping costs ...

    Which one(s) do you want to turn off when <= .99 ...
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  7. #7
    Join Date
    Jun 2009
    Posts
    42
    Plugin Contributions
    0

    Default Re: Setting Shipping Methods Based on Weight

    Ok here is the echo:

    I SEE usps type: Global Express Guaranteed
    I SEE usps type: Express Mail International (EMS)
    I SEE usps type: Priority Mail International
    I SEE usps type: Priority Mail International Flat-Rate Envelope

    I only want the last one to show when total weight is less than or equal to 0.99 lbs

  8. #8
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: Setting Shipping Methods Based on Weight

    You will have to adjust this for the other methods but to give you an idea ...

    Code:
              $show_it = false;
              if ($usps_shipping_weight <= 0.99) {
                // if less than or equal to 0.99 and $type is Priority Flat-Rate show it
                if ($type == 'Priority Mail International Flat-Rate Envelope') {
                  $show_it = true;
                }
                if ($type == 'Priority Mail International') {
                  $show_it = false;
                }
              } else {
                // if greater than 0.99 show it
                $show_it = true;
              }
              if ($show_it == true) {
                $methods[] = array('id' => $type,
                                   'title' => $title,
                                   'cost' => ($cost + MODULE_SHIPPING_USPS_HANDLING) * $shipping_num_boxes);
              }
    There are other ways to do this ... but this is just to give you an idea of what you can try for this ...

    NOTE: don't forget to test with National shipping methods at this low weight and setup for those as well ...
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  9. #9
    Join Date
    Jun 2009
    Posts
    42
    Plugin Contributions
    0

    Default Re: Setting Shipping Methods Based on Weight

    Ok it is working, I will post the working code here soon...but more importantly, how do I filter for Domestic and International?
    I only want this to happen for International shipping, but it is doing so for both International and Domestic.

  10. #10
    Join Date
    Jun 2009
    Posts
    42
    Plugin Contributions
    0

    Default Re: Setting Shipping Methods Based on Weight

    Ok scratch that, I figured it out. The domestic mailing is just named with the EXPRESS and PRIORITY names, so there is no more filtering being done besides that. Here is the code that works great, though sure seems longer than it should be. I am basically only filtering the shipping methods so that the Flat Rate Envelopes for Priority and Express are allowed to show up if the package weight is less than or equal to 0.99 lbs.
    Place this in the includes/modules/shipping/usps.php

    PHP Code:
            $methods = array();
            
    $size sizeof($uspsQuote);
            for (
    $i=0$i<$size$i++) {
              list(
    $type$cost) = each($uspsQuote[$i]);

          
    // echo 'I SEE usps type: ' . $type . '<br>';

              // BOF: UPS USPS
              
    $title = ((isset($this->types[$type])) ? $this->types[$type] : $type);
              if(
    in_array('Display transit time'explode(', 'MODULE_SHIPPING_USPS_OPTIONS)))    $title .= $transittime[$type];
              
    /*
              $methods[] = array('id' => $type,
              'title' => ((isset($this->types[$type])) ? $this->types[$type] : $type),
              'cost' => ($cost + MODULE_SHIPPING_USPS_HANDLING) * $shipping_num_boxes);
              */
              
              
    $show_it false;
              if (
    $usps_shipping_weight <= 0.99) {
                
    // if less than or equal to 0.99 and $type is Global Express Guaranteed, Express Mail International (EMS) Flat-Rate Envelope, or Priority Flat-Rate show it
                
    if ($type == 'Global Express Guaranteed') {
                  
    $show_it true;
                }
                if (
    $type == 'Express Mail International (EMS) Flat-Rate Envelope') {
                  
    $show_it true;
                }
                if (
    $type == 'Priority Mail International Flat-Rate Envelope') {
                  
    $show_it true;
                }
                if (
    $type == 'Priority Mail International') {
                  
    $show_it false;
                }
                if (
    $type == 'Express Mail International (EMS)') {
                  
    $show_it false;
                }
                
    // always show Domestic Shipping
                
    if ($type == 'EXPRESS') {
                  
    $show_it true;
                }
                if (
    $type == 'PRIORITY') {
                  
    $show_it true;
                }
             } else {
                
    // if greater than 0.99 show it
                
    if ($type == 'Global Express Guaranteed') {
                  
    $show_it true;
                }
                if (
    $type == 'Express Mail International (EMS) Flat-Rate Envelope') {
                  
    $show_it false;
                }
                if (
    $type == 'Priority Mail International Flat-Rate Envelope') {
                  
    $show_it false;
                }
                if (
    $type == 'Priority Mail International') {
                  
    $show_it true;
                }
                if (
    $type == 'Express Mail International (EMS)') {
                  
    $show_it true;
                }
                
    // always show Domestic Shipping
                
    if ($type == 'EXPRESS') {
                  
    $show_it true;
                }
                if (
    $type == 'PRIORITY') {
                  
    $show_it true;
                }
             }
              if (
    $show_it == true) {
                
    $methods[] = array('id' => $type,
                                   
    'title' => $title,
                                   
    'cost' => ($cost MODULE_SHIPPING_USPS_HANDLING) * $shipping_num_boxes);
              }
          } 
    Thanks for the help, Im getting a hang of this php thing a little more.

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. Different shipping methods based on quantity
    By falariem in forum Built-in Shipping and Payment Modules
    Replies: 3
    Last Post: 19 Aug 2011, 12:06 AM
  2. Shipping multiple items based on total weight, but need weight per box.
    By Nineve in forum Built-in Shipping and Payment Modules
    Replies: 3
    Last Post: 2 Aug 2010, 07:42 AM
  3. Zone Shipping Cost based on Individual item weight, not total order weight
    By pohnean in forum Built-in Shipping and Payment Modules
    Replies: 15
    Last Post: 16 Sep 2009, 09:02 AM
  4. Changing shipping methods based on item weight??
    By krhody in forum Built-in Shipping and Payment Modules
    Replies: 11
    Last Post: 12 Sep 2009, 09:11 PM
  5. Setting Up Shipping Prices based on categories or Based on Table?
    By CoolCarPartsOnline in forum Built-in Shipping and Payment Modules
    Replies: 2
    Last Post: 21 May 2008, 07:22 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