Forums / Built-in Shipping and Payment Modules / turn on/off the shippment base on product weight? Need PHP Help

turn on/off the shippment base on product weight? Need PHP Help

Locked

Views: 1,161

Results 1 to 8 of 8
This thread is locked. New replies are disabled.
15 Aug 2008, 3:02 PM
#1
ebloger avatar

ebloger

New Zenner

Join Date:
Dec 2007
Posts:
35
Plugin Contributions:
0

turn on/off the shippment base on product weight? Need PHP Help

Hi All, some my products are heavy, the othes is light
i have the pre item and mzmt shipping modules
when the product's weight above 70lbs i want only show the pre item shipping module in checkout_shipping page, when the product's weight bellow 70lbs i want only show mzmt moduls.
in the mzmt.php i have add the following code ,but is can not work.
if ($products_weight = $product['products_weight'] < 70) {
$this->enabled = ((MODULE_SHIPPING_MZMT_STATUS == 'False') ? true : false);
} else {
$this->enabled = ture;
}

or

  if ($order->info['products_weight'] < 70) {

$this->enabled = ((MODULE_SHIPPING_MZMT_STATUS == 'False') ? true : false);
} else
$this->enabled =false;

16 Aug 2008, 5:46 PM
#2
ajeh avatar

ajeh

Oba-san

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

Re: turn on/off the shippment base on product weight? Need PHP Help

You could use:

      // disable only when entire cart is free shipping
      if (zen_get_shipping_enabled($this->code)) {
        // not for over 70
        if (IS_ADMIN_FLAG || $shipping_weight < 70) {
          $this->enabled = ((MODULE_SHIPPING_ITEM_STATUS == 'True') ? true : false);
        }
      }

Don't forget to global $shipping_weight so that it is available to you ...

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!

6 Nov 2008, 4:17 AM
#3
dantheman avatar

dantheman

New Zenner

Join Date:
May 2005
Location:
Toronto, Ontario, Canada
Posts:
41
Plugin Contributions:
0

Re: turn on/off the shippment base on product weight? Need PHP Help

I'm trying to turn on/off the shipment module based on price - the code below worked in ZC 1.37 just fine (by hiding the module). In this example, the module should not appear if the order is over $100.

global $order;

if ($order->info['subtotal'] > 100)
  $this->enabled = false;

Unfortunately, in ZC 1.38, it doesn't work anymore. Is there another command (not $this->enabled = false) that can be used to disable or hide the shipping module? Or perhaps the command works, but only once per session, so it can't be enabled or disabled "on the fly" in ZC 1.38?

Any ideas?

Dan G.

Notebook Solutions Inc.

http://www.notebooksolutions.ca

*Whoever said that money can’t buy happiness simply didn’t know where to go shopping.

  • Sydney J. Harris*
6 Nov 2008, 6:05 AM
#4
ajeh avatar

ajeh

Oba-san

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

Re: turn on/off the shippment base on product weight? Need PHP Help

Can you use:
$order->info['total']

the subtotal is 0 at that point so you are not obtaining a value ...

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!

6 Nov 2008, 4:08 PM
#5
dantheman avatar

dantheman

New Zenner

Join Date:
May 2005
Location:
Toronto, Ontario, Canada
Posts:
41
Plugin Contributions:
0

Re: turn on/off the shippment base on product weight? Need PHP Help

Both $order->info['total'] and $order->info['subtotal'] have values and can be used in the "if" statement, the problem is that > $this->enabled = false; command is ignored by the shipping module.

Dan G.

Notebook Solutions Inc.

http://www.notebooksolutions.ca

*Whoever said that money can’t buy happiness simply didn’t know where to go shopping.

  • Sydney J. Harris*
6 Nov 2008, 6:42 PM
#6
ajeh avatar

ajeh

Oba-san

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

Re: turn on/off the shippment base on product weight? Need PHP Help

echo both values just above where you have the IF ...

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!

7 Nov 2008, 2:36 PM
#7
dantheman avatar

dantheman

New Zenner

Join Date:
May 2005
Location:
Toronto, Ontario, Canada
Posts:
41
Plugin Contributions:
0

Re: turn on/off the shippment base on product weight? Need PHP Help

Well, in my case, echo of "Subtotal" outputs the price of the product(s), while "Total" outputs the sum of products, taxes and other surcharges (if any) - so this is OK, you can use either value depending on your needs.

I found out what the problem was: I was putting the custom "if" statement BEFORE the "zen_get_shipping_enabled" code, so the "if" statement (when true) would disable the module, but "zen_get_shipping_enabled" would just re-enable it - that's why it wasn't working.

WRONG code:

global $order;

if ($order->info['subtotal'] > 100)
  $this->enabled = false;

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

Perhaps I was mislead by "// disable only when..." so I didn't realize that the 2 lines of code below it actually ENABLE the shipping module. Once I put the custom "if" statement AFTER "zen_get_shipping_enabled", it started working just fine.

Working code:

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

global $order;

if ($order->info['subtotal'] > 100)
  $this->enabled = false;

Thanks for your help! The issue is now resolved.

Dan G.

Notebook Solutions Inc.

http://www.notebooksolutions.ca

*Whoever said that money can’t buy happiness simply didn’t know where to go shopping.

  • Sydney J. Harris*
7 Nov 2008, 6:03 PM
#8
ajeh avatar

ajeh

Oba-san

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

Re: turn on/off the shippment base on product weight? Need PHP Help

Be aware that this will only work when the customer is logged in and that the Shipping Estimator will not work as there isn't an Order to build from until the customer logs in ...

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!