Zen Cart Logo
Forums / Addon Shipping Modules / Shipping per Categories

Shipping per Categories

Views: 10,465

Results 21 to 40 of 50
21 Feb 2014, 1:53 PM
#21
ajeh avatar

ajeh

Oba-san

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

Shipping per Categories

You would have to control how much is being charged in this section:

      $chk_total_charge_constant = constant('MODULE_SHIPPING_ITEMCAT_COST' . $i);
      $chk_total_charge += ($chk_total_charge_constant * ${$chk_cat_group});
      $chk_total_count += ${$chk_cat_group};

The price is set in:
$chk_total_charge_constant

you would want to change that from the amount you set per sheet of 2.50 to the lower amount of 0.40 when the count:
$chk_total_count

is at the number of sheets where you want to charge less ...

Keep in mind that the count:
$chk_total_count

is set after the charge is calculated ... so when the first item is calculated the count is 0 ...

Plus, you have to decide if all of the item counts when > 1 get changed to 0.40 or if you want different charges for the groups as it could get complicated to figure out the:
$chk_total_charge_constant

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!

21 Feb 2014, 7:47 PM
#22
missinglife avatar

missinglife

Zen Follower

Join Date:
Apr 2009
Location:
Portland, OR
Posts:
104
Plugin Contributions:
0

Re: Shipping per Categories

so I have to write a "IF" statement?

Ajeh:

You would have to control how much is being charged in this section:

  $chk_total_charge_constant = constant('MODULE_SHIPPING_ITEMCAT_COST' . $i);
  $chk_total_charge += ($chk_total_charge_constant * ${$chk_cat_group});
  $chk_total_count += ${$chk_cat_group};
> 
> The price is set in:
> $chk_total_charge_constant
> 
> you would want to change that from the amount you set per sheet of 2.50 to the lower amount of 0.40 when the count:
> $chk_total_count
> 
> is at the number of sheets where you want to charge less ...
> 
> Keep in mind that the count:
> $chk_total_count
> 
> is set after the charge is calculated ... so when the first item is calculated the count is 0 ...
> 
> Plus, you have to decide if all of the item counts when > 1 get changed to 0.40 or if you want different charges for the groups as it could get complicated to figure out the:
> $chk_total_charge_constant
21 Feb 2014, 10:38 PM
#23
ajeh avatar

ajeh

Oba-san

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

Re: Shipping per Categories

Yes, you will need an IF in this section of the code ...

I would start by rearrange that section of code as:

      $chk_total_count += ${$chk_cat_group};
      $chk_total_charge_constant = constant('MODULE_SHIPPING_ITEMCAT_COST' . $i);
      $chk_total_charge += ($chk_total_charge_constant * ${$chk_cat_group});

so you can better tell if you are on sheet 1 or sheet 2, sheet 3 etc.

Then, you have to decide when/what to use the cost setting for:
$chk_total_charge_constant

the issue is how much to charge based on the count but you are dropping the rate based on count from 2.50 to 0.40 ...

The difficulty is, this is using multiple rates based on the Category ... it wasn't written to suddenly decide to charge different rates for different quantities for different categories ...

You have some categories for 2.50 and some categories for 0.46 ... then, you suddenly want on the categories for 2.50 to only charge the 2.50 if it is 1 sheet but then charge a different price of 0.40 if there are more than 1 sheet ...

But, this is not the same logic for all of the category groups, meaning that on the categories for the 2.50 you want 2.50 for sheet 1 and 0.40 for sheet 2+ but on the categories for 0.46 you want 0.46 for sheet 1 and 0.46 for sheet 2+ ...

I am not sure just how hard it will be to do that with the multiple categories settings ...

The main idea is to get the:
$chk_total_charge_constant

set to the right amount to charge for the sheet for the right category group at the right time ...

You will really need to work with that section to get the IF right on how much to charge ...

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!

22 Feb 2014, 5:22 AM
#24
missinglife avatar

missinglife

Zen Follower

Join Date:
Apr 2009
Location:
Portland, OR
Posts:
104
Plugin Contributions:
0

Re: Shipping per Categories

