Hi gang. I've just installed the First Item, Plus Additional Items Shipping Module from here:
http://www.oscommerce.com/community/contributions,1852 . I'm running 2.2.
I needed to add the ability to select a tax class for this shipping module so GST could be applied to Canadian orders. It worked for me, and here's the code in case anyone wants to use it:
(bear in mind that I'm a semi-n00b to PHP and MySQL so I make no guarantees here. BACK UP!!!!
If anyone notices anything stupid that I did wrong, I have thick skin. Point it out please.
<?php
/*
$Id: firstitemplus.php,v 1.0x 2004/02/06
by MF, modeled after:
$Id: table.php,v 1.26x 2003/01/31 $
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
Copyright (c) 2003 osCommerce
* Modifications by Christian Lescuyer <
[email protected]>
* Copyright (c) 2003 Go?lette http://www.goelette.net
Released under the GNU General Public License
*/
class firstitemplus {
var $code, $title, $description, $icon, $enabled;
// class constructor
function firstitemplus() {
global $order;
$this->code = 'firstitemplus';
$this->title = MODULE_SHIPPING_FIRSTITEMPLUS_TEXT_TITLE;
$this->description = MODULE_SHIPPING_FIRSTITEMPLUS_TEXT_DESCRIPTION;
$this->sort_order = MODULE_SHIPPING_FIRSTITEMPLUS_SORT_ORDER;
$this->icon = '';
$this->tax_class = MODULE_SHIPPING_FIRSTITEMPLUS_TAX_CLASS;
$this->enabled = ((MODULE_SHIPPING_FIRSTITEMPLUS_STATUS == 'True') ? true : false);
if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_FIRSTITEMPLUS_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_FIRSTITEMPLUS_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;
}
}
}
// class methods
function quote($method = '') {
global $cart, $shipping_weight, $shipping_num_boxes;
$order_total = $cart->count_contents();
$table_cost_first = MODULE_SHIPPING_FIRSTITEMPLUS_FIRST;
$table_cost_additional = MODULE_SHIPPING_FIRSTITEMPLUS_ADDITIONAL;
$shipping = ($order_total < 2) ? $table_cost_first : ($table_cost_first + (($order_total - 1) * $table_cost_additional));
$this->quotes = array('id' => $this->code,
'module' => MODULE_SHIPPING_FIRSTITEMPLUS_TEXT_TITLE,
'methods' => array(array('id' => $this->code,
'title' => sprintf(MODULE_SHIPPING_FIRSTITEMPLUS_TEXT_WAY,$table_cost_first,$table_cost_additional),
'cost' => $shipping + MODULE_SHIPPING_FIRSTITEMPLUS_HANDLING)));
if (tep_not_null($this->icon)) $this->quotes['icon'] = tep_image($this->icon, $this->title);
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_FIRSTITEMPLUS_STATUS'");
$this->_check = tep_db_num_rows($check_query);
}
return $this->_check;
}
function install() {
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Enable First Item Plus Additional Method', 'MODULE_SHIPPING_FIRSTITEMPLUS_STATUS', 'True', 'Do you want to offer \"First item $X, additional items $X\" shipping?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Shipping Cost for First Item', 'MODULE_SHIPPING_FIRSTITEMPLUS_FIRST', '6.00', 'The shipping cost is calculated using a cost for the the first item, then another cost for each additional item. Enter the cost of the first item (without dollar sign):', '6', '0', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Shipping Cost for Additional Items', 'MODULE_SHIPPING_FIRSTITEMPLUS_ADDITIONAL', '1.00', 'Cost per additional item (without dollar sign):', '6', '0', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Handling Fee', 'MODULE_SHIPPING_FIRSTITEMPLUS_HANDLING', '0', 'Additional handling fee for this shipping method.', '6', '0', now())");
tep_db_query("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_FIRSTITEMPLUS_ZONE', '0', 'If a zone is selected, only enable this shipping method for that zone.', '6', '0', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', now())");
tep_db_query("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_FIRSTITEMPLUS_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '6', '0', 'tep_get_tax_class_title', 'tep_cfg_pull_down_tax_classes(', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort order of display.', 'MODULE_SHIPPING_FIRSTITEMPLUS_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
}
function remove() {
tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
}
function keys() {
return array('MODULE_SHIPPING_FIRSTITEMPLUS_STATUS', 'MODULE_SHIPPING_FIRSTITEMPLUS_FIRST', 'MODULE_SHIPPING_FIRSTITEMPLUS_ADDITIONAL', 'MODULE_SHIPPING_FIRSTITEMPLUS_HANDLING', 'MODULE_SHIPPING_FIRSTITEMPLUS_ZONE', 'MODULE_SHIPPING_FIRSTITEMPLUS_TAX_CLASS', 'MODULE_SHIPPING_FIRSTITEMPLUS_SORT_ORDER');
}
}
?>