Will this also work in the "Per Unit"(by weight) shipping module?
Lisa
Printable View
Same concept but you have to adapt the code for that shipping module ...
Okay sounds easy,(probably isn't) lol, I'm going to give it a try.
Okay so putting that bit of code into the perweightunit.php didn't work..... can somebody tell me where to put the code in and if it would be the same code that was used for the USPS module?
Thanks again!
Lisa
This is a constant:
MODULE_SHIPPING_UPS_HANDLING
all of the shipping modules have unique constants ...
For UPS it uses:
MODULE_SHIPPING_UPS_HANDLING
For Per Unit it uses:
MODULE_SHIPPING_PERWEIGHTUNIT_HANDLING
See if you forgot to change ALL of the constants to match the shipping module you are working with ...
Hi Ajeh
All I changed is the two lines below (in red), because I really haven't learned as much as I need to to understand why I'm changing it, but I thought that I would at least give it a try. I kind of knew that it probably wouldn't work out to be that easy. :smile:
<?php
/**
* @package shippingMethod
* @copyright Copyright 2003-2006 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: perweightunit.php 3308 2006-03-29 08:21:33Z ajeh $
*/
/**
* "Per Weight Unit" shipping module, allowing you to offer per-unit-rate shipping options
*
*/
class perweightunit extends base {
/**
* $code determines the internal 'code' name used to designate "this" payment module
*
* @var string
*/
var $code;
/**
* $title is the displayed name for this payment method
*
* @var string
*/
var $title;
/**
* $description is a soft name for this payment method
*
* @var string
*/
var $description;
/**
* module's icon
*
* @var string
*/
var $icon;
/**
* $enabled determines whether this module shows or not... during checkout.
*
* @var boolean
*/
var $enabled;
/**
* Constructor
*
* @return perweightunit
*/
function perweightunit() {
global $order, $db;
$this->code = 'perweightunit';
$this->title = MODULE_SHIPPING_PERWEIGHTUNIT_TEXT_TITLE;
$this->description = MODULE_SHIPPING_PERWEIGHTUNIT_TEXT_DESCRIPTION;
$this->sort_order = MODULE_SHIPPING_PERWEIGHTUNIT_SORT_ORDER;
$this->icon = '';
$this->tax_class = MODULE_SHIPPING_PERWEIGHTUNIT_TAX_CLASS;
$this->tax_basis = MODULE_SHIPPING_PERWEIGHTUNIT_TAX_BASIS;
// disable only when entire cart is free shipping
if (zen_get_shipping_enabled($this->code)) {
$this->enabled = ((MODULE_SHIPPING_PERWEIGHTUNIT_STATUS == 'True') ? true : false);
}
if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_PERWEIGHTUNIT_ZONE > 0) ) {
$check_flag = false;
$check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . "
where geo_zone_id = '" . MODULE_SHIPPING_PERWEIGHTUNIT_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;
}
}
}
/**
* Obtain quote from shipping system/calculations
*
* @param string $method
* @return array
*/
function quote($method = '') {
global $order, $shipping_weight;
$total_weight_units = $shipping_weight;
if ($cost < 15.00) {
$this->quotes = array('id' => $this->code,
'module' => MODULE_SHIPPING_PERWEIGHTUNIT_TEXT_TITLE,
'methods' => array(array('id' => $this->code,
'title' => MODULE_SHIPPING_PERWEIGHTUNIT_TEXT_WAY,
'cost' => (15.00 + MODULE_SHIPPING_PERWEIGHTUNIT_COST * $total_weight_units)
+ MODULE_SHIPPING_PERWEIGHTUNIT_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;
}
/**
* Check to see whether module is installed
*
* @return boolean
*/
function check() {
global $db;
if (!isset($this->_check)) {
$check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_PERWEIGHTUNIT_STATUS'");
$this->_check = $check_query->RecordCount();
}
return $this->_check;
}
/**
* Install the shipping module and its configuration settings
*
*/
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 Per Weight Unit Shipping', 'MODULE_SHIPPING_PERWEIGHTUNIT_STATUS', 'True', 'Do you want to offer per unit rate shipping?<br /><br />Product Quantity * Units (products_weight) * Cost per Unit', '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 per Unit', 'MODULE_SHIPPING_PERWEIGHTUNIT_COST', '1', 'NOTE: When using this Shipping Module be sure to check the Tare settings in the Shipping/Packaging and set the Largest Weight high enough to handle the price, such as 5000.00 and the adjust the settings on Small and Large packages which will add to the price as well.<br /><br />The shipping cost will be used to determin shipping charges based on: Product Quantity * Units (products_weight) * Cost per Unit - in an order that uses 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 ('Handling Fee', 'MODULE_SHIPPING_PERWEIGHTUNIT_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, use_function, set_function, date_added) values ('Tax Class', 'MODULE_SHIPPING_PERWEIGHTUNIT_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_PERWEIGHTUNIT_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_PERWEIGHTUNIT_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_PERWEIGHTUNIT_SORT_ORDER', '0', 'Sort order of display.', '6', '0', now())");
}
/**
* Remove the module and all its settings
*
*/
function remove() {
global $db;
$db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key LIKE 'MODULE_SHIPPING_PERWEIGHTUNIT_%'");
}
/**
* Internal list of configuration keys used for configuration of the module
*
* @return array
*/
function keys() {
return array('MODULE_SHIPPING_PERWEIGHTUNIT_STATUS', 'MODULE_SHIPPING_PERWEIGHTUNIT_COST', 'MODULE_SHIPPING_PERWEIGHTUNIT_HANDLING', 'MODULE_SHIPPING_PERWEIGHTUNIT_TAX_CLASS', 'MODULE_SHIPPING_PERWEIGHTUNIT_TAX_BASIS', 'MODULE_SHIPPING_PERWEIGHTUNIT_ZONE', 'MODULE_SHIPPING_PERWEIGHTUNIT_SORT_ORDER');
}
}
?>
Try using this ...
Code:$total_weight_units = $shipping_weight;
if (MODULE_SHIPPING_PERWEIGHTUNIT_COST * $total_weight_units < 15.00) {
$this->quotes = array('id' => $this->code,
'module' => MODULE_SHIPPING_PERWEIGHTUNIT_TEXT_TITLE,
'methods' => array(array('id' => $this->code,
'title' => MODULE_SHIPPING_PERWEIGHTUNIT_TEXT_WAY,
'cost' => (15.00)
+ MODULE_SHIPPING_PERWEIGHTUNIT_HANDLING)));
} else {
$this->quotes = array('id' => $this->code,
'module' => MODULE_SHIPPING_PERWEIGHTUNIT_TEXT_TITLE,
'methods' => array(array('id' => $this->code,
'title' => MODULE_SHIPPING_PERWEIGHTUNIT_TEXT_WAY,
'cost' => (MODULE_SHIPPING_PERWEIGHTUNIT_COST * $total_weight_units)
+ MODULE_SHIPPING_PERWEIGHTUNIT_HANDLING)));
}
Thanks so much Linda, it worked fantastically! I just couldn't do this without the amazing help from several people on this forum. I really hope that I am able to give back the same way eventually. Thank you so very much. :D
Lisa
I'm using the per item shipping fee and need a minimum shipping cost of $20. Can't seem to make it work by altering the code. Could be 'cause it's past 2 am and I'm tired, but any help would be appreciated.
Per Unit perweightunit is based on the total weight of the order and that weight is used to calculate the shipping charges ...
If your units are set to 1.00 then you can just alter the code:
by adding the code in RED below the code in BLACK ...Code:$total_weight_units = $shipping_weight;
// bof: minimum 20.00
if ($total_weight < 20.00) {
$total_weight = 20.00;
}
// eof: minimum 20.00