If this is your first visit, check our documentation. To post, register or login.
Forums / Configuring the Zen Cart Admin / Built-in Shipping and Payment Modules / Free shipping to just 1 country using free shipper and Yes, Always Free Shipping

Free shipping to just 1 country using free shipper and Yes, Always Free Shipping

Started by boomy on 17 Oct 2014, 11:59 PM · Views: 3,306

Results 1 to 10 of 10
17 Oct 2014, 11:59 PM
#1
boomy avatar

boomy

New Zenner

Join Date:
Feb 2011
Posts:
21
Plugin Contributions:
0

Post #1 by boomy

I have read all the threads on this issue and have tried everything, so i require some help from the knowledgeable :D

I have on some of my products - Yes, Always Free Shipping using free shipper, but this always is free to all countries when i need it to be only 1 country,

What i require is if a customer in another country purchases then the free shipper doesnt show and my other shipping to that country shows

I am using v1.3.9h

Would greatly appreciate any help please :P

18 Oct 2014, 12:32 PM
#2
ajeh avatar

ajeh

Oba-san

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

Post #2 by ajeh

What other shipping modules are you using for everything else?

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!

18 Oct 2014, 5:56 PM
#3
ajeh avatar

ajeh

Oba-san

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

Post #3 by ajeh

If, for example, you were trying to do this with USPS you could edit the shipping class:
/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]
// bof: allow 1 zone only for Always Free Shipping (int)MODULE_SHIPPING_FREESHIPPER_ZONE
    global $db, $order, $cart;
        $valid_zone_id = (int)MODULE_SHIPPING_FREESHIPPER_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 ($check_flag == false) {
          $total_weight += $_SESSION['cart']->free_shipping_weight;
        }
// bof: allow 1 zone only for Always Free Shipping
[/B]

Then edit the USPS shipping module:
/includes/modules/shipping/usps.php

