Zen Cart Logo
Forums / Built-in Shipping and Payment Modules / Different shipping methods for different categories

Different shipping methods for different categories

Views: 107,641

Results 541 to 554 of 554
30 Dec 2013, 3:21 PM
#541
pewe avatar

pewe

Zen Follower

Join Date:
Aug 2006
Posts:
134
Plugin Contributions:
0

Different shipping methods for different categories

Ajeh:

Zen Cart is designed to never select the Store Pickup automatically ...

On the checkout_shipping page, do you see the radio button to select Store Pickup, when it should be available?

Yes see below.

Attachment 13618

However - I think I may have jumped the gun with my post about the error (seen on the page above).

What confused me was - if I removed everything from the cart whilst logged in, then added a Store Pickup item to the empty cart whilst still logged in - the error appeared.

However, it seems that if I am logged out with no items in the cart, when I log in and add Store Pickup items only the error does not appear. It first appears if I add/delete items which cause a change in the delivery methods available.

So I think all is OK. :blush:

30 Dec 2013, 3:26 PM
#542
ajeh avatar

ajeh

Oba-san

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

Re: Different shipping methods for different categories

More or less the situation is the change of shipping method which shows that message ...

Choices:
1 Ignore it, that is the way it is

2 Change the message so it is less scary ... :lookaroun

30 Dec 2013, 3:30 PM
#543
pewe avatar

pewe

Zen Follower

Join Date:
Aug 2006
Posts:
134
Plugin Contributions:
0

Re: Different shipping methods for different categories

Ajeh:

2 Change the message so it is less scary ... :lookaroun

I changed the message - it now reads

You have changed the content of your cart - make up your mind or else I will send the boys round - remember I have your address!!!

:laugh::laugh:

Thanks for your help.

30 Dec 2013, 3:34 PM
#544
ajeh avatar

ajeh

Oba-san

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

Re: Different shipping methods for different categories

You are most welcome ... have a good holiday! :smile:

23 Jan 2014, 7:51 PM
#545
hawkweber avatar

hawkweber

New Zenner

Join Date:
Aug 2007
Posts:
15
Plugin Contributions:
0

Re: Different shipping methods for different categories

Ajeh,

I have tried to use the information in this thread to update my flat rate (flat.php) file to do the following:

  1. if cart contains only items from category 32 then show flat rate.
  2. if cart contains only items from category 32 but the qty is more than 4, then utilize higher flat rate.
  3. if cart contains any items from other categories in addition to category 32, then do not show flat rate and only present fedex.

The code mods that I have applied to flat.php (utilizing what I could glean from this thread) seem to work properly for all 3 conditions, but I noticed that the icon next to flat rate in the admin shipping module screen is yellow. This, from what I can gather, only has showed up if a module is installed but not enabled. (Green meaning module is installed and enabled, red meaning module is not installed).

Is there something I am missing from my code that is causing this yellow icon? Should I be concerned about it?

<?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
 */
// $Id: flat.php 14498 2009-10-01 20:16:16Z ajeh $
//

  class flat {
    var $code, $title, $description, $icon, $enabled;

// class constructor
    function flat() {
      global $order, $cart, $db;

      $this->code = 'flat';
      $this->title = MODULE_SHIPPING_FLAT_TEXT_TITLE;
      $this->description = MODULE_SHIPPING_FLAT_TEXT_DESCRIPTION;
      $this->sort_order = MODULE_SHIPPING_FLAT_SORT_ORDER;
      $this->icon = '';
      $this->tax_class = MODULE_SHIPPING_FLAT_TAX_CLASS;
      $this->tax_basis = MODULE_SHIPPING_FLAT_TAX_BASIS;

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

	  // Check for Deodorant (category 32) in cart and is it the only category in cart
	  // If it is only category then enable module for flat rate use
	  $cat32_only = false;
	  $chk_category32 = 0;
	  if (IS_ADMIN_FLAG == false) {
		$chk_category32 += $_SESSION['cart']->in_cart_check('master_categories_id','32');
		if ($chk_category32 > 0 && ($chk_category32 == $_SESSION['cart']->count_contents())) {
		  $cat32_only = true;
		}
	  }
	  if ((IS_ADMIN_FLAG == false && $cat32_only)) {
	    $this->enabled = true;
	  } else {
	    $this->enabled = false;
	  }
	  
      if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_FLAT_ZONE > 0) ) {
        $check_flag = false;
        $check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_FLAT_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, $cart;

	// Check to see if category 32 qty is greater than 4 to incur higher flat rate
	$chk_surcharge_category += ($_SESSION['cart']->in_cart_check('master_categories_id','32') > 4); 
    
    if ($chk_surcharge_category) {

      $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_TWO)));
	} else {

      $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)));
	}
      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_FLAT_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 Flat Shipping', 'MODULE_SHIPPING_FLAT_STATUS', 'True', 'Do you want to offer flat 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_FLAT_COST', '5.00', 'The shipping cost for all orders using 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 ('Shipping Cost with Surcharge', 'MODULE_SHIPPING_FLAT_COST_TWO', '10.00', 'The shipping cost for products in categories with higher flat rate.', '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_FLAT_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_FLAT_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_FLAT_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_FLAT_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\_FLAT\_%'");
    }

    function keys() {
      return array('MODULE_SHIPPING_FLAT_STATUS', 'MODULE_SHIPPING_FLAT_COST', 'MODULE_SHIPPING_FLAT_COST_TWO', 'MODULE_SHIPPING_FLAT_TAX_CLASS', 'MODULE_SHIPPING_FLAT_TAX_BASIS', 'MODULE_SHIPPING_FLAT_ZONE', 'MODULE_SHIPPING_FLAT_SORT_ORDER');
    }
  }
