Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Boxes per Categories (Zones Rates -> Swiss Post Shipping Contrib)


sopinon

Recommended Posts

Hi there,

 

I have only one Shipping Module active (Swiss Post Shipping). This Shipping module is based on "Zones Rates".

 

It work's fine. But I want to extend this module... If there are Products in the Shopping Cart from different Product Categories. It should split the shipping in "n"-boxes (one per Category).

 

Example:

Categories: T-Shirts, Shoes

 

Shopping Cart:

1 T-Shirt blue 0.5 k weight

1 T-Shirt red 0.5k weight

1 Nike Shoes 1.5k weight

 

Shipping Boxes:

(1 x 1k) -> price

(1 x 1.5k) -> price

 

How could i implement this? Here is the link to the Swiss Post Shipping Contribution (only 1 php module file): http://www.oscommerce.com/community/contributions,997

 

<?php
/*
 $Id: chp.php,v 1.02 2003/02/18 03:37:00 harley_vb Exp $

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2002 - 2003 osCommerce

 Released under the GNU General Public License

 Patches:
 - tom 001: Prices changed per 27.7.2006

*/

/********************************************************************
*	Copyright (C) 2001 - 2003 TheMedia, Dipl.-Ing Thomas Plänkers
*	   http://www.themedia.at & http://www.oscommerce.at
*
*					All rights reserved
*
* This program is free software licensed under the GNU General Public License (GPL).
*
*	This program is free software; you can redistribute it and/or modify
*	it under the terms of the GNU General Public License as published by
*	the Free Software Foundation; either version 2 of the License, or
*	(at your option) any later version.
*
*	This program is distributed in the hope that it will be useful,
*	but WITHOUT ANY WARRANTY; without even the implied warranty of
*	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*	GNU General Public License for more details.
*
*	You should have received a copy of the GNU General Public License
*	along with this program; if not, write to the Free Software
*	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
*	USA
*
*********************************************************************/

 class chp {
var $code, $title, $description, $icon, $enabled, $num_chp, $types;

// class constructor
function chp() {
  global $order;

  $this->code		 = 'chp';
  $this->title		= MODULE_SHIPPING_CHP_TEXT_TITLE;
  $this->description  = MODULE_SHIPPING_CHP_TEXT_DESCRIPTION;
  $this->sort_order   = MODULE_SHIPPING_CHP_SORT_ORDER;
  $this->icon		 = DIR_WS_ICONS . 'shipping_chp.gif';
  $this->tax_class	= MODULE_SHIPPING_CHP_TAX_CLASS;
  $this->enabled	  = ((MODULE_SHIPPING_CHP_STATUS == 'True') ? true : false);

  if (   ($this->enabled == true)
	  && ((int)MODULE_SHIPPING_CHP_ZONE > 0) ) {
	$check_flag = false;
	$check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_CHP_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
	while ($check = tep_db_fetch_array($check_query)) {
	  if ($check['zone_id'] < 1) {
		$check_flag = true;
		break;
	  } elseif ($check['zone_id'] == $order->delivery['zone_id']) {
		$check_flag = true;
		break;
	  }
	}

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

  $this->types = array('ECO' => 'Economy',
					   'PRI' => 'Priority',
					   'URG' => 'Urgent');

  // CUSTOMIZE THIS SETTING FOR THE NUMBER OF ZONES NEEDED
  $this->num_chp = 6;   // ch + 5 Zonen
}

// class methods
function quote($method = '') {
  global $HTTP_POST_VARS, $order, $shipping_weight, $shipping_num_boxes;

  $dest_country = $order->delivery['country']['iso_code_2'];
  $dest_zone = 0;
  $error = false;

  if ($shipping_weight - SHIPPING_BOX_WEIGHT == 0)
		$free_shipping = 0;
  else
		$free_shipping = 1;

  for ($j=1; $j<=$this->num_chp; $j++) {
	$countries_table = constant('MODULE_SHIPPING_CHP_COUNTRIES_' . $j);
	$country_zones = split("[,]", $countries_table);
	if (in_array($dest_country, $country_zones)) {
	  $dest_zone = $j;
	  break;
	}
  }

  if ($dest_zone == 0) {
	$error = true;
  } else {
	$shipping = -1;
	$chp_cost_eco = @constant('MODULE_SHIPPING_CHP_COST_ECO_' . $j);
	$chp_cost_pri = @constant('MODULE_SHIPPING_CHP_COST_PRI_' . $j);
	$chp_cost_urg = @constant('MODULE_SHIPPING_CHP_COST_URG_' . $j);

	$methods = array();

	if ($chp_cost_eco != '') {
	  $chp_table_eco = split("[:,]" , $chp_cost_eco);

	  for ($i=0; $i<sizeof($chp_table_eco); $i+=2) {
		if ($shipping_weight <= $chp_table_eco[$i]) {
		  $shipping_eco = $chp_table_eco[$i+1];
		  break;
		}
	  }

	  if ($shipping_eco == -1) {
		$shipping_cost = 0;
		$shipping_method = MODULE_SHIPPING_CHP_UNDEFINED_RATE;
	  } else {
		$shipping_cost_1 = ($shipping_eco + MODULE_SHIPPING_CHP_HANDLING);
	  }

	  if ($shipping_eco != 0) {
		$methods[] = array('id' => 'ECO',
						   'title' => 'Economy',
						   'cost' => (MODULE_SHIPPING_CHP_HANDLING + $shipping_cost_1) * $shipping_num_boxes * $free_shipping);
	  }
	}

	if ($chp_cost_pri != '') {
	  $chp_table_pri = split("[:,]" , $chp_cost_pri);

	  for ($i=0; $i<sizeof($chp_table_pri); $i+=2) {
		if ($shipping_weight <= $chp_table_pri[$i]) {
		  $shipping_pri = $chp_table_pri[$i+1];
		  break;
		}
	  }

	  if ($shipping_pri == -1) {
		$shipping_cost = 0;
		$shipping_method = MODULE_SHIPPING_CHP_UNDEFINED_RATE;
	  } else {
		$shipping_cost_2 = ($shipping_pri + MODULE_SHIPPING_CHP_HANDLING);
	  }

	  if ($shipping_pri != 0) {
		$methods[] = array('id' => 'PRI',
						   'title' => 'Priority',
						   'cost' => (MODULE_SHIPPING_CHP_HANDLING + $shipping_cost_2) * $shipping_num_boxes * $free_shipping);
	  }
	}

	if ($chp_cost_urg != '') {
	  $chp_table_urg = split("[:,]" , $chp_cost_urg);

	  for ($i=0; $i<sizeof($chp_table_urg); $i+=2) {
		if ($shipping_weight <= $chp_table_urg[$i]) {
		  $shipping_urg = $chp_table_urg[$i+1];
		  break;
		}
	  }

	  if ($shipping_urg == -1) {
		$shipping_cost = 0;
		$shipping_method = MODULE_SHIPPING_CHP_UNDEFINED_RATE;
	  } else {
		$shipping_cost_3 = ($shipping_urg + MODULE_SHIPPING_CHP_HANDLING);
	  }

	  if ($shipping_urg != 0) {
		$methods[] = array('id'	 => 'URG',
						   'title'  => 'Urgent',
						   'cost'   => (MODULE_SHIPPING_CHP_HANDLING + $shipping_cost_3) * $shipping_num_boxes * $free_shipping);
	  }
	}
  }

  $this->quotes = array('id' => $this->code,
						'module' => $this->title . ' (' . $shipping_num_boxes . ' x ' . $shipping_weight . ' ' . MODULE_SHIPPING_CHP_TEXT_UNITS .')');
  $this->quotes['methods'] = $methods;

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

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

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

  if ( (tep_not_null($method)) && (isset($this->types[$method])) ) {

	for ($i=0; $i<sizeof($methods); $i++) {
	  if ($method == $methods[$i]['id']) {
		$methodsc = array();
		$methodsc[] = array('id' => $methods[$i]['id'],
							'title' => $methods[$i]['title'],
							'cost' => $methods[$i]['cost']);
		break;
	  }
	}
	$this->quotes['methods'] = $methodsc;
  }

  return $this->quotes;
}

function check() {
  if (!isset($this->_check)) {
	$check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_CHP_STATUS'");
	$this->_check = tep_db_num_rows($check_query);
  }
  return $this->_check;
}

function install() {
  // (...) Configuration (...) skipped
}

function remove() {
  tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
}

function keys() {
  $keys = array('MODULE_SHIPPING_CHP_STATUS', 'MODULE_SHIPPING_CHP_HANDLING', 'MODULE_SHIPPING_CHP_TAX_CLASS', 'MODULE_SHIPPING_CHP_ZONE', 'MODULE_SHIPPING_CHP_SORT_ORDER');

  for ($i=1; $i <= $this->num_chp; $i++) {
	$keys[count($keys)] = 'MODULE_SHIPPING_CHP_COUNTRIES_' . $i;
	$keys[count($keys)] = 'MODULE_SHIPPING_CHP_COST_ECO_' . $i;
	$keys[count($keys)] = 'MODULE_SHIPPING_CHP_COST_PRI_' . $i;
	$keys[count($keys)] = 'MODULE_SHIPPING_CHP_COST_URG_' . $i;
  }

  return $keys;
}
 }
?>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...