Simple shipping calc for ecommerce - HOW?
I have searched the forums but there has been so much discussion on shipbasic / flexicharge and the various .inc files that I am totally confused.
Can anyone explain to me (preferably in words of one syllable ;) exactly how I can implement the simplest possible shipping charge?
Basically I would be happy to just add 4.95 shipping to every order, regardless of weight / quantity / location / etc.
I have tried installing flexicharge (from CVS), but the 4.95 charge I put in was rounded to 4.00, I ended up with two "Shipping" lines on the total, and I got the following error:
warning: Invalid argument supplied for foreach() in /home/watergar/public_html/modules/ecommerce/contrib/flexicharge/flexicharge.module on line 248.
I have also tried putting the quantity.inc file (http://drupal.org/node/71718) in the ecommerce/contrib/shipcalc/partners directory. Don't know if that was right, but I got the following errors:
warning: Cannot modify header information - headers already sent by (output started at /home/watergar/public_html/modules/ecommerce/contrib/shipcalc/partners/quantity.inc:308) in /home/watergar/public_html/includes/common.inc on line 266.
Any help would be extremely gratefully received as I just don't understand this stuff, and shipping is a pretty basic requirement for an ecommerce site!
Thanks, Lucy

Same problem
The same probem led me to disactivate the cart. I need to add a flat shipping rate of Euro 1,5. All the UPS and the like stuff looks a bit too complicated, and US centric, for a small European business as mine. If anybody knows if there is a simple way to add 1,5 (or a small number of values, and that's all) in the sum, could she/he post something here? Thank you very much.
Nostromo
_____________
lablablab.com
*
*
Eventually I wrote my own,
Eventually I wrote my own, based on what alynner and others had posted (see http://drupal.org/node/70936 and http://drupal.org/node/71718).
It seems to work ok, but please use at your own risk, as I'm not sure I entirely understand all the hooks, etc.
It charges a flat fee for shipping, up to a certain total order value, after which shipping is free, but you could set a very high threshold or strip those bits out if you didn't want them.
I saved this file as modules/ecommerce/contrib/shipcalc/partners/simple.inc.
EDIT: There was a mistake in the definitions of DEFAULT_SD_CHARGE and DEFAULT _FD_THRESHOLD which I've corrected now. There may be other mistakes too - see next comment.
<?php
// simple.inc - lucyconnuk
/**
* Simple postage calculator for shipcalc.
*/
define('DEFAULT_SD_CHARGE', 4.95); /* SD = Standard Delivery */
define('DEFAULT_FD_THRESHOLD', 50); /* FD = Free Delivery */
/**
* Shipcalc _shipping_methods hook.
*
* Define the SIMPLE shipping methods.
*/
function simple_shipping_methods($type = 'domestic') {
$methods = array();
$methods['simple'] = array(
'#title' => t( 'Standard' ),
'#description' => t('Standard shipping options for this website.'),
);
$methods['simple']['Standard'] = array(
'#title' => t('Standard Delivery (' . variable_get('payment_symbol', '£') . variable_get( 'shipcalc_sd_charge', $DEFAULT_SD_CHARGE ) . ')'),
);
$methods['simple']['Free'] = array(
'#title' => t('Free Delivery on orders above ' . variable_get('payment_symbol', '£') . variable_get( 'shipcalc_fd_threshold', $DEFAULT_FD_THRESHOLD ) ),
);
return $methods;
}
/**
* Shipcalc _settings_form hook.
*
* Create a form for SIMPLE-specific configuration.
*/
function simple_settings_form(&$form) {
$form['simple'] = array(
'#type' => 'fieldset',
'#title' => t('SIMPLE settings')
);
$form['simple']['sd_charge'] = array(
'#type' => 'textfield',
'#title' => t('Standard Delivery Charge'),
'#description' => t('Enter standard delivery charge.'),
'#default_value' => variable_get( 'shipcalc_sd_charge', $DEFAULT_SD_CHARGE ),
'#required' => TRUE
);
$form['simple']['fd_threshold'] = array(
'#type' => 'textfield',
'#title' => t('Free Delivery Threshold'),
'#description' => t('Enter free delivery threshold.'),
'#default_value' => variable_get( 'shipcalc_fd_threshold', $DEFAULT_FD_THRESHOLD ),
'#required' => TRUE
);
return $form;
}
/**
* Shipcalc _settings_form_submit hook.
*
* Save data from our SIMPLE-specific configuration form.
*/
function simple_settings_form_submit(&$form) {
global $form_values;
$op = $_POST['op'];
if ($form_values['shipping_partner'] == 'simple') {
variable_set('shipcalc_sd_charge', $form_values['sd_charge']);
variable_set('shipcalc_fd_threshold', $form_values['fd_threshold']);
}
}
/**
* Shipcalc _get_rates_form hook.
* This bit used for "Choose shipping method." - LCBC
*/
function simple_get_rates($txn )
{
$total_price = 0;
if (is_array($txn->items) && $txn->items != array())
{
foreach ($txn->items as $item)
{
// Load item info into $item.
shipping_nodeapi($item, 'load', NULL);
$total_price += $item->price * $item->qty;
}
}
$rates = array();
if( $total_price < variable_get( 'shipcalc_fd_threshold', $DEFAULT_FD_THRESHOLD ) )
{
$rates[] = array(
'#service' => 'simple',
'#key' => standard,
'#cost' => variable_get('shipcalc_sd_charge', $DEFAULT_SD_CHARGE),
'#currency' => GBP,
'#method' => 'standard'
);
}
else
{
$rates[] = array(
'#service' => 'simple',
'#key' => free,
'#cost' => 0,
'#currency' => GBP,
'#method' => 'free'
);
}
return $rates;
}
?>
Lucy C
And then I ditched shipcalc
After spending a LOT of time trying to figure out what was going on with the shipping calcs (maybe I'm just thick but it seemed a bit obscure) I realised that as I was calculating shipping per transaction, rather than per item, I might be better off ditching shipcalc and writing a new module, shipcustom.
This was partly because my customer wanted to add an extra dimension to the calculations:
- books have free shipping
- if non-books in the order come to £50 or more, shipping is free, otherwise shipping for the non-books is £4.95.
So I wrote the following, which is offered with the usual disclaimer of "I don't really know what I'm doing, so if you want to use it fine, but at your own risk. Don't sue me!"
One thing with it which I don't quite feel happy about is this: at the moment, checking whether something gets free postage is done by going to the database and checking a taxonomy term, EVEN THOUGH the products themselves have checkboxes that offer free postage and/or standard postage (free above threshold), which in theory I could check instead.
This is because
a) I don't trust the site owner to check the right box for each product and
b) I don't know how to make the boxes mutually exclusive, and it would be meaningless to have a product which had BOTH free postage AND standard postage.
Anyway, here is my
modules/ecommerce/contrib/shipcustom/shipcustom.module
YMMV etc
<?php
//
// CUSTOM SHIPPING MODULE FOR WATERGARDENERMAGAZINE.COM
//
// (c) Lucy Connelly (lucyconnuk) 02 Nov 2006
// <a href="http://www.lucy-connelly.co.uk
//
//" title="www.lucy-connelly.co.uk
//
//" rel="nofollow">www.lucy-connelly.co.uk
//
//</a> Shipping charges calculated as follows:
//
// books - free delivery
// all other products - sd_charge for orders with a total value (not including books) of less than fd_threshold,
// otherwise free
//
// In other words, shipping is calculated per transaction, not per item.
//
// Although user can check standard or free for each product, at the moment shipcustom doesn't take any
// notice and calculates shipping on taxonomy term.
// This is because user may get it wrong when selecting standard or free, and I don't know how to make
// options exclusive.
// ONLINE SHOP VOCAB SHOULD *NOT* HAVE MULTIPLE SELECT - otherwise an item could be a book and a
// non-book, which wouldn't make sense.
//
define('DEBUG', 0);
define('BOOK_TERM_ID', 33); /* SITE-DEPENDENT */
define('DEFAULT_FD_THRESHOLD', 50);
define('DEFAULT_PAYMENT_SYMBOL', '£');
define('DEFAULT_SD_CHARGE', 4.95);
/**
* Shipcalc _ec_settings hook.
*
* Create a form for Shipcalc configuration.
*/
function shipcustom_ec_settings()
{
$form['sd_charge'] = array(
'#type' => 'textfield',
'#title' => t('Standard Delivery Charge'),
'#description' => t('Enter standard delivery charge.'),
'#default_value' => variable_get( 'shipcustom_sd_charge', DEFAULT_SD_CHARGE ),
'#required' => TRUE
);
$form['fd_threshold'] = array(
'#type' => 'textfield',
'#title' => t('Free Delivery Threshold'),
'#description' => t('Enter free delivery threshold.'),
'#default_value' => variable_get( 'shipcustom_fd_threshold', DEFAULT_FD_THRESHOLD ),
'#required' => TRUE
);
return $form;
}
/**
* Shipcustom _settings_form_submit hook.
*
* Save data from our Shipcustom configuration form.
*/
function shipcustom_settings_form_submit(&$form)
{
global $form_values;
$op = $_POST['op'];
variable_set('shipcustom_sd_charge', $form_values['sd_charge']);
variable_set('shipcustom_fd_threshold', $form_values['fd_threshold']);
}
/**
* Shipcustom _shipping_methods hook.
*
* Define the Shipcustom shipping methods.
*/
function shipcustom_shipping_methods($type = 'domestic')
{
$methods = array();
$payment_symbol = variable_get( 'payment_symbol', DEFAULT_PAYMENT_SYMBOL);
$sd_charge = variable_get( 'shipcustom_sd_charge', DEFAULT_SD_CHARGE);
$fd_threshold = variable_get( 'shipcustom_fd_threshold', DEFAULT_FD_THRESHOLD);
$methods['shipcustom'] = array(
'#title' => t( 'Custom' ),
'#description' => t('Custom shipping options defined for this website.'),
);
$methods['shipcustom']['Standard'] = array(
'#title' => t(
'Standard Delivery - ' .
$payment_symbol . $sd_charge .
' for orders below ' .
$payment_symbol . $fd_threshold .
', free for orders above ' .
$payment_symbol . $fd_threshold
)
);
$methods['shipcustom']['Free'] = array(
'#title' => t('Free Delivery'),
);
return $methods;
}
/**
* Shipcustom _shipping_checkout_rates hook.
*
* Calculate shipping rate and pass back to shipping module.
*/
function shipcustom_shipping_checkout_rates($txn)
{
if( DEBUG) watchdog( 'shipcustom.module', 'shipping_checkout_rates');
$rates = array();
$payment_symbol = variable_get( 'payment_symbol', DEFAULT_PAYMENT_SYMBOL);
$sd_charge = variable_get( 'shipcustom_sd_charge', DEFAULT_SD_CHARGE);
$fd_threshold = variable_get( 'shipcustom_fd_threshold', DEFAULT_FD_THRESHOLD);
if( DEBUG) watchdog( 'shipcustom.module', 'fd_threshold=' . $fd_threshold);
$subtotal = 0;
if (is_array($txn->items) && $txn->items != array())
{
foreach ($txn->items as $item)
{
// Load item info into $item.
shipping_nodeapi($item, 'load', NULL);
// Check if this item is a book.
$fields_required =
"{node}.title";
$tables =
"{node}," .
"{term_node}";
$conditions =
"{node}.nid = " . $item->nid . " AND " .
"{term_node}.nid = {node}.nid AND " .
"{term_node}.tid = '" . BOOK_TERM_ID . "'";
if( DEBUG) watchdog( 'shipcustom.module', 'doing query');
$query = "SELECT " . $fields_required . " FROM " . $tables . " WHERE " . $conditions;
$queryResult = db_query($query);
if ($result = db_fetch_object($queryResult))
{
if( DEBUG) watchdog( 'shipcustom.module', $result->title . '=book');
// this is a book, so do nothing
}
else
{
if( DEBUG) watchdog( 'shipcustom.module', $result->title . '=non-book');
// add price to subtotal
$subtotal += $item->price * $item->qty;
if( DEBUG) watchdog( 'shipcustom.module', 'subtotal=' . $subtotal);
if( $subtotal >= $fd_threshold)
{
// gone above threshold, so return free postage
$rates[] = array(
'#service' => 'custom',
'#key' => free,
'#cost' => 0,
'#currency' => $payment_symbol,
'#method' => 'free');
return $rates;
}
else
{
// keep checking
}
}
}
}
// after totting everything up, if subtotal is greater than 0, charge, otherwise free
if( $subtotal > 0 )
{
$rates[] = array(
'#service' => 'custom',
'#key' => standard,
'#cost' => $sd_charge,
'#currency' => $payment_symbol,
'#method' => 'standard');
}
else
// subtotal was 0 - must have been all books. free postage
{
$rates[] = array(
'#service' => 'custom',
'#key' => free,
'#cost' => 0,
'#currency' => $payment_symbol,
'#method' => 'free');
}
return $rates;
}
?>
Lucy C
Lucy, please contact me.
Lucy,
I would like a private conversation with you. Contact me via earnie at users dot sf dot net with the subject line tagged [drupal].
Earnie Boyd
http://For-My-Kids.Com
http://Give-Me-An-Offer.com
http://AffiliationMaster.com
Cant seem to get it working
Hi Lucy,
This is exactly what I'm looking for (i'm not running a book store tho). I've tried setting it up as a module, and as a .inc per your earlier post. But I couldnt get either to work. I can get to the respective config screens, just that the amount doesnt add to my final checkout amount.
I'm using the Apparel product type and do have subproducts enabled. And using Paypal for payment.
I'm new to drupal so although I'd like to try debugging it.. I am lost with the debug tools available and doesnt know when the shipping module is called.
Please give me a pointer to the right direction if you can.
EDIT: Ok.. got the module enabled for apparel product. Still very much fumbling with Drupal's matrix of settings. Now I'm up to the next stumbling block.
I've set each of my product with shipping, so that's ok. But when I reach the cart review summary, it indicates that shipping is still zero, although total cost is less than the free delievery threshold :(
Sorry dsiew, haven't been on
Sorry dsiew, haven't been on Drupal recently so didn't see your post till today. Did you get it working?
Lucy C
Hi Lucy,
Hi Lucy,
I managed to get the include file working.. not for the module tho.
Thanks for the great work. Now I'll need to figure out taking out shipping/delivery when the customer self collects. LOL.
hi dsiew, How do you
hi dsiew,
How do you implement "self collecting" on your site? Were you able to modify Lucy's module accordingly?
Would be very interested to learn what you came up with.
Chris
Awsome module
Hi,
I think this module is great.
I was wondering if you could create something like alynner's q_adjust and fusion it with your shipcustom module.
My idea is to have a module that lets you set shipping costs for three different regions and set a value for free postage all together in the same page, as I said before, is like joining q_adjust and shipcustom in one module.
I would love to hear what you think about this idea and for instance, if right now is not a good time for you to create it, what advice could you give me to develop it my self.
Thanks
Thanks
This solved my problem perfectly!
I'm assuming this module was
I'm assuming this module was for Drupal 4.7?
Did anybody update it for Drupal 5.x? It sure seems to be a missing component of eCommerce out of the box.
--
Ixis (UK) providing Drupal consultancy and Drupal theme design. Check the portfolio.
this one?
anyone tried this one: http://drupal.org/node/93891 ?
I haven't received any responses and I'm curious if it works for others, I quite like it for myself.
-alynner
still cant make the include
still cant make the include or the module to work.
what im missing?
=(
Hmmm, me either. Shipping is proving to be a nightmare. I think I'll be checking out Ubercart next time I do an e-commerce site! =(
Cart in EURO (€)
somebody developpers or the author can confirm that the latest ubercart does not includes EUR (€) currency in the shopping cart ??
is it possible to provide a release which follow the country currency choosen by settings ?
Um
You need to raise a support request against Ubercart. You won't get an answer here.
--
http://www.drupaler.co.uk/