If this is your first visit, check our documentation. To post, register or login.
Forums / Built-in Shipping and Payment Modules / Different shipping methods for different categories

Different shipping methods for different categories

Started by tylerd213 on 13 Mar 2008, 2:16 AM · Views: 107,884

Results 361 to 380 of 554
19 May 2011, 11:17 PM
#361
hornsales avatar

hornsales

New Zenner

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

Different shipping methods for different categories

Clone per item shipping module

Set original module to test to see if tickets are in the cart if they are not this module will turn on if tickets are in the cart it will not turn on

Set cloned module to test for tickets also. if the tickets are in the cart then this one will turn on if they are not it will not

Then the tricky part - in the cloned module have it count the number of tickets in the cart and have it subtract that number from the per item count before it multiples out to calculate shipping

Then set cloned module to have a $5.00 handling fee

19 May 2011, 11:41 PM
#362
hornsales avatar

hornsales

New Zenner

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

Re: Different shipping methods for different categories

Another way to doo this to make it easier in the future is this

Use only one per item shipping module

Then testing for categories as Ajeh has demonstrated

You will need to edit the line that actually calculates the shipping total
using the following logic

If (chk_tickets)>0

5+(7(chk_media))=shipping_total

else

(7(chkmedia))=shipping_total

Then in the future if you add boxed sets in their own category and you need to charge 9 per item for them

YOu also test for their category and modify the logic to be

If (chk_tickets)>0

5+(7(chk_media))+(9(chk_boxset))=shipping_total

else

(7(chkmedia))+(9(chk_boxset))=shipping_total

and you can keep going and going with this as you add in new categories that will require different shipping per item costs

the only thing with this is you need to keep everything in a category to have the same per item shipping cost.

Other wise you are going to have to redo the whole thing and do it to check for each and every product_id in your store and edit your module everytime you add a new item

BTW you do not want to use my syntax.

When ever I do coding I copy and paste from Ajeh's post to get it right

20 May 2011, 12:14 AM
#363
hornsales avatar

hornsales

New Zenner

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

Re: Different shipping methods for different categories

You know I just re read ajeh's post

and what i suggested the second time is exactly what ajeh gave you

so if that ain't gonna work for you.....

Here's the deal

It is nearly impossible to use 2 or more shipping modules to create one TOTAL SHIPPING COST

It has to be done within one module and one module only other wise the different modules show up as multiple shipping options like standard express overnight.

SO Option 1

you have one module and do it the way Ajeh laid out for you which will allow you to do what you want in the future provided you keep everything in a category to have the same per item shipping.

Or you do it like Ajeh laid out but instead of testing for master category you test for product_id.

The draw back to this is every time you add a product you have to edit the module.

But to my knowledge and from my own trial and error trying to get it to work for me you can not combine a test of master category and product id in the same statement. Ajeh may know how to do it or someone here might, but I could never get it to work.

Option 2

Make a separate clone of the shipping module like I suggested a couple posts above, testing for category or product_id to turn them on or off

but as you add new items with different shipping costs you are going to start having more and more modules and you will need to edit each module;s on/off test everytime you create a new module. and the logic gets more and more complicated

Ajeh's method is clean and simple and easily modified in the future

And by using your example of boxed sets it would make sense to put those in their own category in the future.

Of course I can see how it is not that simplistic A 12 disc box set will probably cost more that a 2 disc box set to ship

But Ajeh's methid can still be applied

As I said you can;t mix a test for product_id and master_category in the same test statement.

But say you added in two new dvds that are 4 disc special editions and you need to charge $9 per item shipping

Then Ajeh's code would look like this

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

global $cart;
$chk_dvd = 0;
$chk_dvd += $_SESSION['cart']->in_cart_check('master_categories_id','31');
$chk_dvd += $_SESSION['cart']->in_cart_check('master_categories_id','32');
$chk_dvd += $_SESSION['cart']->in_cart_check('master_categories_id','33');
$chk_dvd = $chk_dvd * 7.00;

$chk_tickets = 0;
$chk_tickets += $_SESSION['cart']->in_cart_check('master_categories_id','21');
$chk_tickets += $_SESSION['cart']->in_cart_check('master_categories_id','22');
$chk_tickets += $_SESSION['cart']->in_cart_check('master_categories_id','23');
$chk_tickets = ($chk_tickets > 0 ? 5.00 : 0.00);