This is over my head, I dont think I can do any of what you suggested above :(
is there a shipping module will work for my situation? or do I need to pay someone to do this for me?

I am hoping to get this shipping module done, so I can upgrade to the new version of Zen Cart.

thank you so much for your help!

22 Feb 2014, 4:18 PM
#25
ajeh avatar

ajeh

Oba-san

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

Re: Shipping per Categories

You could try this to charge sheet 1 2.50 and 0.40 sheet 2+ in category group 1 and charge sheet 1 0.46 and 0.40 sheet 2+ in category group 2

      $chk_total_count += ${$chk_cat_group};
      $chk_total_charge_constant = constant('MODULE_SHIPPING_ITEMCAT_COST' . $i);
//      $chk_total_charge += ($chk_total_charge_constant * ${$chk_cat_group});
      $chk_total_charge += (${$chk_cat_group} > 0 ? (1 * $chk_total_charge_constant) + ( (${$chk_cat_group} - 1) * .40) : 0);

It should work but you will need to test it ...

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!

22 Feb 2014, 6:31 PM
#26
missinglife avatar

missinglife

Zen Follower

Join Date:
Apr 2009
Location:
Portland, OR
Posts:
104
Plugin Contributions:
0

Re: Shipping per Categories

it works for US and Rest of World shipping, Yay!!!!

however Canada shipping is not, it seems it charge the same shipping fees as US shipping.
I am not sure where I did wrong on itemcatcan.php, can you take a look?

Thank you!!!

<?php
/**
 * @package shippingMethod
 * @copyright Copyright 2003-2013 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 itemcatcan.php 1969 2104-01-03 06:57:21Z ajeh $
 */

class itemcatcan extends base {
  /**
   * $code determines the internal 'code' name used to designate "this" shipping module
   *
   * @var string
   */
  var $code;
  /**
   * $title is the displayed name for this shipping method on the storefront
   *
   * @var string
   */
  var $title;
  /**
   * $description is a soft name for this shipping method, rarely used
   *
   * @var string
   */
  var $description;
  /**
   * module's icon, if any.  Must be manually uploaded to the server's images folder, and an appropriate call to zen_image() added to the constructor.
   *
   * @var string
   */
  var $icon;
  /**
   * $enabled determines whether this module shows or not during checkout.
   * Can be updated with custom code in the module's update_status() method.
   * Can be overridden with observers via notifier points NOTIFY_SHIPPING_CHECK_ENABLED_FOR_ZONE and NOTIFY_SHIPPING_CHECK_ENABLED
   * @var boolean
   */
  var $enabled;
  /**
   * additional category groups itemcatcan rate
   */
  var $num_cat_group;
  /**
   * constructor
   *
   * @return itemcatcan
   */
  function __construct() {
    $this->code = 'itemcatcan';
    $this->title = MODULE_SHIPPING_ITEMCATCAN_TEXT_TITLE;
    $this->description = MODULE_SHIPPING_ITEMCATCAN_TEXT_DESCRIPTION;
    $this->sort_order = MODULE_SHIPPING_ITEMCATCAN_SORT_ORDER;
    $this->icon = ''; // add image filename here; must be uploaded to the /images/ subdirectory
    $this->tax_class = MODULE_SHIPPING_ITEMCATCAN_TAX_CLASS;
    $this->tax_basis = MODULE_SHIPPING_ITEMCATCAN_TAX_BASIS;
    $this->enabled = (MODULE_SHIPPING_ITEMCATCAN_STATUS == 'True') ? true : false;
    $this->update_status();
    $this->notify('MODULE_SHIPPING_' . strtoupper($this->code) . '_INSTANTIATED');

    /*
    ** CUSTOMIZE SETTING FOR THE NUMBER OF CATEGORY GROUPS NEEDED **
    If Itemcat Rates module is currently installed ...
      1. Change number below for the number of Category Groups for this->num_cat_group
      2. Upload changed itemcatcan.php
      3. Go to Modules ... Shipping ...
      4. Go to Modules ... Shipping ... a second time to clear any error messages
      5. Click on Itemcat Rates and Edit and Configure new Category groups

    If Itemcat Rates module is not currently installed
      1. Change number below for the number of Category Groups for this->num_cat_group
      2. Upload changed itemcatcan.php
      3. Go to Modules ... Shipping ...
      4. Click on Itemcat Rates and Click Install
      5. Edit and Configure new Item category groups

    */
    $this->num_cat_group = 3;

    if (IS_ADMIN_FLAG === true) {
      // build in admin only additional category groups if missing in the configuration table due to customization of default $this->num_cat_group = 2
      global $db;
      for ($i = 1; $i <= $this->num_cat_group; $i++) {
        $check = $db->Execute("select * from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_ITEMCATCAN_GROUP_" . $i . "'");
        if ($this->enabled && $check->EOF) {
          $default_categories_group = '';
          $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Itemcat group"  . $i . " categories', 'MODULE_SHIPPING_ITEMCATCAN_GROUP_" . $i ."', '" . $default_categories_group . "', 'What categories belong to this category group<br />Separate categories by commas, Example: 53,67 or 10, 12', '6', '0', 'zen_cfg_textarea(', 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 Itemcat group"  . $i . "', 'MODULE_SHIPPING_ITEMCATCAN_COST" . $i ."', '" . '2.50' . "', 'The shipping cost will be multiplied by the number of items in an order that uses this Category Group.', '6', '0', now())");
        }
      }
    } // build in admin only

  }

  /**
   * Coders can add custom logic here in the update_status() method to allow for manipulating the $this->enabled status
   */
  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;

    /** CUSTOM ENABLE/DISABLE LOGIC CAN BE ADDED IN THE AREA SPECIFIED BELOW **/
    if ($this->enabled) {
      global $template, $current_page_base;
      // CUSTOMIZED CONDITIONS GO HERE
      // Optionally add additional code here to disable the module by changing $this->enabled to false based on whatever custom rules you require.
      // -----


      // -----
      // eof: optional additional code
    }
//echo 'ITEM function ' . __FUNCTION__ . ' $this->enabled: ' . ($this->enabled ? ' ON' : ' OFF') . ' $shipping_weight: ' . $shipping_weight . '<br>';
  }

  /**
   * Sets $this->enabled based on zone restrictions applied to this module
   * @return boolean
   */
  function check_enabled_for_zone()
  {
    global $order, $db;
    if ($this->enabled == true && (int)MODULE_SHIPPING_ITEMCATCAN_ZONE > 0) {
      $check_flag = false;
      $check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . "
                             where geo_zone_id = '" . MODULE_SHIPPING_ITEMCATCAN_ZONE . "'
                             and zone_country_id = '" . (int)$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;
      }
    }
    return $this->enabled;
  }

  /**
   * Returns the value of $this->enabled variable
   * @return boolean
   */
  function check_enabled()
  {
    return $this->enabled;
  }

  /**
   * Obtain quote from shipping system/calculations
   *
   * @param string $method
   * @return array
   */
  function quote($method = '') {
    global $order, $total_count;

    $chk_products_id_list_defined = '';
    $chk_total_count = 0;
    $chk_free_shipping_total_count = 0;
    $chk_products_in_cart = $_SESSION['cart']->get_product_id_list();
//echo '$chk_products_in_cart: ' . $chk_products_in_cart . '<br><br>';

    for ($i=1; $i<=$this->num_cat_group; $i++) {
      $chk_cat_group = '$chk_cat_group_' . $i;
      ${$chk_cat_group} = 0;

      $cat_group = '$cat_group_' . $i;
      $cat_group_constant = constant('MODULE_SHIPPING_ITEMCATCAN_GROUP_' . $i);
      ${$cat_group} = preg_split("/[,]/" , $cat_group_constant);

      $size = sizeof(${$cat_group});
      if ($cat_group_constant == '') break; // do not continue if empty
      for ($j=0, $n=$size; $j<$n; $j+=1) {
        if (${$cat_group}[$j] != '') {
          ${$chk_cat_group} += $_SESSION['cart']->in_cart_check('master_categories_id', trim(${$cat_group}[$j]));
        }

//echo 'Looking at trim(${$cat_group}[$j]): ' . trim(${$cat_group}[$j]) . '<br>';
        // check free shipping products
        global $categories_products_id_list;
        $categories_products_id_list = '';
        $chk_products_id_list = array();
        $chk_cat_group_products = trim(${$cat_group}[$j]);

        $chk_products_id_list = zen_get_categories_products_list($chk_cat_group_products);
//echo '<pre>'; echo var_dump($chk_products_id_list); echo '</pre>';
//echo 'itemcatcan $chk_products_id_list';print_r($chk_products_id_list);
        if (is_array($chk_products_id_list) && sizeof($chk_products_id_list) > 0) {
          // build products list
          $list_of_products = '';
          foreach($chk_products_id_list as $key => $value) {
            $list_of_products .= $key . ', ';
          }
          // if any $list_of_products are in cart check if free shipping
          $chk_products = trim(trim($list_of_products), ',');
//echo '$chk_products: ' . $chk_products . '<br>in cart $chk_products_in_cart: '. $chk_products_in_cart . '<br>';
          $chk_donotchargeshipping = '';
          $chk_donotchargeshipping_cnt = 0;
          $arr1 = explode(", ", $chk_products_in_cart);
          $arr2 = explode(", ", $chk_products);
//  echo '<pre>'; echo var_dump($chk_products); echo '</pre>';
          $chk_donotchargeshipping = array_intersect($arr1, $arr2);
//echo '<br>itemcatcan $chk_donotchargeshipping<br> '; print_r($chk_donotchargeshipping); echo '<br>';
          foreach($chk_donotchargeshipping as $key2 => $value) {
            $chk_products_id_list_defined .= $value . ', ';
            $chk_donotchargeshipping_cnt = itemcatcan_free_shipping($value);
            if ($chk_donotchargeshipping_cnt) {
              $chk_free_shipping_total_count += 1;
              echo '<br>Do not charge $key2 $value: ' . $value . ' $chk_donotchargeshipping_cnt: ' . $chk_donotchargeshipping_cnt . '<br>';
            }
                      ${$chk_cat_group} += -$chk_donotchargeshipping_cnt;
          }
//echo 'Cat: ' . trim(${$cat_group}[$j]) . ' ${$chk_cat_group}: ' . ${$chk_cat_group} . '<br>';
        }
      }

	  $chk_total_count += ${$chk_cat_group};
      $chk_total_charge_constant = constant('MODULE_SHIPPING_ITEMCAT_COST' . $i);
//      $chk_total_charge += ($chk_total_charge_constant * ${$chk_cat_group});
      $chk_total_charge += (${$chk_cat_group} > 0 ? (1 * $chk_total_charge_constant) + ( (${$chk_cat_group} - 1) * .75) : 0);
	  
    }
//echo '$chk_total_count: ' . $chk_total_count . ' $chk_total_charge found: ' . $chk_total_charge . '<br>';
//echo '$chk_products_in_cart: ' . $chk_products_in_cart . '<br>vs $chk_products_id_list_defined: ' . $chk_products_id_list_defined . '<br>';
// check products undefined for Free shipping
    //$chk_products_id_list
    // if any $list_of_products are in cart check if free shipping
    $chk_products_id_list_defined = trim(trim($chk_products_id_list_defined), ',');
//echo '$chk_products: ' . $chk_products . '<br>in cart $chk_products_in_cart: '. $chk_products_in_cart . '<br>';
    $chk_donotchargeshipping_undefined = '';
    $chk_undefined_free_shipping = 0;
    $chk_free_shipping_total_count_undefined = 0;
    $arr1 = explode(", ", $chk_products_in_cart);
    $arr2 = explode(", ", $chk_products_id_list_defined);
    $chk_donotchargeshipping_undefined = array_diff($arr1, $arr2);
    foreach($chk_donotchargeshipping_undefined as $key2 => $value) {
//      $chk_products_id_list .= $value . ',';
      $chk_donotchargeshipping_undefined_cnt = itemcatcan_free_shipping($value);
      if ($chk_donotchargeshipping_undefined_cnt) {
        echo 'itemcatcan Do not charge UNDEFINED $key2: ' . $value . '<br>';
        $chk_free_shipping_total_count_undefined += 1;
      }
      $chk_undefined_free_shipping += $chk_donotchargeshipping_undefined_cnt;
    }
//echo '$chk_undefined_free_shipping: ' . $chk_undefined_free_shipping . '<br>';
// calculate any undefined categories and add to $chk_total_charge
    $undefined_products = $_SESSION['cart']->count_contents() - ($chk_total_count + ($chk_free_shipping_total_count + $chk_undefined_free_shipping));
    $undefined_products_charge = (MODULE_SHIPPING_ITEMCATCAN_COST_UNDEFINED * ($undefined_products - $chk_undefined_free_shipping));
//echo '$undefined_products: ' . $undefined_products . ' $undefined_products_charge: ' . $undefined_products_charge . '<br>';

    $chk_total_charge += $undefined_products_charge;
//echo 'TOTAL CHARGE $chk_total_charge: ' . $chk_total_charge . '<br>';

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

    $this->quotes = array('id' => $this->code,
                          'module' => MODULE_SHIPPING_ITEMCATCAN_TEXT_TITLE,
                          'methods' => array(array('id' => $this->code,
                                                   'title' => MODULE_SHIPPING_ITEMCATCAN_TEXT_WAY,
                                                   'cost' => ($chk_total_charge) + MODULE_SHIPPING_ITEMCATCAN_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);

    $this->notify('MODULE_SHIPPING_' . strtoupper($this->code) . '_QUOTES_PREPARED');
    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_ITEMCATCAN_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 Itemcat Shipping', 'MODULE_SHIPPING_ITEMCATCAN_STATUS', 'True', 'Do you want to offer per itemcatcan rate shipping?', '6', '0', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");

      for ($i = 1; $i <= $this->num_cat_group; $i++) {
        $check = $db->Execute("select * from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_ITEMCATCAN_GROUP_" . $i . "'");
        if ($this->enabled && $check->EOF) {
          $default_categories_group = '';
          $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Itemcat group"  . $i . " categories', 'MODULE_SHIPPING_ITEMCATCAN_GROUP_" . $i ."', '" . $default_categories_group . "', 'What categories belong to this category group<br />Separate categories by commas, Example: 53,67', '6', '0', 'zen_cfg_textarea(', 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 Itemcat group"  . $i . "', 'MODULE_SHIPPING_ITEMCATCAN_COST" . $i ."', '" . '2.50' . "', 'The shipping cost will be multiplied by the number of items in an order that uses this Category Group.', '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 ('Shipping Cost for Itemcat category groups undefined', 'MODULE_SHIPPING_ITEMCATCAN_COST_UNDEFINED', '', 'The shipping cost will be multiplied by the number of items in an order that are not in a defined category group.', '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_ITEMCATCAN_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_ITEMCATCAN_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_ITEMCATCAN_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_ITEMCATCAN_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_ITEMCATCAN_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\_ITEMCATCAN\_%'");
  }

  /**
   * Internal list of configuration keys used for configuration of the module
   *
   * @return array
   */
  function keys() {
    $keys = array('MODULE_SHIPPING_ITEMCATCAN_STATUS', 'MODULE_SHIPPING_ITEMCATCAN_HANDLING', 'MODULE_SHIPPING_ITEMCATCAN_TAX_CLASS', 'MODULE_SHIPPING_ITEMCATCAN_TAX_BASIS', 'MODULE_SHIPPING_ITEMCATCAN_ZONE', 'MODULE_SHIPPING_ITEMCATCAN_SORT_ORDER');

    for ($i=1; $i<=$this->num_cat_group; $i++) {
      $keys[] = 'MODULE_SHIPPING_ITEMCATCAN_GROUP_' . $i;
      $keys[] = 'MODULE_SHIPPING_ITEMCATCAN_COST' . $i;
    }

    $keys[] = 'MODULE_SHIPPING_ITEMCATCAN_COST_UNDEFINED';

    return $keys;
  }
}

function itemcatcan_free_shipping($product_id) {
  global $db;
  if ($product_id == '' || $product_id == 0 || !$product_id) {
//    echo 'Blank $product_id<br>';
    return 0;
  }
  if (!zen_has_product_attributes_downloads_status($product_id)) {
//echo 'itemcatcan_free_shipping 1 - A Download: ' . $product_id . ' - ' . zen_has_product_attributes_downloads_status($product_id) . '<br><br>';
    return 1;
  }
  $sql = "SELECT product_is_always_free_shipping, products_virtual, products_model, products_weight from " . TABLE_PRODUCTS . " WHERE products_id = '" . (int)$product_id . "'";
  $chk_free_shipping = $db->Execute($sql);
  if (($chk_free_shipping->fields['product_is_always_free_shipping'] == 1) or ($chk_free_shipping->fields['products_virtual'] == 1) or (preg_match('/^GIFT/', addslashes($chk_free_shipping->fields['products_model'])))) {
//echo 'itemcatcan_free_shipping 1 - B Virtual: ' . $product_id . '<br><br>';
    return 1;
  }
  if ($chk_free_shipping->fields['products_weight'] == 0 && ORDER_WEIGHT_ZERO_STATUS == 1) {
//echo 'itemcatcan_free_shipping 1 - C Weight: ' . $product_id . '<br><br>';
    return 1;
  }
  return 0;
}
22 Feb 2014, 6:41 PM
#27
ajeh avatar

ajeh

Oba-san

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

Re: Shipping per Categories

I believe this line:

      $chk_total_charge_constant = constant('MODULE_SHIPPING_[B]ITEMCAT[/B]_COST' . $i);

should be:

      $chk_total_charge_constant = constant('MODULE_SHIPPING_[B]ITEMCATCAN[/B]_COST' . $i);

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!

22 Feb 2014, 11:26 PM
#28
missinglife avatar

missinglife

Zen Follower

Join Date:
Apr 2009
Location:
Portland, OR
Posts:
104
Plugin Contributions:
0

Re: Shipping per Categories

YAY!!! It all works...!!!!
I bought everyone round of coffees!!!

Thank you so much!!!!

22 Feb 2014, 11:31 PM
#29
ajeh avatar

ajeh

Oba-san

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

Re: Shipping per Categories

Glad that all is now working for you!

Thanks especially for the coffees and donuts! It really helps the Zen Cart Team to continue to help you ... :cool:

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!

14 Mar 2014, 4:19 PM
#30
gabstero avatar

gabstero

Zen Follower

Join Date:
Nov 2007
Posts:
342
Plugin Contributions:
0

Re: Shipping per Categories

Ajeh Oba San -

(giddy with excitement). Will this mod you wrote work in the case when:

  1. I have 3 clones of the Zone Rates working just fine
  2. Setting a Per Unit (or other shipping module) to a specific category
  3. When a use adds two different products from different categories, the shipping adds fine in the cart?

thanks a bunch!
gabstero

14 Mar 2014, 4:30 PM
#31
ajeh avatar

ajeh

Oba-san

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

Re: Shipping per Categories

This is designed to assign a single rate to each Category for pricing.

So it will not work like Per Unit perweightunit that uses the Product Weight to determine the shipping cost of a Product.

It will not work like Zone Rate zones that uses either Item, Weight or Price to determine the shipping costs based on specific country zones.

Can you be more specific in describing what it is exactly that you are trying to do with shipping? :lookaroun

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!

14 Mar 2014, 4:46 PM
#32
gabstero avatar

gabstero

Zen Follower

Join Date:
Nov 2007
Posts:
342
Plugin Contributions:
0

Re: Shipping per Categories

Ajeh -

thanks for giving me the chance to speak it out :-)

I am planning to ship items from at least (for now) two different locations in the world. The majority of the categories (with products originated in Budapest, Hungary) will include items that use the Zone Rate module to calculate the shipping from that origin.
But there are (for now) some products (I grouped them in a separate category) that originate in a whole different location (say NYC, USA).

What can I do to calculate the shipping rate depending from where the product originates?

I was thinking of grouping the products that originate from a different location in one separate category and handle that category with a different shipping module (preferably Zone Rate).

Please let me know if I am making sense.

thanks!
g

14 Mar 2014, 6:02 PM
#33
ajeh avatar

ajeh

Oba-san

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

Re: Shipping per Categories

What are the settings in your Zone Rates zones right now?

Basically, are you trying to say:

3 Products from categories_id 12 ship from New York so 3 * $2.75 = $8.50
2 Products from categories_id 15 ship from Florida so 2 * 1.75 = $3.50

then add that to the Zone Rates zones shipping amount?

Or, do you want do something like that, but each Zone defined in Zone Rates zones has a different shipping cost for the two different categories_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!

14 Mar 2014, 6:17 PM
#34
gabstero avatar

gabstero

Zen Follower

Join Date:
Nov 2007
Posts:
342
Plugin Contributions:
0

Re: Shipping per Categories

Thanks Ajeh -

The latter of your reply. The products shipped from FL should have a different shipping cost than the ones sent from NYC. It is going to be more drastic than that since we are talking of products shipped from two different locations in the world so shipping cost to customer has to be calculated relative to their origins.

hope I am making sense.

thanks
g

14 Mar 2014, 9:29 PM
#35
ajeh avatar

ajeh

Oba-san

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

Re: Shipping per Categories

I really need to know what settings you are using in the Zone Rates zones shipping ...

Go to the Modules ... Shipping ... and click on Zone Rates zones shipping and post what is in the right hand panel ...

Are the shipping costs for the two Categories the same for all shipping zones?

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!

14 Mar 2014, 10:05 PM
#36
gabstero avatar

gabstero

Zen Follower

Join Date:
Nov 2007
Posts:
342
Plugin Contributions:
0

Re: Shipping per Categories

Thanks Ajeh!

Are the shipping costs for the two Categories the same for all shipping zones?

No. I want them to be different calculated in relation from where those shipments are originating.

I didn't instal your mod yet though. This is a fresh ZC v1.5.1 install.

Here it is what I have in the Zone Rate:

Zone Based Rates for UPS

Enable Zones Method
True

Calculation Method
Weight

Tax Class
--none--

Tax Basis
Shipping

Sort Order
0

Skip Countries, use a comma separated list of the two character ISO country codes

Zone 1 Countries

Zone 1 Shipping Table

Zone 1 Handling Fee
0

Handling Per Order or Per Box Zone 1 (when by weight)
Order

Zone 2 Countries
HK,

Zone 2 Shipping Table
0.5:31, 1.0:35, 1.5:39, 2.0:43, 2.5:47, 3.0:52, 3.5:57, 4.0:62, 4.5:67, 5.0:72, 5.5:73, 6.0:75, 6.5:77, 7.0:78, 7.5:80, 8.0:81, 8.5:82, 9.0:83, 9.5:85, 10.0:86, 10.5:87, 11.0:88, 11.5:89, 12.0:90, 12.5:91, 13.0:91, 13.5:92, 14.0:93, 14.5:93, 15.0:94, 15.5:95, 16.0:96, 16.5:97, 17.0:98, 17.5:98, 18.0:99, 18.5:99, 19.0:99, 19.5:99, 20.0:100, 20.5:104, 21.0:104, 22.0:109, 23.0:114, 24.0:119, 25.0:124, 26.0:129, 27.0:134, 28.0:139, 29.0:144, 30.0:149, 31.0:154, 32.0:159, 33.0:164, 34.0:169, 35.0:174, 36.0:179, 37.0:184, 38.0:189, 39.0:194, 40.0:199, 50.0:228, 60.0:274, 70.0:319, 80.0:362, 90.00:407, 100.0:448,

Zone 2 Handling Fee
0

Handling Per Order or Per Box Zone 2 (when by weight)
Order

Zone 3 Countries

Zone 3 Shipping Table
3:8.50,7:10.50,99:20.00

Zone 3 Handling Fee
0

Handling Per Order or Per Box Zone 3 (when by weight)
Order

Zone 4 Countries

Zone 4 Shipping Table
3:8.50,7:10.50,99:20.00

Zone 4 Handling Fee
0

Handling Per Order or Per Box Zone 4 (when by weight)
Order

Zone 5 Countries
US,CA, MX, PR

Zone 5 Shipping Table
0.5:18, 1:22, 1.5:26, 2:30, 2.5:34, 3:37, 3.5:41, 4:44, 4.5:47, 5:51, 5.5:54, 6:57, 6.5:108, 7:114, 7.5:119, 8:125, 8.5:127, 9:130, 9.5:132, 10:134, 10.5:136, 11:138, 11.5:140, 12:142, 12.5:144, 13:147, 13.5:149, 14:151, 14.5:153, 15:155, 15.5:158, 16:160, 16.5:163, 17:166, 17.5:168, 18:172, 18.5:175, 19:178, 19.5:181, 20:185, 20.5:194, 21:194, 22:203, 23:213, 24:222, 25:231, 26:240, 27:250, 28:259, 29:268, 30:277, 31:286, 32:296, 33:305, 34:314, 35:323, 36:333, 37:342, 38:351, 39:360, 40:370, 50:454, 60:544, 70:593, 80:668, 90:752, 100:779

Zone 5 Handling Fee
0

Handling Per Order or Per Box Zone 5 (when by weight)
Order

Zone 6 Countries

Zone 6 Shipping Table
3:8.50,7:10.50,99:20.00

Zone 6 Handling Fee
0

Handling Per Order or Per Box Zone 6 (when by weight)
Order

Zone 7 Countries

Zone 7 Shipping Table
3:8.50,7:10.50,99:20.00

Zone 7 Handling Fee
0

Handling Per Order or Per Box Zone 7 (when by weight)
Order

Zone 8 Countries

Zone 8 Shipping Table
3:8.50,7:10.50,99:20.00

Zone 8 Handling Fee
0

Handling Per Order or Per Box Zone 8 (when by weight)
Order

Zone 9 Countries

Zone 9 Shipping Table
3:8.50,7:10.50,99:20.00

Zone 9 Handling Fee
0

Handling Per Order or Per Box Zone 9 (when by weight)
Order

Zone 10 Countries

Zone 10 Shipping Table
3:8.50,7:10.50,99:20.00

Zone 10 Handling Fee
0

Handling Per Order or Per Box Zone 10 (when by weight)
Order

thanks!
g

14 Mar 2014, 10:51 PM
#37
ajeh avatar

ajeh

Oba-san

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

Re: Shipping per Categories

Currently, shipping is based on Product Weight ...

Let's assume these special Products are from categories_id 12 and categories_id 15 ...

Will ALL zones have the same shipping rate for Products in categories_id 12?

Will ALL zones have the same shipping rate for Products in categories_id 15?

The idea is to count the number of Items in categories_id 12 and categories_id 15 then multiple those by their specific shipping cost ...

So if 3 Products are from categories_id 12 and 2 Products are from categories_id 15, does that rate get computed as:
3 * 2.75 = 8.25 and add that to the current charges for each of the Zones
2 * 1.75 = 3.00 and add that to the current charges for each of the Zones

to get the total shipping cost ...

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!

17 Mar 2014, 4:54 PM
#38
gabstero avatar

gabstero

Zen Follower

Join Date:
Nov 2007
Posts:
342
Plugin Contributions:
0

Re: Shipping per Categories

Ajeh -

Thanks - To answer your questions:

Ajeh:

Currently, shipping is based on Product Weight ...

Let's assume these special Products are from categories_id 12 and categories_id 15 ...

Will ALL zones have the same shipping rate for Products in categories_id 12?

Yes.

Ajeh:

Will ALL zones have the same shipping rate for Products in categories_id 15?

Yes. But note that the products from this category ship from a different location that the ones in categories_id 12. So their rates should be calculated accordingly.
If easier, it would be nice to apply Product Weight shipping module strictly to this category. This way I have two categories that have two different shipping modules.

Ajeh:

The idea is to count the number of Items in categories_id 12 and categories_id 15 then multiple those by their specific shipping cost ...

So if 3 Products are from categories_id 12 and 2 Products are from categories_id 15, does that rate get computed as:
3 * 2.75 = 8.25 and add that to the current charges for each of the Zones
2 * 1.75 = 3.00 and add that to the current charges for each of the Zones

to get the total shipping cost ...

Yes - that's be nice!

thanks a lot!!

17 Mar 2014, 5:32 PM
#39
ajeh avatar

ajeh

Oba-san

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

Re: Shipping per Categories

Cannot use weight as weight is what is used for Zone Rates ...

You can, however, use 0 weight so it does not add anything but the calculated rate for the two categories ...

In the file:
/includes/modules/shipping/zones.php

add the code in RED:

[B]// bof: calculate rates for categories_id 12 and 15
      $chk_cat12 = 0;
      $chk_cat15 = 0;
      $chk_cat12 = $_SESSION['cart']->in_cart_check('master_categories_id','12');
      $chk_cat15 = $_SESSION['cart']->in_cart_check('master_categories_id','15');
      $chk_cat12 = $chk_cat12 * 2.75;
      $chk_cat15 = $chk_cat15 * 1.75;
      $extra_charge = $chk_cat12 + $chk_cat15;
[/B]
      $this->quotes = array('id' => $this->code,
                            'module' => MODULE_SHIPPING_ZONES_TEXT_TITLE,
                            'methods' => array(array('id' => $this->code,
                                                     'title' => $shipping_method,
                                                     'cost' => $shipping_cost[B] + $extra_charge[/B])));
[B]// eof: calculate rates for categories_id 12 and 15
[/B]

Note: check your settings on Configuration ... Shipping/Packaging ... for what you have on:

Order Free Shipping 0 Weight Status
If there is no weight to the order, does the order have Free Shipping?
0= no
1= yes

Note: When using Free Shipping, Enable the Free Shipping Module this will only show when shipping is free.

that should be set to 0 so these 0 weight products do not affect your Zone Rates ...

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 Mar 2014, 8:34 PM
#40
gabstero avatar

gabstero

Zen Follower

Join Date:
Nov 2007
Posts:
342
Plugin Contributions:
0

Re: Shipping per Categories

Ajeh - thanks so much!!

Is there a specific spot I should insert this snippet in the zones.php?

thanks