Forums / Addon Shipping Modules / HELP Zones Shipping (Extra Cost For Large Items)

HELP Zones Shipping (Extra Cost For Large Items)

Views: 1,935

Results 1 to 18 of 18
27 Jan 2014, 9:20 AM
#1
captainfacepalm avatar

captainfacepalm

New Zenner

Join Date:
Oct 2013
Location:
Andover
Posts:
13
Plugin Contributions:
0

HELP Zones Shipping (Extra Cost For Large Items)

I am running Zen Cart 1.3.9h with PHP Version 5.2.6

We currently have shipping set as £5.95 on all UK orders under £75 and free over £75, £20 for Europe and £40 for the rest of the world. But we carry some items such as medical fridges that are costly to ship and we need to charge an extra handling fee (£15) for these items we need some code that will allow us to add extra shipping costs of theses items. I was thinking there may be some way of setting an a rule if item XYZ then add £15 to shipping, I don't know if this is possible but it would be amazing if it was.

I have been reading Zen Cart forums and yet to find a solution that will do this for free I found one paid module that might do it (http://ceon.net/software/business/zen-cart/advanced-shipper).

The closest code I found for doing this was in a post about using the Free Shipping Options module that would seem easy enough to use but only allows one shipping zone so I need it to work on the php script I have attached this is the code that I found written by Ajeh on these forums;

// bof: check for oversized items and charge £15.00 extra per item
global $cart;
$chk_oversized = 0;
$oversized_title = '';
$chk_oversized += $_SESSION['cart']->in_cart_check('products_id', '1053');
$chk_oversized += $_SESSION['cart']->in_cart_check('products_id', '1046');
$chk_oversized += $_SESSION['cart']->in_cart_check('products_id', '3242');
$extra_shipping = $chk_oversized * 15.00;
if ($extra_shipping > 0) {
$oversized_title = '+ overweight shipping surcharge';
}

  if ($this->enabled) {
    $this->quotes = array('id' => $this->code,
                          'module' => MODULE_SHIPPING_FREEOPTIONS_TEXT_TITLE,
                          'methods' => array(array('id' => $this->code,
                                                   'title' => MODULE_SHIPPING_FREEOPTIONS_TEXT_WAY . $oversized_title,
                                                   'cost'  => MODULE_SHIPPING_FREEOPTIONS_COST + MODULE_SHIPPING_FREEOPTIONS_HANDLING + $extra_shipping)));

// eof: check for oversized items and charge £15.00 extra per item

Would I be able to use this code with the Zones Module? If not can someone suggest a code that will work. Or another module that would let me set an extra cost on the oversized items and still let us offer free shipping on other orders over £75 in the UK and the extra costs for international shipping.

Thank you so much.

28 Jan 2014, 3:46 PM
#2
ajeh avatar

ajeh

Oba-san

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

Re: HELP Zones Shipping (Extra Cost For Large Items)

You would need to edit the Zone Rates zones and the Free Shipping Options freeoptions for this ...

This would add that extra charge to both shipping methods ...

For the Zone Rates zones, edit the file with the code in RED:
/includes/modules/shipping/zones.php

[B]// bof: check for oversized items and charge £15.00 extra per item
global $cart;
$chk_oversized = 0;
$oversized_title = '';
$chk_oversized += $_SESSION['cart']->in_cart_check('products_id', '1053');
$chk_oversized += $_SESSION['cart']->in_cart_check('products_id', '1046');
$chk_oversized += $_SESSION['cart']->in_cart_check('products_id', '3242');
$extra_shipping = $chk_oversized * 15.00;
if ($extra_shipping > 0) {
$oversized_title = '+ overweight shipping surcharge';
} else {
  $oversized_title = '';
}
[/B]
      $this->quotes = array('id' => $this->code,
                            'module' => MODULE_SHIPPING_ZONES_TEXT_TITLE,
                            'methods' => array(array('id' => $this->code,
                                                     'title' => $shipping_method[B] . $oversized_title[/B],
                                                     'cost' => $shipping_cost[B] + $extra_shipping[/B])));

and the Free Shipping Options freeoptions with the code in RED:

      if ($this->enabled) {
[B]// bof: check for oversized items and charge £15.00 extra per item
global $cart;
$chk_oversized = 0;
$oversized_title = '';
$chk_oversized += $_SESSION['cart']->in_cart_check('products_id', '1053');
$chk_oversized += $_SESSION['cart']->in_cart_check('products_id', '1046');
$chk_oversized += $_SESSION['cart']->in_cart_check('products_id', '3242');
$extra_shipping = $chk_oversized * 15.00;
if ($extra_shipping > 0) {
$oversized_title = '+ overweight shipping surcharge';
} else {
  $oversized_title = '';
}
[/B]        $this->quotes = array('id' => $this->code,
                              'module' => MODULE_SHIPPING_FREEOPTIONS_TEXT_TITLE,
                              'methods' => array(array('id' => $this->code,
                                                       'title' => MODULE_SHIPPING_FREEOPTIONS_TEXT_WAY[B] . $oversized_title[/B],
                                                        'cost'  => MODULE_SHIPPING_FREEOPTIONS_COST +  MODULE_SHIPPING_FREEOPTIONS_HANDLING[B] + $extra_shipping[/B])));

see if that works for you correctly ...

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!

28 Jan 2014, 5:06 PM
#3
ajeh avatar

ajeh

Oba-san

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

Re: HELP Zones Shipping (Extra Cost For Large Items)

Check the code for the Zone Rates zones as I fixed the title on that in the post I made ...

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!

29 Jan 2014, 9:54 AM
#4
captainfacepalm avatar

captainfacepalm

New Zenner

Join Date:
Oct 2013
Location:
Andover
Posts:
13
Plugin Contributions:
0

Re: HELP Zones Shipping (Extra Cost For Large Items)

Hi when I put the codes into the files and upload them. When I try to go to check out I get a blank white screen.
I am attaching the full php code for each file here so you can tell me any mistake I make.

ZONES:

<?php

/**

 * @package shippingMethod

 * @copyright Copyright 2003-2009 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: zones.php 14498 2009-10-01 20:16:16Z ajeh $

 */

/*



  USAGE

  By default, the module comes with support for 3 zones.  This can be

  easily changed by editing the line below in the zones constructor

  that defines $this->num_zones.



  Next, you will want to activate the module by going to the Admin screen,

  clicking on Modules, then clicking on Shipping.  A list of all shipping

  modules should appear.  Click on the green dot next to the one labeled

  zones.php.  A list of settings will appear to the right.  Click on the

  Edit button.



  PLEASE NOTE THAT YOU WILL LOSE YOUR CURRENT SHIPPING RATES AND OTHER

  SETTINGS IF YOU TURN OFF THIS SHIPPING METHOD.  Make sure you keep a

  backup of your shipping settings somewhere at all times.



  If you want an additional handling charge applied to orders that use this

  method, set the Handling Fee field.



  Next, you will need to define which countries are in each zone.  Determining

  this might take some time and effort.  You should group a set of countries

  that has similar shipping charges for the same weight.  For instance, when

  shipping from the US, the countries of Japan, Australia, New Zealand, and

  Singapore have similar shipping rates.  As an example, one of my customers

  is using this set of zones:

    1: USA

    2: Canada

    3: Austria, Belgium, Great Britain, France, Germany, Greenland, Iceland,

       Ireland, Italy, Norway, Holland/Netherlands, Denmark, Poland, Spain,

       Sweden, Switzerland, Finland, Portugal, Israel, Greece

    4: Japan, Australia, New Zealand, Singapore

    5: Taiwan, China, Hong Kong



  When you enter these country lists, enter them into the Zone X Countries

  fields, where "X" is the number of the zone.  They should be entered as

  two character ISO country codes in all capital letters.  They should be

  separated by commas with no spaces or other punctuation. For example:

    1: US

    2: CA

    3: AT,BE,GB,FR,DE,GL,IS,IE,IT,NO,NL,DK,PL,ES,SE,CH,FI,PT,IL,GR

    4: JP,AU,NZ,SG

    5: TW,CN,HK



  Now you need to set up the shipping rate tables for each zone.  Again,

  some time and effort will go into setting the appropriate rates.  You

  will define a set of weight ranges and the shipping price for each

  range.  For instance, you might want an order than weighs more than 0

  and less than or equal to 3 to cost 5.50 to ship to a certain zone.

  This would be defined by this:  3:5.5



  You should combine a bunch of these rates together in a comma delimited

  list and enter them into the "Zone X Shipping Table" fields where "X"

  is the zone number.  For example, this might be used for Zone 1:

    1:3.5,2:3.95,3:5.2,4:6.45,5:7.7,6:10.4,7:11.85, 8:13.3,9:14.75,10:16.2,11:17.65,

    12:19.1,13:20.55,14:22,15:23.45



  The above example includes weights over 0 and up to 15.  Note that

  units are not specified in this explanation since they should be

  specific to your locale.



  CAVEATS

  At this time, it does not deal with weights that are above the highest amount

  defined.  This will probably be the next area to be improved with the

  module.  For now, you could have one last very high range with a very

  high shipping rate to discourage orders of that magnitude.  For

  instance:  999:1000



  If you want to be able to ship to any country in the world, you will

  need to enter every country code into the Country fields. For most

  shops, you will not want to enter every country.  This is often

  because of too much fraud from certain places. If a country is not

  listed, then the module will add a $0.00 shipping charge and will

  indicate that shipping is not available to that destination.

  PLEASE NOTE THAT THE ORDER CAN STILL BE COMPLETED AND PROCESSED!



  It appears that the osC shipping system automatically rounds the

  shipping weight up to the nearest whole unit.  This makes it more

  difficult to design precise shipping tables.  If you want to, you

  can hack the shipping.php file to get rid of the rounding.



  Lastly, there is a limit of 255 characters on each of the Zone

  Shipping Tables and Zone Countries.



*/



  class zones {

    var $code, $title, $description, $enabled, $num_zones;



// class constructor

    function zones() {

      $this->code = 'zones';

      $this->title = MODULE_SHIPPING_ZONES_TEXT_TITLE;

      $this->description = MODULE_SHIPPING_ZONES_TEXT_DESCRIPTION;

      $this->sort_order = MODULE_SHIPPING_ZONES_SORT_ORDER;

      $this->icon = '';

      $this->tax_class = MODULE_SHIPPING_ZONES_TAX_CLASS;

      $this->tax_basis = MODULE_SHIPPING_ZONES_TAX_BASIS;



      // disable only when entire cart is free shipping

      if (zen_get_shipping_enabled($this->code)) {

        $this->enabled = ((MODULE_SHIPPING_ZONES_STATUS == 'True') ? true : false);

      }



      // CUSTOMIZE THIS SETTING FOR THE NUMBER OF ZONES NEEDED

      $this->num_zones = 3;



      if (IS_ADMIN_FLAG === true) {

  		// build in admin only additional zones if missing in the configuration table due to customization of default $this->num_zones = 3

	  	  global $db;

  	  	for ($i = 1; $i <= $this->num_zones; $i++) {

  		  	$check = $db->Execute("select * from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_ZONES_COUNTRIES_" . $i . "'");

	  		  if ($this->enabled && $check->EOF) {

          $default_countries = '';

          $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Zone " . $i ." Countries', 'MODULE_SHIPPING_ZONES_COUNTRIES_" . $i ."', '" . $default_countries . "', 'Comma separated list of two character ISO country codes that are part of Zone " . $i . ".<br />Set as 00 to indicate all two character ISO country codes that are not specifically defined.', '6', '0', 'zen_cfg_textarea(', now())");

          $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Zone " . $i ." Shipping Table', 'MODULE_SHIPPING_ZONES_COST_" . $i ."', '3:8.50,7:10.50,99:20.00', 'Shipping rates to Zone " . $i . " destinations based on a group of maximum order weights/prices. Example: 3:8.50,7:10.50,... Weight/Price less than or equal to 3 would cost 8.50 for Zone " . $i . " destinations.<br />You can end the last amount as 10000:7% to charge 7% of the Order Total', '6', '0', 'zen_cfg_textarea(', now())");

          $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Zone " . $i ." Handling Fee', 'MODULE_SHIPPING_ZONES_HANDLING_" . $i."', '0', 'Handling Fee for this shipping zone', '6', '0', now())");

          $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Handling Per Order or Per Box Zone " . $i . "  (when by weight)' , 'MODULE_SHIPPING_ZONES_HANDLING_METHOD_" . $i."', 'Order', 'Do you want to charge Handling Fee Per Order or Per Box?', '6', '0', 'zen_cfg_select_option(array(\'Order\', \'Box\'), ', now())");

  		  	}

    		}

  	  } // build in admin only



      if ($this->enabled) {

        global $db;

  	  	for ($i = 1; $i <= $this->num_zones; $i++) {

          // check MODULE_SHIPPING_TABLE_HANDLING_METHOD is in

          $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_ZONES_HANDLING_METHOD_" . $i . "'");

          if ($check_query->EOF) {

            $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Handling Per Order or Per Box Zone " . $i . "  (when by weight)' , 'MODULE_SHIPPING_ZONES_HANDLING_METHOD_" . $i."', 'Order', 'Do you want to charge Handling Fee Per Order or Per Box?', '6', '0', 'zen_cfg_select_option(array(\'Order\', \'Box\'), ', now())");

          }

        }

      }

    }

// bof: check for oversized items and charge £15.00 extra per item
global $cart;
$chk_oversized = 0;
$oversized_title = '';
$chk_oversized += $_SESSION['cart']->in_cart_check('products_id', '1053');
$chk_oversized += $_SESSION['cart']->in_cart_check('products_id', '1046');
$chk_oversized += $_SESSION['cart']->in_cart_check('products_id', '3242');
$extra_shipping = $chk_oversized * 15.00;
if ($extra_shipping > 0) {
$oversized_title = '+ overweight shipping surcharge';
} else {
  $oversized_title = '';
}

      $this->quotes = array('id' => $this->code,
                            'module' => MODULE_SHIPPING_ZONES_TEXT_TITLE,
                            'methods' => array(array('id' => $this->code,
                                                     'title' => $shipping_method . $oversized_title,
                                                     'cost' => $shipping_cost + $extra_shipping)));

// class methods

    function quote($method = '') {

      global $order, $shipping_weight, $shipping_num_boxes, $total_count;

      $dest_country = $order->delivery['country']['iso_code_2'];

      $dest_zone = 0;

      $error = false;



    $order_total_amount = $_SESSION['cart']->show_total() - $_SESSION['cart']->free_shipping_prices() ;



      for ($i=1; $i<=$this->num_zones; $i++) {

        $countries_table = constant('MODULE_SHIPPING_ZONES_COUNTRIES_' . $i);

        $countries_table = strtoupper(str_replace(' ', '', $countries_table));

        $country_zones = preg_split("/[,]/", $countries_table);

        if (in_array($dest_country, $country_zones)) {

          $dest_zone = $i;

          break;

        }

        if (in_array('00', $country_zones)) {

          $dest_zone = $i;

          break;

        }

      }



      if ($dest_zone == 0) {

        $error = true;

      } else {

        $shipping = -1;

        $zones_cost = constant('MODULE_SHIPPING_ZONES_COST_' . $dest_zone);



        $zones_table = preg_split("/[:,]/" , $zones_cost);

        $size = sizeof($zones_table);

        $done = false;

        for ($i=0; $i<$size; $i+=2) {

          switch (MODULE_SHIPPING_ZONES_METHOD) {

        	  case (MODULE_SHIPPING_ZONES_METHOD == 'Weight'):

              if (round($shipping_weight,9) <= $zones_table[$i]) {

                $shipping = $zones_table[$i+1];



                switch (SHIPPING_BOX_WEIGHT_DISPLAY) {

                case (0):

                  $show_box_weight = '';

                  break;

                case (1):

                  $show_box_weight = ' (' . $shipping_num_boxes . ' ' . TEXT_SHIPPING_BOXES . ')';

                  break;

                case (2):

                  $show_box_weight = ' (' . number_format($shipping_weight * $shipping_num_boxes,2) . MODULE_SHIPPING_ZONES_TEXT_UNITS . ')';

                  break;

                default:

                  $show_box_weight = ' (' . $shipping_num_boxes . ' x ' . number_format($shipping_weight,2) . MODULE_SHIPPING_ZONES_TEXT_UNITS . ')';

                  break;

                }



//                $shipping_method = MODULE_SHIPPING_ZONES_TEXT_WAY . ' ' . $dest_country . (SHIPPING_BOX_WEIGHT_DISPLAY >= 2 ? ' : ' . $shipping_weight . ' ' . MODULE_SHIPPING_ZONES_TEXT_UNITS : '');

                $shipping_method = MODULE_SHIPPING_ZONES_TEXT_WAY . ' ' . $dest_country . $show_box_weight;

                $done = true;

        if (strstr($zones_table[$i+1], '%')) {

          $shipping = ($zones_table[$i+1]/100) * $order_total_amount;

        } else {

          $shipping = $zones_table[$i+1];

        }

                break;

        	    }

      	    break;

        	  case (MODULE_SHIPPING_ZONES_METHOD == 'Price'):

// shipping adjustment

              if (($_SESSION['cart']->show_total() - $_SESSION['cart']->free_shipping_prices()) <= $zones_table[$i]) {

                $shipping = $zones_table[$i+1];

                $shipping_method = MODULE_SHIPPING_ZONES_TEXT_WAY . ' ' . $dest_country;

        if (strstr($zones_table[$i+1], '%')) {

          $shipping = ($zones_table[$i+1]/100) * $order_total_amount;

        } else {

          $shipping = $zones_table[$i+1];

        }

                $done = true;

                break;

	            }

	          break;

        	  case (MODULE_SHIPPING_ZONES_METHOD == 'Item'):

// shipping adjustment

              if (($total_count - $_SESSION['cart']->free_shipping_items()) <= $zones_table[$i]) {

                $shipping = $zones_table[$i+1];

                $shipping_method = MODULE_SHIPPING_ZONES_TEXT_WAY . ' ' . $dest_country;

                $done = true;

        if (strstr($zones_table[$i+1], '%')) {

          $shipping = ($zones_table[$i+1]/100) * $order_total_amount;

        } else {

          $shipping = $zones_table[$i+1];

        }

                break;

  	          }

	          break;

          }

          if ($done == true) {

            break;

          }

        }



        if ($shipping == -1) {

          $shipping_cost = 0;

          $shipping_method = MODULE_SHIPPING_ZONES_UNDEFINED_RATE;

        } else {

          switch (MODULE_SHIPPING_ZONES_METHOD) {

        	  case (MODULE_SHIPPING_ZONES_METHOD == 'Weight'):

              // charge per box when done by Weight

              // Handling fee per box or order

              if (constant('MODULE_SHIPPING_ZONES_HANDLING_METHOD_' . $dest_zone) == 'Box') {

                $shipping_cost = ($shipping * $shipping_num_boxes) + constant('MODULE_SHIPPING_ZONES_HANDLING_' . $dest_zone) * $shipping_num_boxes;

              } else {

                $shipping_cost = ($shipping * $shipping_num_boxes) + constant('MODULE_SHIPPING_ZONES_HANDLING_' . $dest_zone);

              }

              break;

        	  case (MODULE_SHIPPING_ZONES_METHOD == 'Price'):

              // don't charge per box when done by Price

              $shipping_cost = ($shipping) + constant('MODULE_SHIPPING_ZONES_HANDLING_' . $dest_zone);

            break;

        	  case (MODULE_SHIPPING_ZONES_METHOD == 'Item'):

              // don't charge per box when done by Item

              $shipping_cost = ($shipping) + constant('MODULE_SHIPPING_ZONES_HANDLING_' . $dest_zone);

            break;

          }

        }

      }

      $this->quotes = array('id' => $this->code,

                            'module' => MODULE_SHIPPING_ZONES_TEXT_TITLE,

                            'methods' => array(array('id' => $this->code,

                                                     'title' => $shipping_method,

                                                     'cost' => $shipping_cost)));



      if ($this->tax_class > 0) {

        $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);

      }



      if (zen_not_null($this->icon)) $this->quotes['icon'] = zen_image($this->icon, $this->title);



      if (strstr(MODULE_SHIPPING_ZONES_SKIPPED, $dest_country)) {

        // don't show anything for this country

        $this->quotes = array();

      } else {

        if ($error == true) $this->quotes['error'] = MODULE_SHIPPING_ZONES_INVALID_ZONE;

      }



      return $this->quotes;

    }



    function check() {

      global $db;

      if (!isset($this->_check)) {

        $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_ZONES_STATUS'");

        $this->_check = $check_query->RecordCount();

      }

      return $this->_check;

    }



    function install() {

      global $db;

      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Enable Zones Method', 'MODULE_SHIPPING_ZONES_STATUS', 'True', 'Do you want to offer zone rate shipping?', '6', '0', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");

      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Calculation Method', 'MODULE_SHIPPING_ZONES_METHOD', 'Weight', 'Calculate cost based on Weight, Price or Item?', '6', '0', 'zen_cfg_select_option(array(\'Weight\', \'Price\', \'Item\'), ', now())");

      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Tax Class', 'MODULE_SHIPPING_ZONES_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '6', '0', 'zen_get_tax_class_title', 'zen_cfg_pull_down_tax_classes(', now())");

      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Tax Basis', 'MODULE_SHIPPING_ZONES_TAX_BASIS', 'Shipping', 'On what basis is Shipping Tax calculated. Options are<br />Shipping - Based on customers Shipping Address<br />Billing Based on customers Billing address<br />Store - Based on Store address if Billing/Shipping Zone equals Store zone', '6', '0', 'zen_cfg_select_option(array(\'Shipping\', \'Billing\', \'Store\'), ', now())");

      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_SHIPPING_ZONES_SORT_ORDER', '0', 'Sort order of display.', '6', '0', now())");

      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Skip Countries, use a comma separated list of the two character ISO country codes', 'MODULE_SHIPPING_ZONES_SKIPPED', '', 'Disable for the following Countries:', '6', '0', 'zen_cfg_textarea(', now())");



      for ($i = 1; $i <= $this->num_zones; $i++) {

        $default_countries = '';

        if ($i == 1) {

          $default_countries = 'US,CA';

        }

        $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Zone " . $i ." Countries', 'MODULE_SHIPPING_ZONES_COUNTRIES_" . $i ."', '" . $default_countries . "', 'Comma separated list of two character ISO country codes that are part of Zone " . $i . ".<br />Set as 00 to indicate all two character ISO country codes that are not specifically defined.', '6', '0', 'zen_cfg_textarea(', now())");

        $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Zone " . $i ." Shipping Table', 'MODULE_SHIPPING_ZONES_COST_" . $i ."', '3:8.50,7:10.50,99:20.00', 'Shipping rates to Zone " . $i . " destinations based on a group of maximum order weights/prices. Example: 3:8.50,7:10.50,... Weight/Price less than or equal to 3 would cost 8.50 for Zone " . $i . " destinations.<br />You can also use percentage amounts, such 25:8.50,35:5%,40:9.50,10000:7% to charge a percentage value of the Order Total', '6', '0', 'zen_cfg_textarea(', now())");

        $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Zone " . $i ." Handling Fee', 'MODULE_SHIPPING_ZONES_HANDLING_" . $i."', '0', 'Handling Fee for this shipping zone', '6', '0', now())");



        $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Handling Per Order or Per Box Zone " . $i . " (when by weight)' , 'MODULE_SHIPPING_ZONES_HANDLING_METHOD_" . $i."', 'Order', 'Do you want to charge Handling Fee Per Order or Per Box?', '6', '0', 'zen_cfg_select_option(array(\'Order\', \'Box\'), ', now())");



      }

    }



    function remove() {

      global $db;

      $db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key like 'MODULE\_SHIPPING\_ZONES\_%'");

    }



    function keys() {

      $keys = array('MODULE_SHIPPING_ZONES_STATUS', 'MODULE_SHIPPING_ZONES_METHOD', 'MODULE_SHIPPING_ZONES_TAX_CLASS', 'MODULE_SHIPPING_ZONES_TAX_BASIS', 'MODULE_SHIPPING_ZONES_SORT_ORDER', 'MODULE_SHIPPING_ZONES_SKIPPED');



      for ($i=1; $i<=$this->num_zones; $i++) {

        $keys[] = 'MODULE_SHIPPING_ZONES_COUNTRIES_' . $i;

        $keys[] = 'MODULE_SHIPPING_ZONES_COST_' . $i;

        $keys[] = 'MODULE_SHIPPING_ZONES_HANDLING_' . $i;

        $keys[] = 'MODULE_SHIPPING_ZONES_HANDLING_METHOD_' . $i;

      }



      return $keys;

    }

  }

?>
29 Jan 2014, 9:54 AM
#5
captainfacepalm avatar

captainfacepalm

New Zenner

Join Date:
Oct 2013
Location:
Andover
Posts:
13
Plugin Contributions:
0

Re: HELP Zones Shipping (Extra Cost For Large Items)

FREE OPTIONS:

 <?php
/**
 * @package shippingMethod
 * @copyright Copyright 2003-2009 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: freeoptions.php 14498 2009-10-01 20:16:16Z ajeh $
 */

  class freeoptions extends base {
    var $code, $title, $description, $icon, $enabled;
    var $ck_freeoptions_total, $ck_freeoptions_weight, $ck_freeoptions_items;

// class constructor
    function freeoptions() {
      global $order, $db;

      $this->code = 'freeoptions';
      $this->title = MODULE_SHIPPING_FREEOPTIONS_TEXT_TITLE;
      $this->description = MODULE_SHIPPING_FREEOPTIONS_TEXT_DESCRIPTION;
      $this->sort_order = MODULE_SHIPPING_FREEOPTIONS_SORT_ORDER;
      $this->icon = '';
      $this->tax_class = MODULE_SHIPPING_FREEOPTIONS_TAX_CLASS;
      $this->tax_basis = MODULE_SHIPPING_FREEOPTIONS_TAX_BASIS;

      // disable only when entire cart is free shipping
      if (zen_get_shipping_enabled($this->code)) {
          $this->enabled = ((MODULE_SHIPPING_FREEOPTIONS_STATUS == 'True') ? true : false);
      }

      if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_FREEOPTIONS_ZONE > 0) ) {
        $check_flag = false;
        $check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_FREEOPTIONS_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
        while (!$check->EOF) {
          if ($check->fields['zone_id'] < 1) {
            $check_flag = true;
            break;
          } elseif ($check->fields['zone_id'] == $order->delivery['zone_id']) {
            $check_flag = true;
            break;
          }
		  $check->MoveNext();
        }

        if ($check_flag == false) {
          $this->enabled = false;
        }
      }
    }

// class methods
    function quote($method = '') {
      global $order;
      $order_weight = round($_SESSION['cart']->show_weight(),9);

      // check if anything is configured for total, weight or item
      if ((MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN !='' or MODULE_SHIPPING_FREEOPTIONS_TOTAL_MAX !='')) {
        $this->ck_freeoptions_total = true;
      } else {
        $this->ck_freeoptions_total = false;
      }
      if ((MODULE_SHIPPING_FREEOPTIONS_WEIGHT_MIN !='' or MODULE_SHIPPING_FREEOPTIONS_WEIGHT_MAX !='')) {
        $this->ck_freeoptions_weight = true;
      } else {
        $this->ck_freeoptions_weight = false;
      }
      if ((MODULE_SHIPPING_FREEOPTIONS_ITEMS_MIN !='' or MODULE_SHIPPING_FREEOPTIONS_ITEMS_MAX !='')) {
        $this->ck_freeoptions_items = true;
      } else {
        $this->ck_freeoptions_items = false;
      }
      if ($this->ck_freeoptions_total or $this->ck_freeoptions_weight or $this->ck_freeoptions_items) {
        $this->enabled = true;
      } else {
        $this->enabled = false;
      }

   if ($this->enabled) {
// bof: check for oversized items and charge £15.00 extra per item
global $cart;
$chk_oversized = 0;
$oversized_title = '';
$chk_oversized += $_SESSION['cart']->in_cart_check('products_id', '1053');
$chk_oversized += $_SESSION['cart']->in_cart_check('products_id', '1046');
$chk_oversized += $_SESSION['cart']->in_cart_check('products_id', '3242');
$extra_shipping = $chk_oversized * 15.00;
if ($extra_shipping > 0) {
$oversized_title = '+ overweight shipping surcharge';
} else {
  $oversized_title = '';
}
        $this->quotes = array('id' => $this->code,
                              'module' => MODULE_SHIPPING_FREEOPTIONS_TEXT_TITLE,
                              'methods' => array(array('id' => $this->code,
                                                       'title' => MODULE_SHIPPING_FREEOPTIONS_TEXT_WAY . $oversized_title,
                                                        'cost'  => MODULE_SHIPPING_FREEOPTIONS_COST +  MODULE_SHIPPING_FREEOPTIONS_HANDLING + $extra_shipping)))    {  
// disabled if nothing validates for total, weight or item
      if ($this->enabled) {
        if ($this->ck_freeoptions_total) {
          switch (true) {
          case ((MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN !='' and MODULE_SHIPPING_FREEOPTIONS_TOTAL_MAX !='')):
// free shipping total should not need adjusting
//            if (($_SESSION['cart']->show_total() - $_SESSION['cart']->free_shipping_prices()) >= MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN and ($_SESSION['cart']->show_total() - $_SESSION['cart']->free_shipping_prices()) <= MODULE_SHIPPING_FREEOPTIONS_TOTAL_MAX) {
            if (($_SESSION['cart']->show_total()) >= MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN and ($_SESSION['cart']->show_total()) <= MODULE_SHIPPING_FREEOPTIONS_TOTAL_MAX) {
              $this->ck_freeoptions_total = true;
            } else {
              $this->ck_freeoptions_total = false;
            }
            break;
          case ((MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN !='')):
//            if (($_SESSION['cart']->show_total() - $_SESSION['cart']->free_shipping_prices()) >= MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN) {
            if (($_SESSION['cart']->show_total()) >= MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN) {
              $this->ck_freeoptions_total = true;
            } else {
              $this->ck_freeoptions_total = false;
            }
            break;
          case ((MODULE_SHIPPING_FREEOPTIONS_TOTAL_MAX !='')):
//            if (($_SESSION['cart']->show_total() - $_SESSION['cart']->free_shipping_prices()) <= MODULE_SHIPPING_FREEOPTIONS_TOTAL_MAX) {
            if (($_SESSION['cart']->show_total()) <= MODULE_SHIPPING_FREEOPTIONS_TOTAL_MAX) {
              $this->ck_freeoptions_total = true;
            } else {
              $this->ck_freeoptions_total = false;
            }
            break;
          }
        }

        if ($this->ck_freeoptions_weight) {
          switch (true) {
          case ((MODULE_SHIPPING_FREEOPTIONS_WEIGHT_MIN !='' and MODULE_SHIPPING_FREEOPTIONS_WEIGHT_MAX !='')):
            if ($order_weight >= MODULE_SHIPPING_FREEOPTIONS_WEIGHT_MIN and $order_weight <= MODULE_SHIPPING_FREEOPTIONS_WEIGHT_MAX) {
              $this->ck_freeoptions_weight = true;
            } else {
              $this->ck_freeoptions_weight = false;
            }
            break;
          case ((MODULE_SHIPPING_FREEOPTIONS_WEIGHT_MIN !='')):
            if ($order_weight >= MODULE_SHIPPING_FREEOPTIONS_WEIGHT_MIN) {
              $this->ck_freeoptions_weight = true;
            } else {
              $this->ck_freeoptions_weight = false;
            }
            break;
          case ((MODULE_SHIPPING_FREEOPTIONS_WEIGHT_MAX !='')):
            if ($order_weight <= MODULE_SHIPPING_FREEOPTIONS_WEIGHT_MAX) {
              $this->ck_freeoptions_weight = true;
            } else {
              $this->ck_freeoptions_weight = false;
            }
            break;
          }
        }

        if ($this->ck_freeoptions_items) {
          switch (true) {
          case ((MODULE_SHIPPING_FREEOPTIONS_ITEMS_MIN !='' and MODULE_SHIPPING_FREEOPTIONS_ITEMS_MAX !='')):
// free shipping items should not need adjusting
//            if (($_SESSION['cart']->count_contents() - $_SESSION['cart']->free_shipping_items()) >= MODULE_SHIPPING_FREEOPTIONS_ITEMS_MIN and ($_SESSION['cart']->count_contents() - $_SESSION['cart']->free_shipping_items()) <= MODULE_SHIPPING_FREEOPTIONS_ITEMS_MAX) {
            if (($_SESSION['cart']->count_contents()) >= MODULE_SHIPPING_FREEOPTIONS_ITEMS_MIN and ($_SESSION['cart']->count_contents()) <= MODULE_SHIPPING_FREEOPTIONS_ITEMS_MAX) {
              $this->ck_freeoptions_items = true;
            } else {
              $this->ck_freeoptions_items = false;
            }
            break;
          case ((MODULE_SHIPPING_FREEOPTIONS_ITEMS_MIN !='')):
//            if (($_SESSION['cart']->count_contents() - $_SESSION['cart']->free_shipping_items()) >= MODULE_SHIPPING_FREEOPTIONS_ITEMS_MIN) {
            if (($_SESSION['cart']->count_contents()) >= MODULE_SHIPPING_FREEOPTIONS_ITEMS_MIN) {
              $this->ck_freeoptions_items = true;
            } else {
              $this->ck_freeoptions_items = false;
            }
            break;
          case ((MODULE_SHIPPING_FREEOPTIONS_ITEMS_MAX !='')):
//            if (($_SESSION['cart']->count_contents() - $_SESSION['cart']->free_shipping_items())<= MODULE_SHIPPING_FREEOPTIONS_ITEMS_MAX) {
            if (($_SESSION['cart']->count_contents())<= MODULE_SHIPPING_FREEOPTIONS_ITEMS_MAX) {
              $this->ck_freeoptions_items = true;
            } else {
              $this->ck_freeoptions_items = false;
            }
            break;
          }
        }
      }

/*
echo 'I see count: ' . $_SESSION['cart']->count_contents() . ' free count: ' . $_SESSION['cart']->free_shipping_items() . '<br>' .
'I see weight: ' . $_SESSION['cart']->show_weight() . '<br>' .
'I see total: ' . $_SESSION['cart']->show_total() . ' free price: ' . $_SESSION['cart']->free_shipping_prices() . '<br>' .
'Final check ' . ($this->ck_freeoptions_total ? 'T: YES ' : 'T: NO ') . ($this->ck_freeoptions_weight ? 'W: YES ' : 'W: NO ') . ($this->ck_freeoptions_items ? 'I: YES ' : 'I: NO ') . '<br>';
*/

// final check for display of Free Options
      if ($this->ck_freeoptions_total or $this->ck_freeoptions_weight or $this->ck_freeoptions_items) {
        $this->enabled = true;
      } else {
        $this->enabled = false;
      }

      if ($this->enabled) {
        $this->quotes = array('id' => $this->code,
                              'module' => MODULE_SHIPPING_FREEOPTIONS_TEXT_TITLE,
                              'methods' => array(array('id' => $this->code,
                                                       'title' => MODULE_SHIPPING_FREEOPTIONS_TEXT_WAY,
                                                       'cost'  => MODULE_SHIPPING_FREEOPTIONS_COST + MODULE_SHIPPING_FREEOPTIONS_HANDLING)));

        if ($this->tax_class > 0) {
          $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
        }

        if (zen_not_null($this->icon)) $this->quotes['icon'] = zen_image($this->icon, $this->title);
      }

      return $this->quotes;
    }

    function check() {
      global $db;
      if (!isset($this->_check)) {
        $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_FREEOPTIONS_STATUS'");
        $this->_check = $check_query->RecordCount();
      }
      return $this->_check;
    }

    function install() {
      global $db;
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Free Options Shipping', 'MODULE_SHIPPING_FREEOPTIONS_STATUS', 'True', 'Free Options is used to display a Free Shipping option when other Shipping Modules are displayed.
It can be based on: Always show, Order Total, Order Weight or Order Item Count.
The Free Options module does not show when Free Shipper is displayed.<br /><br />
Setting Total to >= 0.00 and <= nothing (leave blank) will activate this module to show with all shipping modules, except for Free Shipping - freeshipper.<br /><br />
NOTE: Leaving all settings for Total, Weight and Item count blank will deactivate this module.<br /><br />
NOTE: Free Shipping Options does not display if Free Shipping is used based on 0 weight is Free Shipping.
See: freeshipper<br /><br />Do you want to offer per freeoptions rate shipping?', '6', '0', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Shipping Cost', 'MODULE_SHIPPING_FREEOPTIONS_COST', '0.00', 'The shipping cost will be $0.00', '6', '0', now())");
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Handling Fee', 'MODULE_SHIPPING_FREEOPTIONS_HANDLING', '0', 'Handling fee for this shipping method.', '6', '0', now())");

      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Total >=', 'MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN', '0.00', 'Free Shipping when Total >=', '6', '0', now())");
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Total <=', 'MODULE_SHIPPING_FREEOPTIONS_TOTAL_MAX', '', 'Free Shipping when Total <=', '6', '0', now())");

      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Weight >=', 'MODULE_SHIPPING_FREEOPTIONS_WEIGHT_MIN', '', 'Free Shipping when Weight >=', '6', '0', now())");
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Weight <=', 'MODULE_SHIPPING_FREEOPTIONS_WEIGHT_MAX', '', 'Free Shipping when Weight <=', '6', '0', now())");

      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Item Count >=', 'MODULE_SHIPPING_FREEOPTIONS_ITEMS_MIN', '', 'Free Shipping when Item Count >=', '6', '0', now())");
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Item Count <=', 'MODULE_SHIPPING_FREEOPTIONS_ITEMS_MAX', '', 'Free Shipping when Item Count <=', '6', '0', now())");

      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Tax Class', 'MODULE_SHIPPING_FREEOPTIONS_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '6', '0', 'zen_get_tax_class_title', 'zen_cfg_pull_down_tax_classes(', now())");
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Tax Basis', 'MODULE_SHIPPING_FREEOPTIONS_TAX_BASIS', 'Shipping', 'On what basis is Shipping Tax calculated. Options are<br />Shipping - Based on customers Shipping Address<br />Billing Based on customers Billing address<br />Store - Based on Store address if Billing/Shipping Zone equals Store zone', '6', '0', 'zen_cfg_select_option(array(\'Shipping\', \'Billing\', \'Store\'), ', now())");
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Shipping Zone', 'MODULE_SHIPPING_FREEOPTIONS_ZONE', '0', 'If a zone is selected, only enable this shipping method for that zone.', '6', '0', 'zen_get_zone_class_title', 'zen_cfg_pull_down_zone_classes(', now())");
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_SHIPPING_FREEOPTIONS_SORT_ORDER', '0', 'Sort order of display.', '6', '0', now())");
    }

   function remove() {
     global $db;
     $db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key LIKE  'MODULE\_SHIPPING\_FREEOPTIONS\_%'");
   }

    function keys() {
      return array('MODULE_SHIPPING_FREEOPTIONS_STATUS', 'MODULE_SHIPPING_FREEOPTIONS_COST', 'MODULE_SHIPPING_FREEOPTIONS_HANDLING', 'MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN', 'MODULE_SHIPPING_FREEOPTIONS_TOTAL_MAX', 'MODULE_SHIPPING_FREEOPTIONS_WEIGHT_MIN', 'MODULE_SHIPPING_FREEOPTIONS_WEIGHT_MAX', 'MODULE_SHIPPING_FREEOPTIONS_ITEMS_MIN', 'MODULE_SHIPPING_FREEOPTIONS_ITEMS_MAX', 'MODULE_SHIPPING_FREEOPTIONS_TAX_CLASS', 'MODULE_SHIPPING_FREEOPTIONS_TAX_BASIS', 'MODULE_SHIPPING_FREEOPTIONS_ZONE', 'MODULE_SHIPPING_FREEOPTIONS_SORT_ORDER');
    }
  }
?> 

I hope this is helpful to you.

29 Jan 2014, 1:45 PM
#6
ajeh avatar

ajeh

Oba-san

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

Re: HELP Zones Shipping (Extra Cost For Large Items)

You do not really have in your code these tags for:

[ COLOR="#FF0000" ]
[ /COLOR ]

Do you?

If so you need to remove them they are not part of the code ...

Otherwise, look at your debug logs in either /logs or /cache depending on your version and see what the error messages are when you get the white screen ...

It sounds like spaces/blank lines before/after the opening <?php or closing ?> tags in the file ...

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!

29 Jan 2014, 2:08 PM
#7
captainfacepalm avatar

captainfacepalm

New Zenner

Join Date:
Oct 2013
Location:
Andover
Posts:
13
Plugin Contributions:
0

Re: HELP Zones Shipping (Extra Cost For Large Items)

The colour codes are not part of the code I was trying to highlight where I had placed the coded you gave me in the php file I shall check for the blanks.

I will get back to you if I get it working.

Cheers

29 Jan 2014, 2:27 PM
#8
ajeh avatar

ajeh

Oba-san

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

Re: HELP Zones Shipping (Extra Cost For Large Items)

Also the new code for the Free Shipping Options freeoptions is in the wrong place ...

It should be under:

// final check for display of Free Options
      if ($this->ck_freeoptions_total or $this->ck_freeoptions_weight or $this->ck_freeoptions_items) {
        $this->enabled = true;
      } else {
        $this->enabled = false;
      }

and just inside the:

      if ($this->enabled) {

You should be including only the new code and not the existing code ... the new code is in RED ...

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!

30 Jan 2014, 3:56 PM
#9
captainfacepalm avatar

captainfacepalm

New Zenner

Join Date:
Oct 2013
Location:
Andover
Posts:
13
Plugin Contributions:
0

Re: HELP Zones Shipping (Extra Cost For Large Items)

Awesome that works really well.

Before I leave you be is there a way to make only charge the £15 once per order rather than charging it for each item?

BTW I have brought the Zen Cart team doughnuts and coffee.

30 Jan 2014, 4:20 PM
#10
ajeh avatar

ajeh

Oba-san

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

Re: HELP Zones Shipping (Extra Cost For Large Items)

Thanks for the update that this is working for you ...

You can change how much is charged based on the line:

$extra_shipping = $chk_oversized * 15.00;

That is charging 15.00 * the number of Products found ...

If you only want 15.00 charged, regardless of the quantity, then use:

$extra_shipping = 15.00;

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!

12 Apr 2014, 1:17 PM
#11
simon1066 avatar

simon1066

Totally Zenned

Join Date:
Feb 2009
Location:
UK
Posts:
1,326
Plugin Contributions:
0

Re: HELP Zones Shipping (Extra Cost For Large Items)

Ajeh:

You would need to edit the Zone Rates zones and the Free Shipping Options freeoptions for this ...

This would add that extra charge to both shipping methods ...

For the Zone Rates zones, edit the file with the code in RED:
/includes/modules/shipping/zones.php

[B]// bof: check for oversized items and charge £15.00 extra per item
global $cart;
$chk_oversized = 0;
$oversized_title = '';
$chk_oversized += $_SESSION['cart']->in_cart_check('products_id', '1053');
$chk_oversized += $_SESSION['cart']->in_cart_check('products_id', '1046');
$chk_oversized += $_SESSION['cart']->in_cart_check('products_id', '3242');
$extra_shipping = $chk_oversized * 15.00;
if ($extra_shipping > 0) {
$oversized_title = '+ overweight shipping surcharge';
} else {
$oversized_title = '';
}
[/B]

$this->quotes = array('id' => $this->code,
'module' => MODULE_SHIPPING_ZONES_TEXT_TITLE,
'methods' => array(array('id' => $this->code,
'title' => $shipping_method[B] . $oversized_title[/B],
'cost' => $shipping_cost[B] + $extra_shipping[/B])));


So glad I came across this bit of code. I've applied it to a Table Rate clone and I want to be able to check the cart for an oversized item as defined by its attribute. Just adding 

$chk_oversized += $_SESSION['cart']->in_cart_check('products_attributes_id', '8');


It may be that I need to code another function in includes\classes\shopping_cart.php to allow for a check in TABLE_PRODUCTS_ATTRIBUTES, just guessing really. Does anyone have any suggestions as to how to include an attribute check in this oversized items code?

Simon

12 Apr 2014, 2:33 PM
#12
simon1066 avatar

simon1066

Totally Zenned

Join Date:
Feb 2009
Location:
UK
Posts:
1,326
Plugin Contributions:
0

Re: HELP Zones Shipping (Extra Cost For Large Items)

Well blow me down! It seems I was on the right track.

I added

$chk_oversized += $_SESSION['cart']->in_cart_check_attrib('products_attributes_id', '8');

into Ajeh's code and created this new function in shopping_cart.php

/* Method to calculate the number of items in a cart based on an attribute property */
  
   function in_cart_check_attrib($check_what, $check_value='1') {
    global $db;
    // if nothing is in cart return 0
    if (!is_array($this->contents)) return 0;

    // compute total quantity for field
    $in_cart_check_qty=0;

    reset($this->contents);
    while (list($products_id, ) = each($this->contents)) {
      $testing_id = zen_get_prid($products_id);
      // check if field it true
      $product_check = $db->Execute("select " . $check_what . " as check_it from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id='" . $testing_id . "' limit 1");
      if ($product_check->fields['check_it'] == $check_value) {
        $in_cart_check_qty += $this->contents[$products_id]['qty'];
      }
    }
    return $in_cart_check_qty;
  }

Seems to work fine.

Simon

12 Apr 2014, 3:02 PM
#13
simon1066 avatar

simon1066

Totally Zenned

Join Date:
Feb 2009
Location:
UK
Posts:
1,326
Plugin Contributions:
0

Re: HELP Zones Shipping (Extra Cost For Large Items)

Ok, still need a bit of help on this.

The 'check for oversized items' is identifying the product just because it has the desired attribute, not because the product has that attribute selected in the shopping cart.

Suggestions welcome.

Simon

12 Apr 2014, 3:06 PM
#14
ajeh avatar

ajeh

Oba-san

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

Re: HELP Zones Shipping (Extra Cost For Large Items)

Is this products_attributes_id 8 the only Attribute on this Product?

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!

12 Apr 2014, 3:20 PM
#15
simon1066 avatar

simon1066

Totally Zenned

Join Date:
Feb 2009
Location:
UK
Posts:
1,326
Plugin Contributions:
0

Re: HELP Zones Shipping (Extra Cost For Large Items)

No, it also has a products_attributes_id of '7'

No Frame - products_attributes_id 7 (options_values_id 2)
With Frame - products_attributes_id 8 (options_values_id 1)

Only some products have a frame option

It is products 'With Frame' that need to be classed as oversized

Simon

12 Apr 2014, 7:22 PM
#16
ajeh avatar

ajeh

Oba-san

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

Re: HELP Zones Shipping (Extra Cost For Large Items)

Would something like this work for you?

/* Method to calculate the number of items in a cart based on an attribute option_id and option_values_id combo */
// example: $_SESSION['cart']->in_cart_check_attrib_quantity(1, 16)

  function in_cart_check_attrib_quantity($check_option_id, $check_option_values_id) {
//    global $db;
    // if nothing is in cart return 0
    if (!is_array($this->contents)) return 0;

    // compute total quantity for field
    $in_cart_check_qty = 0;

    $chk_products = $this->get_products();
    for ($i=0, $n=sizeof($chk_products); $i<$n; $i++) {
      foreach ($chk_products[$i]['attributes'] as $option => $value) {
        if ($option == $check_option_id && $value == $check_option_values_id) {
//          echo 'Attribute FOUND FOR $option: ' . $option . ' $value: ' . $value . ' quantity: ' . $chk_products[$i]['quantity'] . '<br><br>';
          $in_cart_check_qty += $chk_products[$i]['quantity'];
        }
      }
    }
    return $in_cart_check_qty;
  }

I have an idea to expand a similar function with more flexibility in the future but I am still giving it a think ...:lookaroun

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!

13 Apr 2014, 7:26 AM
#17
simon1066 avatar

simon1066

Totally Zenned

Join Date:
Feb 2009
Location:
UK
Posts:
1,326
Plugin Contributions:
0

Re: HELP Zones Shipping (Extra Cost For Large Items)

Ajeh:

Would something like this work for you?

/* Method to calculate the number of items in a cart based on an attribute option_id and option_values_id combo */
// example: $_SESSION['cart']->in_cart_check_attrib_quantity(1, 16)

function in_cart_check_attrib_quantity($check_option_id, $check_option_values_id) {
// global $db;
// if nothing is in cart return 0
if (!is_array($this->contents)) return 0;

// compute total quantity for field
$in_cart_check_qty = 0;

$chk_products = $this->get_products();
for ($i=0, $n=sizeof($chk_products); $i<$n; $i++) {
  foreach ($chk_products[$i]['attributes'] as $option => $value) {
    if ($option == $check_option_id && $value == $check_option_values_id) {

// echo 'Attribute FOUND FOR $option: ' . $option . ' $value: ' . $value . ' quantity: ' . $chk_products[$i]['quantity'] . '<br><br>';
$in_cart_check_qty += $chk_products[$i]['quantity'];
}
}
}
return $in_cart_check_qty;
}

> 
> I have an idea to expand a similar function with more flexibility in the future but I am still giving it a think ...:lookaroun


I think that is exactly what I needed, the couple of checks I've made seem to work well - I'll test more once I've fully set up my shipping and hopefully give some feedback/suggestions for your future design.

This last bit of help was all I needed to finalise my shipping costs (until I find something else!) so thank you very much.

I've sent the Team a coffee and donut.

Cheers

Simon

Simon

13 Apr 2014, 12:54 PM
#18
ajeh avatar

ajeh

Oba-san

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

Re: HELP Zones Shipping (Extra Cost For Large Items)

Thanks for the update that this was able to work for you ...

The Zen Cart Team also appreciates the support ... we really love those coffees and donuts! :cool:

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!