Zen Cart Logo
Forums / Built-in Shipping and Payment Modules / Changing Default Shipping Option to FedEx instead of flat?

Changing Default Shipping Option to FedEx instead of flat?

Locked

Views: 4,811

Results 1 to 14 of 14
This thread is locked. New replies are disabled.
30 Sep 2009, 9:48 PM
#1
stlnyc avatar

stlnyc

Zen Follower

Join Date:
Oct 2008
Posts:
179
Plugin Contributions:
0

Changing Default Shipping Option to FedEx instead of flat?

I just added the flat rate shipping mod (actually changed it so customers can choose local delivery). When I reach the choose shipping page, the option selected by default is the "flat rate" mod.

How can I change this? I would like to change it to Fedex Ground/Home Delivery. Thanks

1 Oct 2009, 5:34 AM
#2
ajeh avatar

ajeh

Oba-san

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

Re: Changing Default Shipping Option to FedEx instead of flat?

You would have to customize the shipping.php class ...

One way to stop Flat Rate from being picked is to change:

          if ($rates[$i]['module'] != 'storepickup') {

to read:

          if ($rates[$i]['module'] != 'storepickup' && $rates[$i]['module'] != 'flat') {

You may need more customizing for a specific method of shipping with FedEx vs just the lowest shipping cost, which is how it is designed now ...

8 Dec 2009, 6:26 PM
#3
aly22 avatar

aly22

Zen Follower

Join Date:
Feb 2008
Posts:
174
Plugin Contributions:
0

Re: Changing Default Shipping Option to FedEx instead of flat?

I need to do this as well. WHERE is shipping.php ????

9 Dec 2009, 12:17 AM
#4
ajeh avatar

ajeh

Oba-san

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

Re: Changing Default Shipping Option to FedEx instead of flat?

shipping.php is a class so it is located in the:
/includes/classes

directory ...

9 Dec 2009, 8:25 PM
#5
aly22 avatar

aly22

Zen Follower

Join Date:
Feb 2008
Posts:
174
Plugin Contributions:
0

Re: Changing Default Shipping Option to FedEx instead of flat?

Found it THANK YOU ... but how can we change the default shipping option to be UPS? (specifically UPS ground)

I do not see language and am not a php expert.

10 Dec 2009, 3:46 AM
#6
ajeh avatar

ajeh

Oba-san

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

Re: Changing Default Shipping Option to FedEx instead of flat?

By default this is intercepted to be set to the lowest amount ...

You would need to change that logic to be specific to the shipping module and the type used ...

10 Dec 2009, 3:52 AM
#7
aly22 avatar

aly22

Zen Follower

Join Date:
Feb 2008
Posts:
174
Plugin Contributions:
0

Re: Changing Default Shipping Option to FedEx instead of flat?

I figured, but have searched high and low and cannot seem to find language to make that happen :(

10 Dec 2009, 5:24 AM
#8
ajeh avatar

ajeh

Oba-san

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

Re: Changing Default Shipping Option to FedEx instead of flat?

See if this change does it for you:

      $cheapest = false;
      $size = sizeof($rates);
      for ($i=0; $i<$size; $i++) {
        // override normal cheapest and force UPS Ground
        if ($rates[$i]['id'] == 'GND') {
          $cheapest = $rates[$i];
          break;
        }
        if (is_array($cheapest)) {
          // never quote storepickup as lowest - needs to be configured in shipping module
          if ($rates[$i]['cost'] < $cheapest['cost'] and $rates[$i]['module'] != 'storepickup') {
            $cheapest = $rates[$i];
          }
        } else {
          if ($rates[$i]['module'] != 'storepickup') {
            $cheapest = $rates[$i];
          }
        }
      }
10 Dec 2009, 6:00 AM
#9
aly22 avatar

aly22

Zen Follower

Join Date:
Feb 2008
Posts:
174
Plugin Contributions:
0

Re: Changing Default Shipping Option to FedEx instead of flat?

Thanks Linda, but sadly it did nothing at all that I can see :(

10 Dec 2009, 3:16 PM
#10
ajeh avatar

ajeh

Oba-san

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

Re: Changing Default Shipping Option to FedEx instead of flat?

Try testing by logging out and then login and see if it works ...

10 Dec 2009, 5:48 PM
#11
aly22 avatar

aly22

Zen Follower

Join Date:
Feb 2008
Posts:
174
Plugin Contributions:
0

Re: Changing Default Shipping Option to FedEx instead of flat?

I copied the entire block you posted and replaced it in my shipping.php (classes) as follows:

<?php
/**
 * shipping class
 *
 * @package classes
 * @copyright Copyright 2003-2007 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: shipping.php 6276 2007-05-02 11:50:10Z drbyte $
 */
if (!defined('IS_ADMIN_FLAG')) {
  die('Illegal Access');
}
/**
 * shipping class
 * Class used for interfacing with shipping modules
 *
 * @package classes
 */
class shipping extends base {
  var $modules;

  // class constructor
  function shipping($module = '') {
    global $PHP_SELF, $messageStack;

    if (defined('MODULE_SHIPPING_INSTALLED') && zen_not_null(MODULE_SHIPPING_INSTALLED)) {
      $this->modules = explode(';', MODULE_SHIPPING_INSTALLED);

      $include_modules = array();

      if ( (zen_not_null($module)) && (in_array(substr($module['id'], 0, strpos($module['id'], '_')) . '.' . substr($PHP_SELF, (strrpos($PHP_SELF, '.')+1)), $this->modules)) ) {
        $include_modules[] = array('class' => substr($module['id'], 0, strpos($module['id'], '_')), 'file' => substr($module['id'], 0, strpos($module['id'], '_')) . '.' . substr($PHP_SELF, (strrpos($PHP_SELF, '.')+1)));
      } else {
        reset($this->modules);
        while (list(, $value) = each($this->modules)) {
          $class = substr($value, 0, strrpos($value, '.'));
          $include_modules[] = array('class' => $class, 'file' => $value);
        }
      }

      for ($i=0, $n=sizeof($include_modules); $i<$n; $i++) {
        //          include(DIR_WS_LANGUAGES . $_SESSION['language'] . '/modules/shipping/' . $include_modules[$i]['file']);
        $lang_file = zen_get_file_directory(DIR_WS_LANGUAGES . $_SESSION['language'] . '/modules/shipping/', $include_modules[$i]['file'], 'false');
        if (@file_exists($lang_file)) {
          include_once($lang_file);
        } else {
          if (IS_ADMIN_FLAG === false) {
            $messageStack->add(WARNING_COULD_NOT_LOCATE_LANG_FILE . $lang_file, 'caution');
          } else {
            $messageStack->add_session(WARNING_COULD_NOT_LOCATE_LANG_FILE . $lang_file, 'caution');
          }
        }
        include_once(DIR_WS_MODULES . 'shipping/' . $include_modules[$i]['file']);

        $GLOBALS[$include_modules[$i]['class']] = new $include_modules[$i]['class'];
      }
    }
  }

  function calculate_boxes_weight_and_tare() {
    global $total_weight, $shipping_weight, $shipping_quoted, $shipping_num_boxes;

    if (is_array($this->modules)) {
      $shipping_quoted = '';
      $shipping_num_boxes = 1;
      $shipping_weight = $total_weight;

      $za_tare_array = split("[:,]" , SHIPPING_BOX_WEIGHT);
      $zc_tare_percent= $za_tare_array[0];
      $zc_tare_weight= $za_tare_array[1];

      $za_large_array = split("[:,]" , SHIPPING_BOX_PADDING);
      $zc_large_percent= $za_large_array[0];
      $zc_large_weight= $za_large_array[1];

      // SHIPPING_BOX_WEIGHT = tare
      // SHIPPING_BOX_PADDING = Large Box % increase
      // SHIPPING_MAX_WEIGHT = Largest package

      /*
      if (SHIPPING_BOX_WEIGHT >= $shipping_weight*SHIPPING_BOX_PADDING/100) {
        $shipping_weight = $shipping_weight+SHIPPING_BOX_WEIGHT;
      } else {
        $shipping_weight = $shipping_weight + ($shipping_weight*SHIPPING_BOX_PADDING/100);
      }
      */

      switch (true) {
        // large box add padding
        case(SHIPPING_MAX_WEIGHT <= $shipping_weight):
          $shipping_weight = $shipping_weight + ($shipping_weight*($zc_large_percent/100)) + $zc_large_weight;
          break;
        default:
        // add tare weight < large
          $shipping_weight = $shipping_weight + ($shipping_weight*($zc_tare_percent/100)) + $zc_tare_weight;
          break;
      }

      if ($shipping_weight > SHIPPING_MAX_WEIGHT) { // Split into many boxes
        $shipping_num_boxes = ceil($shipping_weight/SHIPPING_MAX_WEIGHT);
        $shipping_weight = $shipping_weight/$shipping_num_boxes;
      }
    }
  }

  function quote($method = '', $module = '', $calc_boxes_weight_tare = true) {
    $quotes_array = array();

    if ($calc_boxes_weight_tare) $this->calculate_boxes_weight_and_tare();

    if (is_array($this->modules)) {
      $include_quotes = array();

      reset($this->modules);
      while (list(, $value) = each($this->modules)) {
        $class = substr($value, 0, strrpos($value, '.'));
        if (zen_not_null($module)) {
          if ( ($module == $class) && ($GLOBALS[$class]->enabled) ) {
            $include_quotes[] = $class;
          }
        } elseif ($GLOBALS[$class]->enabled) {
          $include_quotes[] = $class;
        }
      }

      $size = sizeof($include_quotes);
      for ($i=0; $i<$size; $i++) {
        $quotes = $GLOBALS[$include_quotes[$i]]->quote($method);
        if (is_array($quotes)) $quotes_array[] = $quotes;
      }
    }

    return $quotes_array;
  }

  function cheapest() {
    if (is_array($this->modules)) {
      $rates = array();

      reset($this->modules);
      while (list(, $value) = each($this->modules)) {
        $class = substr($value, 0, strrpos($value, '.'));
        if ($GLOBALS[$class]->enabled) {
          $quotes = $GLOBALS[$class]->quotes;
          $size = sizeof($quotes['methods']);
          for ($i=0; $i<$size; $i++) {
            //              if ($quotes['methods'][$i]['cost']) {
            if (isset($quotes['methods'][$i]['cost'])){
              $rates[] = array('id' => $quotes['id'] . '_' . $quotes['methods'][$i]['id'],
                               'title' => $quotes['module'] . ' (' . $quotes['methods'][$i]['title'] . ')',
                               'cost' => $quotes['methods'][$i]['cost'],
                               'module' => $quotes['id']
              );
            }
          }
        }
      }

      $cheapest = false;
      $size = sizeof($rates);
      for ($i=0; $i<$size; $i++) {
        // override normal cheapest and force UPS Ground
        if ($rates[$i]['id'] == 'GND') {
          $cheapest = $rates[$i];
          break;
        }
        if (is_array($cheapest)) {
          // never quote storepickup as lowest - needs to be configured in shipping module
          if ($rates[$i]['cost'] < $cheapest['cost'] and $rates[$i]['module'] != 'storepickup2') {
            $cheapest = $rates[$i];
          }
        } else {
          if ($rates[$i]['module'] != 'storepickup2') {
            $cheapest = $rates[$i];
          }
        }
      }

      return $cheapest;
    }
  }
}
?>

After logging out and in again it did stop choosing Local Delivery, but rather than selecting UPS Ground it jumped to a different (FREE) option. (We have local delivery for $8, store pickup for free and then UPS -- I Cloned storepickup for the local delivery -- that's why my code above shows "storepickup2")

If I turn off storepickup (the main one that is free store pickup) then no shipping options are pre-selected which is actually perfect :)

SO it's very close and I thank you for that. I imagine I'd have to edit something in the ups module to actually get it to select ground.

24 Dec 2010, 6:46 AM
#12
linnx avatar

linnx

Zen Follower

Join Date:
Jun 2009
Posts:
187
Plugin Contributions:
0

Re: Changing Default Shipping Option to FedEx instead of flat?

How can I apply this to a site with two options, ZONES (EMS) and TABLE. I want the ZONES to be the default.

I tried putting in 'ZONES' and 'EMS' in the code but nothing happened.

// override normal cheapest and force UPS Ground
if ($rates[$i]['id'] == 'EMS') {
$cheapest = $rates[$i];
break;
}

Thanks!

27 Dec 2010, 5:00 PM
#13
linnx avatar

linnx

Zen Follower

Join Date:
Jun 2009
Posts:
187
Plugin Contributions:
0

Re: Changing Default Shipping Option to FedEx instead of flat?

I probably shouldn't have written this during the holiday time! If anyone has a chance, please let me know how to use this code to make our ZONES be the default shipping method. Thanks again! Happy New Year! Let 2011 be a successful one!

linnx:

How can I apply this to a site with two options, ZONES (EMS) and TABLE. I want the ZONES to be the default.

I tried putting in 'ZONES' and 'EMS' in the code but nothing happened.

// override normal cheapest and force UPS Ground
if ($rates[$i]['id'] == 'EMS') {
$cheapest = $rates[$i];
break;
}

Thanks!

28 Dec 2010, 8:18 AM
#14
linnx avatar

linnx

Zen Follower

Join Date:
Jun 2009
Posts:
187
Plugin Contributions:
0

Re: Changing Default Shipping Option to FedEx instead of flat?

Think I got it..

I just changed...

if ($rates[$i]['cost'] < $cheapest['cost'] and $rates[$i]['module'] != 'storepickup') {

To the module I didn't want to be default. And since we are only using 2 modules, it goes to the one I want....