Forums / Built-in Shipping and Payment Modules / Calculated shipping doesn't show up when an item is free shipping.

Calculated shipping doesn't show up when an item is free shipping.

Started by vanhorn_s on 7 Jul 2012, 12:22 AM · Views: 5,542

Results 21 to 28 of 28
28 Jan 2014, 5:28 PM
#21
lolwaut avatar

lolwaut

Zen Follower

Join Date:
Dec 2010
Posts:
142
Plugin Contributions:
0

Calculated shipping doesn't show up when an item is free shipping.

Ajeh:

Have you a link to that add on? I am not following how a clone of Flat Rate flat is calculating shipping regarding weight ... :lookaroun

http://www.zen-cart.com/downloads.php?do=file&id=1224

It doesn't actually calculate shipping... that's the point of the add-on... I calculate the shipping manually, email the customer the shipping quote, then they enter what I tell them themselves in the text entry box that this add-on creates.

28 Jan 2014, 5:41 PM
#22
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Calculated shipping doesn't show up when an item is free shipping.

What version of Zen Cart are you using?

What is the Zone Definition for the USA set to on the id?

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

28 Jan 2014, 11:51 PM
#23
lolwaut avatar

lolwaut

Zen Follower

Join Date:
Dec 2010
Posts:
142
Plugin Contributions:
0

Re: Calculated shipping doesn't show up when an item is free shipping.

Ajeh:

What version of Zen Cart are you using?

What is the Zone Definition for the USA set to on the id?

1.39h....

I'm not quite sure what you are asking for regarding the zone definition..... When I click Admin > Locations/Taxes > Zone Definitions > USA >

It says: Country: United States Zone: All Zones

28 Jan 2014, 11:53 PM
#24
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Calculated shipping doesn't show up when an item is free shipping.

If you look at the URL ... what is the zID for that Zone Definition that you see in the URL?

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

29 Jan 2014, 12:49 AM
#25
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Calculated shipping doesn't show up when an item is free shipping.

Once you know the Zone Definition id number, you can replace the 21 that I use with your value ...

Edit the file:
/includes/classes/shipping.php