$chk_box1= 0;
$chk_box1 += $_SESSION['cart']->in_cart_check('products_id','101');
$chk_dvd += $_SESSION['cart']->in_cart_check('products_id','102');
$chk_box1 = $chk_box1 * 9.00;

$cost = $chk_dvd + $chk_tickets + $chk_box1;
$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)));

101 and 102 would be replaced with the actual product ids of the boxed sets

Then as you go you create new tests. or add product_ids or master category ids to current tests

Just remember each test must be only be product id or master category

now what i did above assumes the 2 box sets are in a different category then the ones already being tested for.

But if you are just going to add them to say category 31 then all you do is change the 9 to a 2 since the chk_dvd is already going to add $7 in for that item

20 May 2011, 4:15 AM
#364
jilk avatar

jilk

New Zenner

Join Date:
May 2009
Posts:
7
Plugin Contributions:
0

Re: Different shipping methods for different categories

Thanks hornsales,

While it did not give me the solution, your post certainly helped by reminding me that I can only have one shipping module in my case - I thank you heaps for that! Having broken my store completely several times today :yuck: trying various ways of changing the code, I have currently concluded that I should really just use the "Per Item" shipping module.

That way I can set all of the products weights to their postage values:

Tickets = 0
DVD's = 7.00 or whatever the item's $ postage should be
Downloads = 0

So now my basic problem is to manipulate the "Per Item" module's handling fee so that it only applies when tickets are in the cart, and then apply it only once regardless of how many tickets are present. And of course, not apply it at all if there are no tickets present. It seems sort of like a quasi flat fee override.

Ideas on how to code this in item.php would be great!!!!

20 May 2011, 4:32 AM
#365
jilk avatar

jilk

New Zenner

Join Date:
May 2009
Posts:
7
Plugin Contributions:
0

Re: Different shipping methods for different categories

Hmmm.... make that the "Per Unit" module not the "Per item" module so that postage cost is handledd by the product weight field... apols for any confusion. My post should read...

I have currently concluded that I should really just use the "Per Unit" shipping module.

That way I can set all of the products weights to their postage values:

Tickets = 0
DVD's = 7.00 or whatever the item's $ postage should be
Downloads = 0

So now my basic problem is to manipulate the "Per Unit" module's handling fee so that it only applies when tickets are in the cart, and then apply it only once regardless of how many tickets are present. And of course, not apply it at all if there are no tickets present. It seems sort of like a quasi flat fee override.

Ideas on how to code this in perweight.php would be stupendous!!!!

20 May 2011, 5:41 PM
#366
hornsales avatar

hornsales

New Zenner

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

Re: Different shipping methods for different categories

That sounds like a brilliant idea actually

Pretty sure this will do what you want

global $cart;
$chk_tickets = 0;
$chk_tickets += $_SESSION['cart']->in_cart_check('master_categories_id','21');
$chk_tickets += $_SESSION['cart']->in_cart_check('master_categories_id','22');
$chk_tickets += $_SESSION['cart']->in_cart_check('master_categories_id','23');
$chk_tickets = ($chk_tickets > 0 ? 5.00 : 0.00);

Then change

'cost' => (MODULE_SHIPPING_PERWEIGHTUNIT_COST * $total_weight_units)
+ MODULE_SHIPPING_PERWEIGHTUNIT_HANDLING)));

to

'cost' => (MODULE_SHIPPING_PERWEIGHTUNIT_COST * $total_weight_units)
+ MODULE_SHIPPING_PERWEIGHTUNIT_HANDLING+$chk_tickets)));

22 May 2011, 10:18 PM
#367
jilk avatar

jilk

New Zenner

Join Date:
May 2009
Posts:
7
Plugin Contributions:
0

Re: Different shipping methods for different categories

Thanks Hornsales, I'm trying to insert the code into my perweightunit.php file but I'm unsure where it should go - my admin is also having a fit on the third line of the above code:

$chk_tickets += $_SESSION['cart']->in_cart_check('master_categories_id','21');