and add the code in RED:

  function update_status() {
    global $order, $db;
    if (IS_ADMIN_FLAG == TRUE) return;

    // disable only when entire cart is free shipping
    if (zen_get_shipping_enabled($this->code) == FALSE) $this->enabled = FALSE;

[B]// bof: allow 1 zone only for Always Free Shipping (int)MODULE_SHIPPING_FREESHIPPER_ZONE
$this->enabled = TRUE;
// eof: allow 1 zone only for Always Free Shipping (int)MODULE_SHIPPING_FREESHIPPER_ZONE
[/B]
    if ($this->enabled == true) {
[B]// bof: allow 1 zone only for Always Free Shipping (int)MODULE_SHIPPING_FREESHIPPER_ZONE
//echo 'I see quantity: ' . ($_SESSION['cart']->in_cart_check('product_is_always_free_shipping', 1)) . '<br>';

        $valid_zone_id = (int)MODULE_SHIPPING_FREESHIPPER_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 ($check_flag == true) {
          if ($_SESSION['cart']->count_contents() == $_SESSION['cart']->in_cart_check('product_is_always_free_shipping', 1)) {
            $this->enabled = false;
          } else {
            $this->enabled = true;
          }
        } else {
          $this->enabled = true;
        }
// eof: allow 1 zone only for Always Free Shipping (int)MODULE_SHIPPING_FREESHIPPER_ZONE
[/B]
      global $template, $current_page_base;
      // CUSTOMIZED CONDITIONS GO HERE

then, on the Products for Always Free Shipping, mark them as such and add the weight that the shipping modules should use when the Product is not being sent to a Zone for Free Shipping ...

Now, in the shipping module for FREE SHIPPING! freeshipper, set your Zone that is allowed the Always Free Shipping on these Products ...

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!

18 Oct 2014, 11:33 PM
#4
boomy avatar

boomy

New Zenner

Join Date:
Feb 2011
Posts:
21
Plugin Contributions:
0

Post #4 by boomy

Thank you Ajeh,

I was just about to quote that code above, i have tried that and adapted it for use on item shipping module, only problem im having now is its not counting each product for outside my free zone

Im using shipping item module

So yes always free - working no problem in my free zone

Shipping outside free zone using per item module but it only counts and charges once for shipping and not per item... if i have 2 or 3 items still only charges one

Any ideas on that one?

19 Oct 2014, 2:20 AM
#5
ajeh avatar

ajeh

Oba-san

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

Post #5 by ajeh

You need to adjust the number of items to include the free shipping items in the items.php shipping module ...

      // adjusted count for free shipping
      $item_total_count = $total_count - $_SESSION['cart']->free_shipping_items();

Currently, it reduces the count based on:
$_SESSION['cart']->free_shipping_items()

You will need to not subtract the $_SESSION['cart']->free_shipping_items() when not in the right Zone being (int)MODULE_SHIPPING_FREESHIPPER_ZONE ...

See if you are able to adapt the code, otherwise I will try to work out the calculation for you tomorrow ...

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!

19 Oct 2014, 7:33 AM
#6
boomy avatar

boomy

New Zenner

Join Date:
Feb 2011
Posts:
21
Plugin Contributions:
0

Post #6 by boomy

Im not sure what to do there Ajeh, im not that good at coding, do i have to add anything or ?

19 Oct 2014, 9:37 AM
#7
boomy avatar

boomy

New Zenner

Join Date:
Feb 2011
Posts:
21
Plugin Contributions:
0

Post #7 by boomy

This is currently my item.php

<?php /** * @package shippingMethod * @copyright Copyright 2003-2009 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: item.php 14498 2009-10-01 20:16:16Z ajeh $ */ class item { var $code, $title, $description, $icon, $enabled; // class constructor function item() { global $order, $db; $this->code = 'item'; $this->title = MODULE_SHIPPING_ITEM_TEXT_TITLE; $this->description = MODULE_SHIPPING_ITEM_TEXT_DESCRIPTION; $this->sort_order = MODULE_SHIPPING_ITEM_SORT_ORDER; $this->icon = ''; $this->tax_class = MODULE_SHIPPING_ITEM_TAX_CLASS; $this->tax_basis = MODULE_SHIPPING_ITEM_TAX_BASIS; // disable only when entire cart is free shipping // if (zen_get_shipping_enabled($this->code)) { $this->enabled = ((MODULE_SHIPPING_ITEM_STATUS == 'True') ? true : false); // } if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_ITEM_ZONE > 0) ) { $check_flag = false; $check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_ITEM_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; } } } // class methods function quote($method = '') { global $order, $total_count; 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_ITEM_TEXT_TITLE, 'methods' => array(array('id' => $this->code, 'title' => MODULE_SHIPPING_ITEM_TEXT_WAY, 'cost' => MODULE_SHIPPING_ITEM_COST + $chk_weight_charge))); } 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; } function check() { global $db; if (!isset($this->_check)) { $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_ITEM_STATUS'"); $this->_check = $check_query->RecordCount(); } return $this->_check; } 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 Item Shipping', 'MODULE_SHIPPING_ITEM_STATUS', 'True', 'Do you want to offer per item rate shipping?', '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', 'MODULE_SHIPPING_ITEM_COST', '2.50', 'The shipping cost will be multiplied by the number of items 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_ITEM_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_ITEM_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_ITEM_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_ITEM_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_ITEM_SORT_ORDER', '0', 'Sort order of display.', '6', '0', now())"); } function remove() { global $db; $db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key like 'MODULE\_SHIPPING\_ITEM\_%'"); } function keys() { return array('MODULE_SHIPPING_ITEM_STATUS', 'MODULE_SHIPPING_ITEM_COST', 'MODULE_SHIPPING_ITEM_HANDLING', 'MODULE_SHIPPING_ITEM_TAX_CLASS', 'MODULE_SHIPPING_ITEM_TAX_BASIS', 'MODULE_SHIPPING_ITEM_ZONE', 'MODULE_SHIPPING_ITEM_SORT_ORDER'); } } ?>
19 Oct 2014, 1:32 PM
#8
ajeh avatar

ajeh

Oba-san

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

Post #8 by ajeh

I have added a new item.php file 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!

19 Oct 2014, 10:23 PM
#9
boomy avatar

boomy

New Zenner

Join Date:
Feb 2011
Posts:
21
Plugin Contributions:
0

Post #9 by boomy

Thank you thank you and thank you :P

It is working now perfectly, i think i may have to make a donation

Much appreciate the help!

20 Oct 2014, 12:43 AM
#10
ajeh avatar

ajeh

Oba-san

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

Post #10 by ajeh

Thanks for the update that this is working for you ... :smile:

Donations are always appreciated!

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!