Zen Cart Logo
Forums / General Questions / Restrict shipping module to specific category

Restrict shipping module to specific category

Views: 1,765

Results 1 to 13 of 13
26 Mar 2012, 3:04 AM
#1
lanbo avatar

lanbo

New Zenner

Join Date:
Dec 2011
Posts:
48
Plugin Contributions:
0

Restrict shipping module to specific category

Hello. I'll try to be as specific as possible as shortly as possible. :)

I am using the FedEx module by numinix located here: https://www.numinix.com/fedex-web-services-shipping?zenid=ded8cfcc2384caba7cb3bf343cd189ce

What would be the easiest way to disable this shipping module and only allow it to be selected for certain categories? Specifically, the categories are 17-23. 18-23 are all subcategories of 17 like this:

17->18->20
------->21
--->19->22
------->23

So basically I have two modules, USPS and FedEx. I want USPS to always show, and I want FedEx to only show as an option for the above categories. I'm also fine with creating a new column in the products table if necessary but I'm thinking that won't be needed.

As always, thanks for your help.

26 Mar 2012, 1:05 PM
#2
ajeh avatar

ajeh

Oba-san

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

Re: Restrict shipping module to specific category

What happens if 3 Products come from master_categories_id 20, 21, 22 and/or 23 and 1 product comes from another master_categories_id ... does FedEx show? :unsure:

26 Mar 2012, 1:47 PM
#3
lanbo avatar

lanbo

New Zenner

Join Date:
Dec 2011
Posts:
48
Plugin Contributions:
0

Re: Restrict shipping module to specific category

Good catch. That actually brings up another question I'll post at the end of this reply.

Preferably, FedEx would only show when all products are in those categories.

The other question that comes to mind (and I can ask elsewhere if needed) would be if there is a way to not allow checkout if the cart has mixed items. Maybe give a message saying items xxx must be purchased separately. Would be cool since I have some hazmat items that have to ship separately.

Thanks again.

26 Mar 2012, 1:50 PM
#4
ajeh avatar

ajeh

Oba-san

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

Re: Restrict shipping module to specific category

You can customize the FedEx with the code in RED to only show if ALL products in the cart use master_categories_id 20, 21, 22 and 23 with:

      if (zen_get_shipping_enabled($this->code)) {
			  $this->enabled = ((MODULE_SHIPPING_FEDEX_EXPRESS_STATUS == 'True') ? true : false);
      }
      
    if (!IS_ADMIN_FLAG) {
      global $cart;
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','20');
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','21');
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','22');
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','23');
      
      if ($_SESSION['cart']->count_contents() == $chk_cat) {
        $this->enabled = false;
      }
    }
      

26 Mar 2012, 2:56 PM
#5
lanbo avatar

lanbo

New Zenner

Join Date:
Dec 2011
Posts:
48
Plugin Contributions:
0

Re: Restrict shipping module to specific category

Not sure if I did something wrong, but it shows FedEx no matter what. Below is the first section of the module code:

<?php
class fedexwebservices {
 var $code, $title, $description, $icon, $sort_order, $enabled, $tax_class, $fedex_key, $fedex_pwd, $fedex_act_num, $fedex_meter_num, $country;

//Class Constructor
  function fedexwebservices() {
    global $order, $customer_id, $db;
    
    @define('MODULE_SHIPPING_FEDEX_WEB_SERVICES_KEY', 'PpFEn9QGjnR4Wdb2');
    @define('MODULE_SHIPPING_FEDEX_WEB_SERVICES_PWD', 'u4hXPKKcpKBw9RQ4n1hBvsJAH');
    @define('MODULE_SHIPPING_FEDEX_WEB_SERVICES_INSURE', 0); 
    $this->code             = "fedexwebservices";
    $this->title             = MODULE_SHIPPING_FEDEX_WEB_SERVICES_TEXT_TITLE;
    $this->description      = MODULE_SHIPPING_FEDEX_WEB_SERVICES_TEXT_DESCRIPTION;
    $this->sort_order        = MODULE_SHIPPING_FEDEX_WEB_SERVICES_SORT_ORDER;
    $this->handling_fee     = MODULE_SHIPPING_FEDEX_WEB_SERVICES_HANDLING_FEE;
    //$this->icon = DIR_WS_IMAGES . 'fedex-images/fedex.gif';
    $this->icon = ''; 
    if (zen_get_shipping_enabled($this->code)) {
      $this->enabled = ((MODULE_SHIPPING_FEDEX_WEB_SERVICES_STATUS == 'true') ? true : false);
    }
	if (!IS_ADMIN_FLAG) {
      global $cart;
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','20');
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','21');
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','22');
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','23');
      
      if ($_SESSION['cart']->count_contents() == $chk_cat) {
        $this->enabled = false;
      }
    }
    $this->tax_class        = MODULE_SHIPPING_FEDEX_WEB_SERVICES_TAX_CLASS;
    $this->fedex_key        = MODULE_SHIPPING_FEDEX_WEB_SERVICES_KEY;
    $this->fedex_pwd        = MODULE_SHIPPING_FEDEX_WEB_SERVICES_PWD;
    $this->fedex_act_num    = MODULE_SHIPPING_FEDEX_WEB_SERVICES_ACT_NUM;
    $this->fedex_meter_num  = MODULE_SHIPPING_FEDEX_WEB_SERVICES_METER_NUM;
    if (defined("SHIPPING_ORIGIN_COUNTRY")) {
      if ((int)SHIPPING_ORIGIN_COUNTRY > 0) {
        $countries_array = zen_get_countries(SHIPPING_ORIGIN_COUNTRY, true);
        $this->country = $countries_array['countries_iso_code_2'];
      } else {
        $this->country = SHIPPING_ORIGIN_COUNTRY;
      }
    } else {
      $this->country = STORE_ORIGIN_COUNTRY;
    }
    if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_FEDEX_WEB_SERVICES_ZONE > 0) ) {
      $check_flag = false;
      $check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_FEDEX_WEB_SERVICES_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

EDIT:

Also, I just noticed that it does NOT show FedEx when items in the categories 20-23 are added, but if an item from another category is added then it shows FedEx.

26 Mar 2012, 3:21 PM
#6
lanbo avatar

lanbo

New Zenner

Join Date:
Dec 2011
Posts:
48
Plugin Contributions:
0

Re: Restrict shipping module to specific category

Since categories 15 and 16 are the only ones that cannot ship FedEx (I probably should have mentioned that, sorry), I changed it to this and it appears to work properly. Do you foresee any problems with anything?

	if (!IS_ADMIN_FLAG) {
      global $cart;
	  $chk_cat = 0;
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','15');
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','16');
      
      if ($chk_cat > 0) {
        $this->enabled = false;
      }
    }

Thanks again.

26 Mar 2012, 3:57 PM
#7
ajeh avatar

ajeh

Oba-san

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

Re: Restrict shipping module to specific category

That method can work ...

You mainly are trying to build a test to see what is in the cart and when that condition is met either allow or not allow the shipping module is shown ...

26 Mar 2012, 4:04 PM
#8
lanbo avatar

lanbo

New Zenner

Join Date:
Dec 2011
Posts:
48
Plugin Contributions:
0

Re: Restrict shipping module to specific category

Ok, thanks. I'll keep an eye on it in the event I add other non-ground shippable items.

With my other question about no allowing checkout if the items are mixed, should I ask that in its own thread?

Thanks again.

26 Mar 2012, 4:07 PM
#9
ajeh avatar

ajeh

Oba-san

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

Re: Restrict shipping module to specific category

If you build your conditions on when the shipping module can display, if all shipping modules get disabled because of the conditions you test for then the customer will not be able to checkout ...

26 Mar 2012, 5:05 PM
#10
lanbo avatar

lanbo

New Zenner

Join Date:
Dec 2011
Posts:
48
Plugin Contributions:
0

Re: Restrict shipping module to specific category

Makes sense. Thanks for your help.

28 Mar 2012, 3:39 AM
#11
kny1 avatar

kny1

New Zenner

Join Date:
Mar 2012
Posts:
2
Plugin Contributions:
0

Re: Restrict shipping module to specific category

Hi,

I am using the same FedEx module and was wondering if it is possible to disable the shipping based upon a specific product instead of a specific category?

I have one product that is light, but because of the dimensions it must be shipped freight. I am hoping to disable FedEx from quoting shipping on that single product and allow the freightquote module to pick it up.

Any help would be greatly appreciated.

Thanks,
Ken

28 Mar 2012, 3:54 AM
#12
lanbo avatar

lanbo

New Zenner

Join Date:
Dec 2011
Posts:
48
Plugin Contributions:
0

Re: Restrict shipping module to specific category

I'm sure there are other ways, but if you're wanting to do it exactly like I did with my category, you could do the single item like this. Let's assume the product ID is 12.

    if (!IS_ADMIN_FLAG) { 
      global $cart; 
      $chk_cat = 0; 
      $chk_cat += $_SESSION['cart']->in_cart_check('products_id','12'); 
       
      if ($chk_cat > 0) { 
        $this->enabled = false; 
      } 
    } 

That should do the trick. But as noted in earlier posts, that will disable FedEx if that item is added even if there are other items that are eligible for FedEx.

EDIT: Sorry for the original crappy PHP code, I posted it from my iPad and it didn't work so well.

28 Mar 2012, 3:13 PM
#13
kny1 avatar

kny1

New Zenner

Join Date:
Mar 2012
Posts:
2
Plugin Contributions:
0

Re: Restrict shipping module to specific category

Great, Thank you! Works perfect.