and add the code in RED:

  function calculate_boxes_weight_and_tare() {
    global $total_weight, $shipping_weight, $shipping_quoted, $shipping_num_boxes;

[B]// Always Free Shipping added back except for US 48 plus DC zone_id = 21
// bof: allow 1 zone only for Always Free Shipping
    global $db, $order, $cart;
        $valid_zone_id = 21;
        $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 ($check_flag == false) {
          $total_weight += $_SESSION['cart']->free_shipping_weight;
        }
// eof: allow 1 zone only for Always Free Shipping
// Always Free Shipping added back except for US 48 plus DC zone_id = 21
[/B]
    if (is_array($this->modules)) {

Then customize your Flat Rate flat clone ...

I am using the Flat Rate flat module so just adapt the code to your Flat Rate clone with the code in RED:

      // disable only when entire cart is free shipping
[B]//[/B]      if (zen_get_shipping_enabled($this->code)) {
        $this->enabled = ((MODULE_SHIPPING_FLAT_STATUS == 'True') ? true : false);
[B]//[/B]      }
// class methods
    function quote($method = '') {
      global $order;

[B]global $shipping_weight;
//echo 'Flat $shipping_weight: ' . $shipping_weight . ' $total_weight: ' . $total_weight . '<br>';
if ($shipping_weight > 0) {
      $this->quotes = array('id' => $this->code,
                            'module' => MODULE_SHIPPING_FLAT_TEXT_TITLE,
                            'methods' => array(array('id' => $this->code,
                                                     'title' => MODULE_SHIPPING_FLAT_TEXT_WAY,
                                                     'cost' => MODULE_SHIPPING_FLAT_COST + $chk_weight_charge)));
}
[/B]
      if ($this->tax_class > 0) {

On the FREE SHIPPING! freeshipper add your Zone for the US to that module ...

See if this makes it work for you ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

29 Jan 2014, 7:01 AM
#26
lolwaut avatar

lolwaut

Zen Follower

Join Date:
Dec 2010
Posts:
142
Plugin Contributions:
0

Re: Calculated shipping doesn't show up when an item is free shipping.

Ajeh:

Once you know the Zone Definition id number, you can replace the 21 that I use with your value ...

Edit the file:
/includes/classes/shipping.php

and add the code in RED:

function calculate_boxes_weight_and_tare() {
global $total_weight, $shipping_weight, $shipping_quoted, $shipping_num_boxes;

[B]// Always Free Shipping added back except for US 48 plus DC zone_id = 21
// bof: allow 1 zone only for Always Free Shipping
global $db, $order, $cart;
$valid_zone_id = 21;
$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 ($check_flag == false) {
      $total_weight += $_SESSION['cart']->free_shipping_weight;
    }

// eof: allow 1 zone only for Always Free Shipping
// Always Free Shipping added back except for US 48 plus DC zone_id = 21
[/B]
if (is_array($this->modules)) {

> 
> Then customize your Flat Rate flat clone ...
> 
> I am using the Flat Rate flat module so just adapt the code to your Flat Rate clone with the code in **RED**:
> ```
      // disable only when entire cart is free shipping
[B]//[/B]      if (zen_get_shipping_enabled($this->code)) {
        $this->enabled = ((MODULE_SHIPPING_FLAT_STATUS == 'True') ? true : false);
[B]//[/B]      }

// class methods
function quote($method = '') {
global $order;

[B]global $shipping_weight;
//echo 'Flat $shipping_weight: ' . $shipping_weight . ' $total_weight: ' . $total_weight . '<br>';
if ($shipping_weight > 0) {
$this->quotes = array('id' => $this->code,
'module' => MODULE_SHIPPING_FLAT_TEXT_TITLE,
'methods' => array(array('id' => $this->code,
'title' => MODULE_SHIPPING_FLAT_TEXT_WAY,
'cost' => MODULE_SHIPPING_FLAT_COST + $chk_weight_charge)));
}
[/B]

if ($this->tax_class > 0) {

> 
> On the FREE SHIPPING! freeshipper add your Zone for the US to that module ...
> 
> See if this makes it work for you ...

Linda,

Thanks so much for your help and time. I got it working perfectly now so that ALWAYS FREE SHIPPING products do not offer the free shipping option for zones outside the USA. This solution worked for me. THANK YOU!
29 Jan 2014, 1:40 PM
#27
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Calculated shipping doesn't show up when an item is free shipping.

Thanks for the update that this is working for you to offer Always Free Shipping to just one zone ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

30 May 2017, 4:55 PM
#28
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,511
Plugin Contributions:
176

Re: Calculated shipping doesn't show up when an item is free shipping.

Here's an Observer class that can be added to a v1.5.5 site to skip the need to edit the shipping.php file as shown in post #25 above:

Install it as /includes/classes/observers/auto.free_shipping_override_for_international.php

<?php
/**
 * @package plugins
 * @copyright Copyright 2003-2017 Zen Cart Development Team
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: Designed for v1.5.5+  $
 */


class zcObserverFreeShippingOverrideForInternational extends base {


  function __construct() {
    $this->attach($this, array('NOTIFY_SHIPPING_MODULE_PRE_CALCULATE_BOXES_AND_TARE'));
  }


// For items that are marked as always_free_shipping, check the shipping zone, and if not in the zone-limits for FreeShipper, reset the free-shipping to 0
  function updateNotifyShippingModulePreCalculateBoxesAndTare(&$class, $eventID, $null, $total_weight, $shipping_weight, $shipping_quoted, $shipping_num_boxes)
  {
    global $db, $order;
    if (isset($order) && isset($order->delivery)) {
      $check_flag = false;
      $check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_FREESHIPPER_ZONE . "' 
                              and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
      while (!$check->EOF) {
        if ($check->fields['zone_id'] < 1) {
          // 0 = all zones match; therefore restriction is imposed
          $check_flag = true;
          break;
        } elseif ($check->fields['zone_id'] == $order->delivery['zone_id']) {
          // zone matches; therefore restriction is imposed
          $check_flag = true;
          break;
        }
        $check->MoveNext();
      }
      if ($check_flag == false) {
        // no matches for free-shipping zones, so treat as chargeable instead of free shipping
        $total_weight += $_SESSION['cart']->free_shipping_weight;
      }
    }
  }




}

Then configure the FreeShipper shipping module to have a "Shipping Zone" for the country/states that you wish to allow free shipping.

The observer will use that zone to determine when to restore the shipping weight back for quoting for addresses outside that zone.

Then comment out the zen_get_shipping_enabled() line as shown in post #25 for whichever shipping module you want to provide quotes for these always-free-shipping items when outside the zone defined in the FreeShipper module.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.