Oba-san
- Join Date:
- Sep 2003
- Location:
- Ohio
- Posts:
- 62,757
- Plugin Contributions:
- 1
Free Shipping - some items - some zones - need upgrades
Start without those changes in post #10 as I do not believe they will calculate correctly ...
Views: 3,038
Oba-san
Start without those changes in post #10 as I do not believe they will calculate correctly ...
New Zenner
Hi, I wanted to give some more feedback to ajeh's code.
*Situation: *Offer free shipping on select products, restrict to one zone. "Always Free Shipping" selected, weight '0' so mixed carts would not include free item weight.
*Problem: *Orders outside the set zone would also benefit from the '0' weight.
Before testing: weight added to Always Free Shipping product.
The Shipping modules are the Royal Mail add-ons, so UPS/USPS edits were not included in tests.
Test 1:
Using 'freeshipper' (with zone set in module) and making the edits in post #19 to shipping class worked fine.
Test 2:
As you do not recommend freeshipping with zone restriction (I've never had any problems doing this though), installed freeoptions and made edits per post #8 to freeoptions file.
This did work, however Free Shipping was always available even with a mixed cart (only for the allowed zone). djdavedawson's first piece of code in post #10 (the closing else) fixed this.
Weight issues were fixed in both examples - the allowed zone ignores Always Free Shipping weight, outside the allowed zone the weight is included.
NB: I've only tested this on the shopping cart/shipping estimator page, not all the way through checkout.
Hope this is some help.
Thanks
Zen Follower
I had to comment out the original piece of code you gave first
// bof: add back Free Shipping
// global $cart;
// $total_weight += $_SESSION['cart']->free_shipping_weight;
//
After that, The code you have provided on #19 produces the following:
International Works
US works except that on a mixed cart where:
Item A, Free Ground Shipping, 15lbs
Item B, Regular Shipping Applies, 20lbs
All the shipping options displayed are based on 20lbs shipping.
Where the shipping options should be:
Next Day Air -> Rate on 35lbs
2nd Day Air -> Rate on 35lbs
3 Day -> Rate on 35lbs
Ground -> Rate on 20lbs
This is the same issue as before except the new code just reverses the issue, where not using code on #19 produces the following:
International Works
US works except that on a mixed cart where:
Item A, Free Ground Shipping, 15lbs
Item B, Regular Shipping Applies, 20lbs
All the shipping options displayed are based on 35lbs shipping.
Where the shipping options should be:
Next Day Air -> Rate on 35lbs
2nd Day Air -> Rate on 35lbs
3 Day -> Rate on 35lbs
Ground -> Rate on 20lbs
At this point is where I tried to introduce the code on #10, after reviewing what I originally posted on #10 I still have some issues with the calculation of the rates on the Ground Portion, because I was not sure how to go about it accurately.
How can I either,
Use the code on #19 and add the freeship weight to all options except ground on a mixed cart
or
Not use code on #19 and subtract the freeship weight from only ground on a mixed cart?
Thanks
~D
Zen Follower
Ok I think I got it.
For a Store that offers free UPS GROUND shipping on only some items to only the Lower 48.
Cart -> Mixed Cart
Display -> UPS Ground Option based on the NON Free Ship Items
Display -> UPS Upgraded Shipping Rates based on All Items
Here is the First part based on Ajeh's Code on #8
Make a Zone Definition defined for the US Only ...
Install the Free Shipping Options freeoptions instead of the FREE SHIPPING! freeshipper ... and set the Total >= 0 and set the Zone to the new Zone Definition for the US Only ...
Edit the code for:
/includes/modules/shipping/freeoptions.php
to include the code in RED:
// disable only when entire cart is free shipping
if (zen_get_shipping_enabled($this->code)) {
$this->enabled = ((MODULE_SHIPPING_FREEOPTIONS_STATUS == 'True') ? true : false);
}
// bof: Always Free Shipping
if (!IS_ADMIN_FLAG) {
global $cart;
if ($_SESSION['cart']->in_cart_check('product_is_always_free_shipping','1') == $_SESSION['cart']->count_contents()) {
$this->enabled = true;
} else {$this->enabled = false;}
}
// eof: Always Free Shipping
if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_FREEOPTIONS_ZONE > 0) ) {
Edit the code for the UPS shipping module with the code in RED:
// disable only when entire cart is free shipping
// if (zen_get_shipping_enabled($this->code)) {
$this->enabled = ((MODULE_SHIPPING_UPS_STATUS == 'True') ? true : false);
// }
Edit the code for the shipping class with the code in RED:
function calculate_boxes_weight_and_tare() {
global $total_weight, $shipping_weight, $shipping_quoted, $shipping_num_boxes;
// bof: add back Free Shipping
global $cart;
$total_weight += $_SESSION['cart']->free_shipping_weight;
//
if (is_array($this->modules)) {
Now the Free Shipping Options freeoptions will only show for the US when the whole order is Always Free Shipping and the UPS will always show with the proper weight ...
Here is the Next Part of my solution for the mixed cart:
Around line 192 in the UPS shipping module, i changed this:
$methods[] = array('id' => $type,
'title' => $this->types[$type],
'cost' => ($cost * $shipping_num_boxes ) + (MODULE_SHIPPING_UPS_HANDLING_METHOD == 'Box' ? MODULE_SHIPPING_UPS_HANDLING * $shipping_num_boxes : MODULE_SHIPPING_UPS_HANDLING) );
to this:
global $db, $order, $cart;
$valid_zone_id = (int)MODULE_SHIPPING_FREEOPTIONS_ZONE;
$check_flag = false;
$check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . $valid_zone_id . "' 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 ($type=='GND' && $_SESSION['cart']->free_shipping_weight !=0 && $check_flag == true) {
if ($_SESSION['cart']->in_cart_check('product_is_always_free_shipping','1') == $_SESSION['cart']->count_contents()) {
} else {
$adjusted_weight = ($ups_shipping_weight * $shipping_num_boxes) - ($_SESSION['cart']->free_shipping_weight);
(SHIPPING_MAX_WEIGHT > $adjusted_weight ? $adjusted_boxes = 1: $adjusted_boxes = ceil($adjusted_weight / SHIPPING_MAX_WEIGHT));
$adjusted_package = $adjusted_weight / $adjusted_boxes;
$this->_upsAction(3);
$this->_upsWeight($adjusted_package);
$gndQuote = $this->_upsGetQuote();
$gndcost = $gndQuote[0]['GND'];
$methods[] = array('id' => $type,
'title' => $this->types[$type] . " (Free Shipping + " . ($adjusted_package * $adjusted_boxes) ." lbs.)",
'cost' => ($gndcost * $adjusted_boxes) + (MODULE_SHIPPING_UPS_HANDLING_METHOD == 'Box' ? MODULE_SHIPPING_UPS_HANDLING * $adjusted_boxes : MODULE_SHIPPING_UPS_HANDLING) );
}
} else {
$methods[] = array('id' => $type,
'title' => $this->types[$type],
'cost' => ($cost * $shipping_num_boxes ) + (MODULE_SHIPPING_UPS_HANDLING_METHOD == 'Box' ? MODULE_SHIPPING_UPS_HANDLING * $shipping_num_boxes : MODULE_SHIPPING_UPS_HANDLING) );
}
I hope this helps someone too.
~D
Zen Follower
Note: If you're using anything prior to 1.3.9a you will need to correct the class shopping_cart.php as follows around 654:
// shipping adjustments
if (($product->fields['product_is_always_free_shipping'] == 1) or ($product->fields['products_virtual'] == 1) or (preg_match('^GIFT', addslashes($product->fields['products_model'])))) {
$this->free_shipping_item += $qty;
$this->free_shipping_price += zen_add_tax($products_price, $products_tax) * $qty;
//$this->free_shipping_weight += ($qty * $products_weight);
$this->free_shipping_weight += ($qty * $product->fields['products_weight']);
}
Tell staff why this post should be reviewed.