...resulting in "Fatal error: Call to a member function in_cart_check() on a non-object..."

Do I need to have something specific for admin? Do I need to include some brackets somewhere?

This is my original (unchanged) perweightunit.php file:

<?php
/**
 * @package shippingMethod
 * @copyright Copyright 2003-2006 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: perweightunit.php 3308 2006-03-29 08:21:33Z ajeh $
 */
/**
 * "Per Weight Unit" shipping module, allowing you to offer per-unit-rate shipping options
 *
 */
class perweightunit extends base {
  /**
   * $code determines the internal 'code' name used to designate "this" payment module
   *
   * @var string
   */
  var $code;
  /**
   * $title is the displayed name for this payment method
   *
   * @var string
   */
  var $title;
  /**
   * $description is a soft name for this payment method
   *
   * @var string
   */
  var $description;
  /**
   * module's icon
   *
   * @var string
   */
  var $icon;
  /**
   * $enabled determines whether this module shows or not... during checkout.
   *
   * @var boolean
   */
  var $enabled;
  /**
     * Constructor
   *
   * @return perweightunit
   */
  function perweightunit() {
    global $order, $db;

    $this->code = 'perweightunit';
    $this->title = MODULE_SHIPPING_PERWEIGHTUNIT_TEXT_TITLE;
    $this->description = MODULE_SHIPPING_PERWEIGHTUNIT_TEXT_DESCRIPTION;
    $this->sort_order = MODULE_SHIPPING_PERWEIGHTUNIT_SORT_ORDER;
    $this->icon = '';
    $this->tax_class = MODULE_SHIPPING_PERWEIGHTUNIT_TAX_CLASS;
    $this->tax_basis = MODULE_SHIPPING_PERWEIGHTUNIT_TAX_BASIS;

    // disable only when entire cart is free shipping
    if (zen_get_shipping_enabled($this->code)) {
      $this->enabled = ((MODULE_SHIPPING_PERWEIGHTUNIT_STATUS == 'True') ? true : false);
    }

    if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_PERWEIGHTUNIT_ZONE > 0) ) {
      $check_flag = false;
      $check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . "
                             where geo_zone_id = '" . MODULE_SHIPPING_PERWEIGHTUNIT_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;
      }
    }
  }
  /**
   * Obtain quote from shipping system/calculations
   *
   * @param string $method
   * @return array
   */
  function quote($method = '') {
    global $order, $shipping_weight;

    $total_weight_units = $shipping_weight;
    $this->quotes = array('id' => $this->code,
                          'module' => MODULE_SHIPPING_PERWEIGHTUNIT_TEXT_TITLE,
                          'methods' => array(array('id' => $this->code,
                                                   'title' => MODULE_SHIPPING_PERWEIGHTUNIT_TEXT_WAY,
                                                   'cost' => (MODULE_SHIPPING_PERWEIGHTUNIT_COST * $total_weight_units)
                                                              + MODULE_SHIPPING_PERWEIGHTUNIT_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);

    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_PERWEIGHTUNIT_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 Per Weight Unit Shipping', 'MODULE_SHIPPING_PERWEIGHTUNIT_STATUS', 'True', 'Do you want to offer per unit rate shipping?<br /><br />Product Quantity * Units (products_weight) * Cost per Unit', '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 per Unit', 'MODULE_SHIPPING_PERWEIGHTUNIT_COST', '1', 'NOTE: When using this Shipping Module be sure to check the Tare settings in the Shipping/Packaging and set the Largest Weight high enough to handle the price, such as 5000.00 and the adjust the settings on Small and Large packages which will add to the price as well.<br /><br />The shipping cost will be used to determin shipping charges based on: Product Quantity * Units (products_weight) * Cost per Unit - 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_PERWEIGHTUNIT_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_PERWEIGHTUNIT_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_PERWEIGHTUNIT_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_PERWEIGHTUNIT_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_PERWEIGHTUNIT_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_PERWEIGHTUNIT_%'");
  }
  /**
   * Internal list of configuration keys used for configuration of the module
   *
   * @return array
   */
  function keys() {
    return array('MODULE_SHIPPING_PERWEIGHTUNIT_STATUS', 'MODULE_SHIPPING_PERWEIGHTUNIT_COST', 'MODULE_SHIPPING_PERWEIGHTUNIT_HANDLING', 'MODULE_SHIPPING_PERWEIGHTUNIT_TAX_CLASS', 'MODULE_SHIPPING_PERWEIGHTUNIT_TAX_BASIS', 'MODULE_SHIPPING_PERWEIGHTUNIT_ZONE', 'MODULE_SHIPPING_PERWEIGHTUNIT_SORT_ORDER');
  }
}
?>

Your help is truly appreciated!

23 May 2011, 1:41 AM
#368
hornsales avatar

hornsales

New Zenner

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

Re: Different shipping methods for different categories

This is a total guess

I have used the concept of this to enable or disable a shipping method. Ajeh is the real expert oi this since I believe she wrote the module

The changes are in red

<?php /** * @package shippingMethod * @copyright Copyright 2003-2006 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: perweightunit.php 3308 2006-03-29 08:21:33Z ajeh $ */ /** * "Per Weight Unit" shipping module, allowing you to offer per-unit-rate shipping options * */ class perweightunit extends base { /** * $code determines the internal 'code' name used to designate "this" payment module * * @var string */ var $code; /** * $title is the displayed name for this payment method * * @var string */ var $title; /** * $description is a soft name for this payment method * * @var string */ var $description; /** * module's icon * * @var string */ var $icon; /** * $enabled determines whether this module shows or not... during checkout. * * @var boolean */ var $enabled; /** * Constructor * * @return perweightunit */ function perweightunit() { global $order, $db; $this->code = 'perweightunit'; $this->title = MODULE_SHIPPING_PERWEIGHTUNIT_TEXT_TITLE; $this->description = MODULE_SHIPPING_PERWEIGHTUNIT_TEXT_DESCRIPTION; $this->sort_order = MODULE_SHIPPING_PERWEIGHTUNIT_SORT_ORDER; $this->icon = ''; $this->tax_class = MODULE_SHIPPING_PERWEIGHTUNIT_TAX_CLASS; $this->tax_basis = MODULE_SHIPPING_PERWEIGHTUNIT_TAX_BASIS; // disable only when entire cart is free shipping if (zen_get_shipping_enabled($this->code)) { $this->enabled = ((MODULE_SHIPPING_PERWEIGHTUNIT_STATUS == 'True') ? true : false); } if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_PERWEIGHTUNIT_ZONE > 0) ) { $check_flag = false; $check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_PERWEIGHTUNIT_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; } } } /** * Obtain quote from shipping system/calculations * * @param string $method * @return array */ function quote($method = '') { global $order, $shipping_weight; $chk_tickets = 0; $chk_tickets += $_SESSION['cart']->in_cart_check('master_categories_id','21'); $chk_tickets += $_SESSION['cart']->in_cart_check('master_categories_id','22'); $chk_tickets += $_SESSION['cart']->in_cart_check('master_categories_id','23'); $chk_tickets = ($chk_tickets > 0 ? 5.00 : 0.00); $total_weight_units = $shipping_weight; $this->quotes = array('id' => $this->code, 'module' => MODULE_SHIPPING_PERWEIGHTUNIT_TEXT_TITLE, 'methods' => array(array('id' => $this->code, 'title' => MODULE_SHIPPING_PERWEIGHTUNIT_TEXT_WAY, 'cost' => (MODULE_SHIPPING_PERWEIGHTUNIT_COST * $total_weight_units) + MODULE_SHIPPING_PERWEIGHTUNIT_HANDLING + $chk_tickets))); 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; } /** * 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_PERWEIGHTUNIT_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 Per Weight Unit Shipping', 'MODULE_SHIPPING_PERWEIGHTUNIT_STATUS', 'True', 'Do you want to offer per unit rate shipping?<br /><br />Product Quantity * Units (products_weight) * Cost per Unit', '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 per Unit', 'MODULE_SHIPPING_PERWEIGHTUNIT_COST', '1', 'NOTE: When using this Shipping Module be sure to check the Tare settings in the Shipping/Packaging and set the Largest Weight high enough to handle the price, such as 5000.00 and the adjust the settings on Small and Large packages which will add to the price as well.<br /><br />The shipping cost will be used to determin shipping charges based on: Product Quantity * Units (products_weight) * Cost per Unit - 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_PERWEIGHTUNIT_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_PERWEIGHTUNIT_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_PERWEIGHTUNIT_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_PERWEIGHTUNIT_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_PERWEIGHTUNIT_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_PERWEIGHTUNIT_%'"); } /** * Internal list of configuration keys used for configuration of the module * * @return array */ function keys() { return array('MODULE_SHIPPING_PERWEIGHTUNIT_STATUS', 'MODULE_SHIPPING_PERWEIGHTUNIT_COST', 'MODULE_SHIPPING_PERWEIGHTUNIT_HANDLING', 'MODULE_SHIPPING_PERWEIGHTUNIT_TAX_CLASS', 'MODULE_SHIPPING_PERWEIGHTUNIT_TAX_BASIS', 'MODULE_SHIPPING_PERWEIGHTUNIT_ZONE', 'MODULE_SHIPPING_PERWEIGHTUNIT_SORT_ORDER'); } } ?>
23 May 2011, 2:37 AM
#369
jilk avatar

jilk

New Zenner

Join Date:
May 2009
Posts:
7
Plugin Contributions:
0

Re: Different shipping methods for different categories

Hornsales - YOU ARE A GURU!!!!!

This code works perfectly! Thank you soooooooo much!

My only glitch, for anyone trying this method - I got errors in admin but was swiftly fixed by removing (uninstalling) the Per Unit shipping module in admin before changing the perunitweight.php file, then re-installing the module in admin.

I also made changes to the language file for the perunitweight to reflect that the "Order" fees included both postage and booking fees.

WORKS A TREAT!!!!

Hornsales and Ajeh - thanks so much for your help :hug::clap:

23 May 2011, 12:52 PM
#370
hornsales avatar

hornsales

New Zenner

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

Re: Different shipping methods for different categories

you are quite welcome

26 May 2011, 12:07 PM
#371
colin01 avatar

colin01

New Zenner

Join Date:
May 2011
Posts:
9
Plugin Contributions:
0

Re: Different shipping methods for different categories

Hi some advice needed please

I would like to clone the per item shipping module, but it is based on zones, the product is irrelevant.

I send out books and I charge a flat rate of shipping per item as follows:

Anywhere in the UK is £1.90 per item, Anywhere in Europe is £2.90 per item Anywhere else in the world is £3.90 per item.

I have achieved the result I want using zone rates module, but it's messy and I'd like to clone the per item module.

Any help would be much appreciated.

26 May 2011, 3:07 PM
#372
ajeh avatar

ajeh

Oba-san

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

Re: Different shipping methods for different categories

Build 3 Zone definitions ...

Next, clone the Item Rate item shipping module ...

Now, add your Zones that you built to each one and set its individual 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!

26 May 2011, 3:15 PM
#373
colin01 avatar

colin01

New Zenner

Join Date:
May 2011
Posts:
9
Plugin Contributions:
0

Re: Different shipping methods for different categories

Thanks very much

got it sorted.

8 Aug 2011, 7:19 PM
#374
kerrie avatar

kerrie

New Zenner

Join Date:
Sep 2007
Location:
Phoenix, Arizona
Posts:
15
Plugin Contributions:
0

Re: Different shipping methods for different categories

Do you think this same method would work if for example I wanted ABC Product to default to ground UPS shipping and DEF Product to default to air UPS shipping??????????

Kerrie Mallory-Thompson
https://www.laserbits.com

15 Oct 2011, 7:43 AM
#375
andreitero avatar

andreitero

Zen Follower

Join Date:
Dec 2009
Posts:
207
Plugin Contributions:
0

Re: Different shipping methods for different categories

GraniteMan44:

I would like to do what the original poster asked. If I want to use "per item" on more than one category, do I have to duplicate the

  • if ((IS_ADMIN_FLAG == false && $_SESSION['cart']->in_cart_check('master_categories_id','17') > 0)) {
    $this->enabled = false; *

for each category?

Or can I list the others within the same line as the '17' ?

example: 'master_categories_id','17','18', '20')

Thank you.

G

Does any one have a solution for this?
The condition is if the cart contains products from any of these categories.

Tried something like:

in_array($master_categories_id, array('17','18','20'))

But that did not work, maybe the syntax is wrong?

15 Oct 2011, 1:18 PM
#376
ajeh avatar

ajeh

Oba-san

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

Re: Different shipping methods for different categories

Let's say you were trying to customize the Per Item item shipping module in:
/includes/modules/shipping/item.php

You could use something like adding the code in RED:

      // disable only when entire cart is free shipping
      if (zen_get_shipping_enabled($this->code)) {
        $this->enabled = ((MODULE_SHIPPING_ITEM_STATUS == 'True') ? true : false);
      }

// bof: turn off for master_categories_id 31, 32 or 33
      if (!IS_ADMIN_FLAG) {
        global $cart;
        $chk_products = 0;
        $chk_products += $_SESSION['cart']->in_cart_check('master_categories_id','31');
        $chk_products += $_SESSION['cart']->in_cart_check('master_categories_id','32');
        $chk_products += $_SESSION['cart']->in_cart_check('master_categories_id','33');
        if ($chk_products > 0) {
          $this->enabled = false;
        }
      }
// eof: turn off for master_categories_id 31, 32 or 33

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 Oct 2011, 3:31 AM
#377
sdpolishdeli avatar

sdpolishdeli

New Zenner

Join Date:
Oct 2011
Location:
Pittsburgh, PA
Posts:
18
Plugin Contributions:
0

Re: Different shipping methods for different categories

hello, I am new to ZenCart,just starting... I seem to have a similar issue. My products fall into two categories: Perishables and Nonperishables. My shipping method is UPS with the drop down menu showing 5 of UPS shipping options. My problem is that Perishables can only be shipped a 1Day or a 2Day shipping while Nonperishables can use Ground, 3Day.. basicaly any shipping. How to do it so Perishables will only show a limited drop down menu with two shipping options while Nonperishable will have a full 6 option menu?
Also, when the cart contains any Perishable item, I need to add a charge for a cooler. Where should it be set up so it only adds to Perishables and so only one cooler is added regardles on the quantity of Perishables ordered??? Grateful for any help!

Owners of the best home made polish food for sale online.
Come visit us at our polish deli. We are first on google under polish deli.

20 Oct 2011, 11:09 PM
#378
brobrow avatar

brobrow

New Zenner

Join Date:
Jun 2011
Posts:
13
Plugin Contributions:
0

Re: Different shipping methods for different categories


```For some reason this isnt working for me and I cant work out why.

I have tried the code from both post #9 and post #376

Currently im using the code from post 376.

When I add a product NOT from category_id 31, 32 or 33 it still disables the item shipping module.

This is the website <http://www.blackmarketartco.com>

heres 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); } // bof: turn off for master_categories_id 31, 32 or 33 if (!IS_ADMIN_FLAG) { global $cart; $chk_products = 0; $chk_products += $_SESSION['cart']->in_cart_check('master_categories_id','31'); $chk_products += $_SESSION['cart']->in_cart_check('master_categories_id','32'); $chk_products += $_SESSION['cart']->in_cart_check('master_categories_id','33'); if ($chk_products > 0) { $this->enabled = false; } } // eof: turn off for master_categories_id 31, 32 or 33 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; // adjusted count for free shipping $item_total_count = $total_count - $_SESSION['cart']->free_shipping_items(); $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 * $item_total_count) + MODULE_SHIPPING_ITEM_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); 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'); } } ?>
20 Oct 2011, 11:16 PM
#379
ajeh avatar

ajeh

Oba-san

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

Re: Different shipping methods for different categories

Do you use Linked Products? :unsure:

Do you have a specific Product that this is happening with?

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!

20 Oct 2011, 11:32 PM
#380
brobrow avatar

brobrow

New Zenner

Join Date:
Jun 2011
Posts:
13
Plugin Contributions:
0

Re: Different shipping methods for different categories

Im not using linked products.

I have tried multiple products, but for example

http://www.blackmarketartco.com/index.php?main_page=product_info&cPath=22_30&products_id=438

Also, this may be why, when I add my code to the file then load the admin->shipping modules page, the circle icon thingy is yellow. Before I add the code it is green.