?>

Here is a screenshot showing the shipping module traffic lights:

Attachment 13696

BTW - the groundcom module is showing yellow as it is installed but not enabled.

Manny

23 Jan 2014, 11:19 PM
#546
ajeh avatar

ajeh

Oba-san

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

Re: Different shipping methods for different categories

I am not seeing the reason, off the top of my head ...

23 Jan 2014, 11:23 PM
#547
ajeh avatar

ajeh

Oba-san

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

Re: Different shipping methods for different categories

Found it ...

You have the code:

      if ((IS_ADMIN_FLAG == false && $cat32_only)) {
        $this->enabled = true;
      } else {
        $this->enabled = false;
      }

So in the Admin the:
$this->enabled

evaluates as false ... so you see the yellow icon as that would mean NOT enabled ...

24 Jan 2014, 1:26 AM
#548
hawkweber avatar

hawkweber

New Zenner

Join Date:
Aug 2007
Posts:
15
Plugin Contributions:
0

Re: Different shipping methods for different categories

Ajeh:

Found it ...

You have the code:

  if ((IS_ADMIN_FLAG == false && $cat32_only)) {
    $this->enabled = true;
  } else {
    $this->enabled = false;
  }
> 
> So in the Admin the:
> $this->enabled
> 
> evaluates as false ... so you see the yellow icon as that would mean NOT enabled ...

I thought that changing the $this->enabled to false would make it so that the module (option) doesn't show as a shipping option in the cart and setting it to true would make it show up.  Similar to the first items in this thread where you have:

```php
      // disable for one master_categories_id
      if ((IS_ADMIN_FLAG == false && $_SESSION['cart']->in_cart_check('master_categories_id','17') > 0)) {
          $this->enabled = false;
      }  

To turn off the shipping option if any items from master category 17 is in the cart.

If my coding is not the proper way to set it so that the option will show at checkout if the cart only contains master_category_32 then what do I need to change to make it work and make it so that the admin shipping module icon is green?

Manny

24 Jan 2014, 2:06 PM
#549
ajeh avatar

ajeh

Oba-san

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

Re: Different shipping methods for different categories

You have to ensure that when in the Admin that $this->enabled is true when this is installed ...

You are using:

      if (IS_ADMIN_FLAG == false) {
        $chk_category32 += $_SESSION['cart']->in_cart_check('master_categories_id','32');
        if ($chk_category32 > 0 && ($chk_category32 == $_SESSION['cart']->count_contents())) {
          $cat32_only = true;
        }
      }
      if ((IS_ADMIN_FLAG == false && $cat32_only)) {
        $this->enabled = true;
      } else {
        $this->enabled = false;
      }

Probable using:

      if (IS_ADMIN_FLAG == false) {
        $chk_category32 += $_SESSION['cart']->in_cart_check('master_categories_id','32');
        if ($chk_category32 > 0 && ($chk_category32 == $_SESSION['cart']->count_contents())) {
          $cat32_only = true;
        }
        if (($cat32_only)) {
          $this->enabled = true;
        } else {
          $this->enabled = false;
        }
      }
24 Jan 2014, 8:59 PM
#550
hawkweber avatar

hawkweber

New Zenner

Join Date:
Aug 2007
Posts:
15
Plugin Contributions:
0

Re: Different shipping methods for different categories

Ajeh:

You have to ensure that when in the Admin that $this->enabled is true when this is installed ...

Probable using:

  if (IS_ADMIN_FLAG == false) {
    $chk_category32 += $_SESSION['cart']->in_cart_check('master_categories_id','32');
    if ($chk_category32 > 0 && ($chk_category32 == $_SESSION['cart']->count_contents())) {
      $cat32_only = true;
    }
    if (($cat32_only)) {
      $this->enabled = true;
    } else {
      $this->enabled = false;
    }
  }

Ajeh - that didn't work.  Same issue with admin showing yellow.  Not only that, but I noticed that even if I disable the module in the admin console it would still show flat rate shipping option in the cart if it contains only category32 items.  So, this got me thinking - the line above this is:

```php
      if (zen_get_shipping_enabled($this->code)) {
        $this->enabled = ((MODULE_SHIPPING_FLAT_STATUS == 'True') ? true : false);

which I take as it checking to see if the module is enabled in the admin area and sets $this->enabled to true if it is or false if not and normal processing (without my code) would normally commence based on that. But my code was just checking to see if the admin flag was set and if not then it would run and if it found the cart to only contain the proper items would enable the module even though disabled in admin. So I modified the code to this:

	  $chk_category32 = 0;
	  if ((IS_ADMIN_FLAG == false) && ($this->enabled == true)) { 
		$chk_category32 += $_SESSION['cart']->in_cart_check('master_categories_id','32'); 
		if ($chk_category32 > 0 && ($chk_category32 == $_SESSION['cart']->count_contents())) {
		  $this->enabled = true;  // Only category 32 items in cart - enable
		} else {
	        $this->enabled = false; // Other Category items in cart - disable
	    }
	  }

This now does a check to make sure admin_flag is not set AND that the module status is enabled before running my code. This way if it is not enabled it will bypass the code, stay disabled and not show in the cart. This code seems to work correctly and the admin setting is green when enabled and yellow when disabled. The cart option shows when it should and doesn't when disabled in admin like it should.

But, I was wondering if there is a better way to code this. I am not very proficient with php and my code is somewhat redundant as the check to see that category32 > 0 and the count equals cart items sets the $this->enabled to true and if not then sets it to false. However theoretically the $this->enabled is already set to true as it wouldn't have run this code section if it wasnt. Should the

		if ($chk_category32 > 0 && ($chk_category32 == $_SESSION['cart']->count_contents()))

be some type of NOT statement and just set $this->enabled to false? Would that make better sense and coding and if so what is the statment to do it?

Manny

24 Jan 2014, 10:50 PM
#551
ajeh avatar

ajeh

Oba-san

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

Re: Different shipping methods for different categories

The code change I posted works just fine on my site, I am not sure why it does not work for you ...

The code change that you made does basically the same thing so which ever works for you is fine ...

I cannot think, off the top of my head, something that would work any better ...

25 Jan 2014, 2:58 AM
#552
hawkweber avatar

hawkweber

New Zenner

Join Date:
Aug 2007
Posts:
15
Plugin Contributions:
0

Re: Different shipping methods for different categories

Ajeh:

The code change I posted works just fine on my site, I am not sure why it does not work for you ...

The code change that you made does basically the same thing so which ever works for you is fine ...

I cannot think, off the top of my head, something that would work any better ...

Well, at least it's working properly now. Thanks for your help and looking at the code, I really appreciate it!

Manny

25 Jan 2014, 11:13 PM
#553
gonz0 avatar

gonz0

New Zenner

Join Date:
Apr 2007
Posts:
3
Plugin Contributions:
0

Re: Different shipping methods for different categories

I unfortunately need to use Zones as the USPS module is messed up always giving the wron price. Having said that I am useing Zones but cannot get the 1st class option to show for something under 3 oz's

18 Mar 2020, 1:12 AM
#554
nick1973 avatar

nick1973

Totally Zenned

Join Date:
Sep 2008
Location:
Cleethorpes
Posts:
1,230
Plugin Contributions:
3

Re: Different shipping methods for different categories

Linda, how would i use this with the Module called Big Royal Mail, found here https://www.zen-cart.com/downloads.php?do=file&id=190&styleid=2

Also I have three categories which are virtual products and two categories that aren't

Category One requires: Free Shipping, Next Day Delivery and Saturday Delivery

Category Two: No Shipping (Virtual)

Category Three: No Shipping (Virtual)

Category Four: No Shipping (Virtual)

Category Five: Big Royal Mail Shipping Methods

Using your code

// disable only when entire cart is free shipping       if (zen_get_shipping_enabled($this->code)) {           $this->enabled = ((MODULE_SHIPPING_ITEM_STATUS == 'True') ? true : false);       } 
      // disable for one master_categories_id       if ((IS_ADMIN_FLAG == false && $_SESSION['cart']->in_cart_check('master_categories_id','17') > 0)) {           $this->enabled = false;       }