Zen Cart Logo
Forums / Built-in Shipping and Payment Modules / Switch from one shipping module to another dependent on product variables

Switch from one shipping module to another dependent on product variables

Locked

Views: 1,998

Results 1 to 20 of 20
This thread is locked. New replies are disabled.
10 Aug 2009, 2:08 AM
#1
litepockets avatar

litepockets

Zen Follower

Join Date:
Apr 2008
Location:
Covington, Washington, United States
Posts:
206
Plugin Contributions:
0

Switch from one shipping module to another dependent on product variables

Hello all...

I am trying to figure out if it is possible to use and show only FedEx by default, but if product weight <= 0, then use and show only table rates...?

The reason for this is that I have the weight for only about half of my products entered... So the FedEx module will only show the lowest rate (based on 0 lbs).

Thanks for your advice.

10 Aug 2009, 2:55 PM
#2
ajeh avatar

ajeh

Oba-san

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

Re: Switch from one shipping module to another dependent on product variables

Shipping modules display based on the $this->enabled being true and do not display based on $this->enabled being false ...

You could test the weight of the cart for 0 weight and set the $this->enabled to false and that would "turn off" the FedEx shipping module when the weight is 0 ...

10 Aug 2009, 7:05 PM
#3
litepockets avatar

litepockets

Zen Follower

Join Date:
Apr 2008
Location:
Covington, Washington, United States
Posts:
206
Plugin Contributions:
0

Re: Switch from one shipping module to another dependent on product variables

Ajeh,

Thank you. Would this do the trick then?

function quote($method = '') {

	global $shipping_weight, $shipping_num_boxes, $cart, $order;

        // FedEx not available if weight is 0 or null
	if ($shipping_weight ==0 | $shipping_weight ==null) {
		$this->enabled = ((MODULE_SHIPPING_FEDEX_GROUND_STATUS == 'False');
		} else {
		$this->enabled = ((MODULE_SHIPPING_FEDEX_GROUND_STATUS == 'True');
	}
10 Aug 2009, 7:08 PM
#4
ajeh avatar

ajeh

Oba-san

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

Re: Switch from one shipping module to another dependent on product variables

NOTE: the OR connector is || vs the single | you have ...

You should just be able to use is the $shipping_weight == 0 ...

Be aware that if you have Tare Weight set that this would be added in, so in the Configuration ... Shipping/Packaging ... you would want those set to 0:0 ...

Also, check where you are testing this and setting: $this->enabled

If it is not tested in the code below what you are showing, you are not using the code in the right place ...

10 Aug 2009, 7:39 PM
#5
litepockets avatar

litepockets

Zen Follower

Join Date:
Apr 2008
Location:
Covington, Washington, United States
Posts:
206
Plugin Contributions:
0

Re: Switch from one shipping module to another dependent on product variables

Good call on the "|" OR mistake, must have just been excited :)

Well, the good news is it works... The bad news is it doesn't work perfectly :) It doesn't allow the customer to get a FedEx quote using the estimator, which is fabulous. However, on the checkout page where it breaksdown the charges, it still displays FedEx but says:

No Rates Returned, E523 : Invalid weight.

I would like nothing to display. Is there a better place I should do my check?

11 Aug 2009, 3:27 AM
#6
ajeh avatar

ajeh

Oba-san

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

Re: Switch from one shipping module to another dependent on product variables

The better way to do this is at the start of the shipping module ... for example, USPS usps.php I would change this code:

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

to read:

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

    global $cart;
    if (IS_ADMIN_FLAG == false && $_SESSION['cart']->show_weight() == 0) {
      $this->enabled = false;
    }

This allows it to work in the Admin and the Catalog ...

Notice I am using the $_SESSION['cart']->show_weight() as the $shipping_weight is not available at this point ...

11 Aug 2009, 5:36 PM
#7
litepockets avatar

litepockets

Zen Follower

Join Date:
Apr 2008
Location:
Covington, Washington, United States
Posts:
206
Plugin Contributions:
0

Re: Switch from one shipping module to another dependent on product variables

That makes sense. I will give this a shot. Thank you!
Posted via Mobile Device

11 Aug 2009, 5:38 PM
#8
litepockets avatar

litepockets

Zen Follower

Join Date:
Apr 2008
Location:
Covington, Washington, United States
Posts:
206
Plugin Contributions:
0

Re: Switch from one shipping module to another dependent on product variables

Ajeh, another thing I appreciate is that you provide a "why" anytime you use code in a post. It helps all of us learn as opposed to just having the answer. Thanks again, your posts on every thread always seem to help me.
Posted via Mobile Device

12 Aug 2009, 3:39 AM
#9
ajeh avatar

ajeh

Oba-san

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

Re: Switch from one shipping module to another dependent on product variables

You are most welcome ... glad to be able to help you out ... :smile:

23 Sep 2010, 4:53 PM
#10
craig_md avatar

craig_md

New Zenner

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

Re: Switch from one shipping module to another dependent on product variables

Ajeh,
I have installed this mod but have been running into problems when people change items in their cart after going to checkout page 1. I want to have it set so that any package below .813 lbs will only offer the table rate that equates to USPS First class, all packages over that weight ship UPS. This works great as long as they don't edit items in their cart. If they start off with an order less than .813lbs and go to checkout page 1, and then go back and add enough product to go over the weight limit it gets messy. Returning to checkout page 1 only shows the UPS option, but its not selected. USPS is still selected though not displayed. It works inversely going from a heavier order to a lighter order as well. Some times I will see both shipping options. I have also noticed that sometimes when the address has changed both shipping options will pop up when only one should be displayed. In order to clear the unwanted shipping options, I sometimes have to empty the cart and then log out and log back in.

I put the code above into table.php, but wonder if it should be somewhere else?

I am running version 1.3.9e
Thanks
Craig

23 Sep 2010, 5:37 PM
#11
ajeh avatar

ajeh

Oba-san

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

Re: Switch from one shipping module to another dependent on product variables

What all shipping modules are installed and what custom code have you added to them? :unsure:

23 Sep 2010, 5:52 PM
#12
craig_md avatar

craig_md

New Zenner

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

Re: Switch from one shipping module to another dependent on product variables

Installed are Free shipping which applies to only a few items. Table, which I use for anything under .813 lbs and is limited to the lower 48 states. UPS, for all other shipments and USPS for alaska and Hawaii orders only per a zone only including them.
The only custom mod was adding in the center section of code below from //added by to }.

  $this->tax_basis = MODULE_SHIPPING_TABLE_TAX_BASIS;
    // disable only when entire cart is free shipping
    if (zen_get_shipping_enabled($this->code)) {
      $this->enabled = ((MODULE_SHIPPING_TABLE_STATUS == 'True') ? true : false);
    }
	// added in by cs for table ship off switch
    global $cart;
    if (IS_ADMIN_FLAG == false && $_SESSION['cart']->show_weight() > 0.813) {
      $this->enabled = false;
    }

    
    if ($this->enabled) {
      // check MODULE_SHIPPING_TABLE_HANDLING_METHOD is in
      $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_TABLE_HANDLING_METHOD'");
      if ($check_query->EOF) {
        $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Handling Per Order or Per Box', 'MODULE_SHIPPING_TABLE_HANDLING_METHOD', 'Order', 'Do you want to charge Handling Fee Per Order or Per Box?', '6', '0', 'zen_cfg_select_option(array(\'Order\', \'Box\'), ', now())");
      }
    }
23 Sep 2010, 7:40 PM
#13
ajeh avatar

ajeh

Oba-san

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

Re: Switch from one shipping module to another dependent on product variables

Which ones are showing together that should not be seen together?

23 Sep 2010, 7:48 PM
#14
craig_md avatar

craig_md

New Zenner

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

Re: Switch from one shipping module to another dependent on product variables

The table (orders less than .813lbs) and UPS (orders over .813lbs). The mod works until you pick a different address or adjust the weight above or below the .813lbs mark.

23 Sep 2010, 9:38 PM
#15
ajeh avatar

ajeh

Oba-san

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

Re: Switch from one shipping module to another dependent on product variables

Do you have some custom code in the UPS module to enable/disable it based on the weight?

24 Sep 2010, 4:23 PM
#16
craig_md avatar

craig_md

New Zenner

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

Re: Switch from one shipping module to another dependent on product variables

No mods in UPS.php.
I see what is happening now, I imported most of my customer data from another shopping cart system. For some reason the states in their address info need to be opened and re saved in order for the zones to work properly. Since I have the table shipping option limited to my lower 48 state zone it isn't showing up unless the address is edited first. Looking in customer data the states look to be fine but they don't jive with the zones. I guess I need to either export, fix, and then re import the file or some how modify my zones to match what has been imported. While I am in communication with a person of your expertise, how would you recommend fixing 6000 customers states?
Thanks
Craig

24 Sep 2010, 6:24 PM
#17
ajeh avatar

ajeh

Oba-san

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

Re: Switch from one shipping module to another dependent on product variables

I don't know the format of your old data for the other shopping cart ...

You would need to run a translate for the data of some type to fix the old customer data to match the new customer data ...

What are you importing the data from? There might be a translation program in the Free Software Add Ons ...

24 Sep 2010, 7:36 PM
#18
craig_md avatar

craig_md

New Zenner

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

Re: Switch from one shipping module to another dependent on product variables

It was some program called Candy Press. It was here when I got here. It took around 40 clicks to process an order. I have started searching, is there someway to open up the entire address book and edit the database?

24 Sep 2010, 10:11 PM
#19
ajeh avatar

ajeh

Oba-san

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

Re: Switch from one shipping module to another dependent on product variables

The database tables can be browsed in phpMyAdmin ...

The table:
address_book

holds the address(es) of the customers ...

27 Sep 2010, 12:30 PM
#20
craig_md avatar

craig_md

New Zenner

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

Re: Switch from one shipping module to another dependent on product variables

Thanks Again Ajeh!!