This is a notification for Guests
Forums / Built-in Shipping and Payment Modules / Shipping Module Programming Question about weight and free shipping

Shipping Module Programming Question about weight and free shipping

Results 1 to 20 of 60
26 Jul 2011, 14:17
#1
voltar avatar

voltar

New Zenner

Join Date:
Apr 2011
Posts:
80
Plugin Contributions:
0

Shipping Module Programming Question about weight and free shipping

I would like to identify if a customer is a USA customer in shipping.php to make a decision on whether or not to add the Free Shipping weight back to $total_weight. Can someone direct me to the correct variable that would allow me to do this?

Something to the effect of:

if (USA customer)
$total_weight -= $_SESSION['cart']->free_shipping_weight();
else
$total_weight += $_SESSION['cart']->free_shipping_weight();

Thanks.
26 Jul 2011, 15:04
#2
ajeh avatar

ajeh

Oba-san

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

Re: Shipping Module Programming Question about weight and free shipping

Did you look at your original post and read the post that I just posted for reference?
http://www.zen-cart.com/forum/showthread.php?p=1050375#post1050375

NOTE: if you continue to have problems, please respond to this post so we can work on your specific issues ...
26 Jul 2011, 16:49
#3
voltar avatar

voltar

New Zenner

Join Date:
Apr 2011
Posts:
80
Plugin Contributions:
0

Re: Shipping Module Programming Question about weight and free shipping

Thanks for the reply. This looks like the thing I wanted to do. The only question I have is how or where are the valid_zone_id's defined? I would like have free shipping to all 50 states + DC.

I assume that I would need to make similar changes to the UPS module as done for the USPS module to have both options?

Out of curiosity, was the way I was wanting to go about this not going to work or not the right way to do it? The reason I ask is that it seemed to work when testing by changing shipping.php and adding items either as a USA customer or changing shipping.php and adding items as a non-USA customer.

Thanks.
26 Jul 2011, 17:12
#4
ajeh avatar

ajeh

Oba-san

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

Re: Shipping Module Programming Question about weight and free shipping

To make Always Free Shipping only work for the US 50+ States ... you would first want to make sure it works with the USPS shipping as described in post #11 ...

If so, then you would need to adapt that code to UPS if you are also using that shipping module ...

Have you tried the customization on the USPS shipping module:
/includes/modules/shipping/usps.php

and the Shipping class file:
/includes/class/shipping.php

If so, is the USPS shipping module working correctly?
27 Jul 2011, 15:58
#5
voltar avatar

voltar

New Zenner

Join Date:
Apr 2011
Posts:
80
Plugin Contributions:
0

Re: Shipping Module Programming Question about weight and free shipping

Is the $valid_zone_id the number found in the geo_zone_id in table zones_to_geo_zones?
27 Jul 2011, 16:08
#6
voltar avatar

voltar

New Zenner

Join Date:
Apr 2011
Posts:
80
Plugin Contributions:
0

Re: Shipping Module Programming Question about weight and free shipping

I seemed to have answered my question from above. Now, I've implemented to changes but I need to do one more thing. I still need to show all of the shipping options with the actual weight used in the calculations even though Free Shipping is enabled to allow the customer the opportunity to select a faster option if they want. For Free Shipping, we will select the most cost effective method whereas the customer may want to use Express and pay the additional cost. How would I implement this option?
27 Jul 2011, 16:46
#7
ajeh avatar

ajeh

Oba-san

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

Re: Shipping Module Programming Question about weight and free shipping

What is the full goal here?

Do you want All US Customers to get Free Shipping plus the regular shipping methods and non-US to get just the regular shipping methods?

What shipping modules do you have installed? :unsure:
27 Jul 2011, 17:00
#8
voltar avatar

voltar

New Zenner

Join Date:
Apr 2011
Posts:
80
Plugin Contributions:
0

Re: Shipping Module Programming Question about weight and free shipping

Exactly. This way the customer gets to make the shipping choice that best fits their situation. My installed modules are Free Shipping, USPS, and UPS.
27 Jul 2011, 17:14
#9
ajeh avatar

ajeh

Oba-san

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

Re: Shipping Module Programming Question about weight and free shipping

Does the US always get the Free Shipping Option regardless of Products in the cart? :unsure:
27 Jul 2011, 17:21
#10
voltar avatar

voltar

New Zenner

Join Date:
Apr 2011
Posts:
80
Plugin Contributions:
0

Re: Shipping Module Programming Question about weight and free shipping

No. Only the products marked as Always Free Shipping for USA customers have that option. Everything else should add the associated weight to the total.
28 Jul 2011, 00:09
#11
ajeh avatar

ajeh

Oba-san

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

Re: Shipping Module Programming Question about weight and free shipping

Good news ... it can be done ... :cool:

Bad News ... you get to start over ... :blink:

When you want US ONLY Free Shipping *and* Regular Shipping for UPS and USPS ...

Products are Marked as Always Free Shipping YES *and* Product Weight is set ...

Edit the shipping class and add the new code in red:
/includes/classes/shipping.php

  function calculate_boxes_weight_and_tare() {
    global $total_weight, $shipping_weight, $shipping_quoted, $shipping_num_boxes;

// bof: allow 1 zone only for Always Free Shipping US ONLY
// add back in the Always Free Shipping Weight for everyone
    global $db, $order, $cart;
          $total_weight += $_SESSION['cart']->free_shipping_weight;
// bof: allow 1 zone only for Always Free Shipping US ONLY

    if (is_array($this->modules)) {


Edit the USPS shipping module:
/includes/modules/shipping/usps.php

and comment out the test for Free Shipping:
    // disable only when entire cart is free shipping
//    if (zen_get_shipping_enabled($this->code)) {
      $this->enabled = ((MODULE_SHIPPING_USPS_STATUS == 'True') ? true : false);
//    }


Edit the USPS shipping module:
/includes/modules/shipping/ups.php

and comment out the test for Free Shipping:
    // disable only when entire cart is free shipping
//    if (zen_get_shipping_enabled($this->code)) {
      $this->enabled = ((MODULE_SHIPPING_UPS_STATUS == 'True') ? true : false);
//    }


First, edit the Free Shipping Options freeoptions shipping module:
/includes/modules/shipping/freeoptions.php

and comment out the test for Free Shipping and then test if the whole order would have been Free Shipping based on the Always Free Shipping setting and if so, then turn this on, otherwise turn this off:

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

// bof: allow 1 zone only for Always Free Shipping when US ONLY
// Only allow Free Shipping when whole cart is Always Free Shipping
  if (!IS_ADMIN_FLAG) {
    global $cart;
    $chk_weight = round($_SESSION['cart']->show_weight(),9);
    if ($chk_weight == 0) {
      $this->enabled = true;
    } else {
      $this->enabled = false;
    }
  }
// bof: allow 1 zone only for Always Free Shipping when US ONLY

      if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_FREEOPTIONS_ZONE > 0) ) {


Next, add the Zone Definition that you created for the United States to the Free Shipping Options freeoptions shipping module, so it is only available to the United States ... providing the whole cart is marked as Always Free Shipping ...

Nifty eh? :lamo:
28 Jul 2011, 13:38
#12
voltar avatar

voltar

New Zenner

Join Date:
Apr 2011
Posts:
80
Plugin Contributions:
0

Re: Shipping Module Programming Question about weight and free shipping

So far here is what I'm seeing. I've double checked everything and all appears to be in place. What have I missed?

For USA customers:
- add Free Shipping item to cart - Free Shipping and Free Shipping options both are displayed along with UPS and USPS. Additional Free Shipping items increase shipping charges for selections and Free Shipping remains an option. OK.

- add additional non-Free Shipping item to cart - Free Shipping disappears but the shipping charge displayed reflects the charge for the total cart including the Free Shipping weight for UPS and USPS. The displayed weight shown on screen is correct in that it shows only the non-Free Shipping item weight but not reflected in the calculation.

For Non-USA customers:
- add USA Free Shipping item to cart - shipping options and cost display correctly. Adding additional USA Free Shipping items to cart reflect properly adjusted charges. OK.

- add additional non-Free USA Shipping item to cart - shipping calculation breaks with no shipping options displayed.

Non Free Shipping items work correctly in all scenarios.

Thanks for the help. Any ideas?
28 Jul 2011, 14:04
#13
ajeh avatar

ajeh

Oba-san

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

Re: Shipping Module Programming Question about weight and free shipping

Make sure that you added the code to Free Shipping Options freeoptions and the Zone to Free Shipping Options freeoptions for the US and set the Total to >= 0 ...
28 Jul 2011, 14:40
#14
voltar avatar

voltar

New Zenner

Join Date:
Apr 2011
Posts:
80
Plugin Contributions:
0

Re: Shipping Module Programming Question about weight and free shipping

I double checked the code additions and everything is where it's suppose to be, seemingly. Free Shipping Options freeoptions is set with the USA zone the same as regular free shipping and the freeoptions Total is >= 0 with all of the other boxes blank? I am obviously missing something important. Is there a variable that I could check to see what's happening at some point? This seems really close to perfect.
28 Jul 2011, 15:01
#15
ajeh avatar

ajeh

Oba-san

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

Re: Shipping Module Programming Question about weight and free shipping

NOTE: you do not need the shipping module FREE SHIPPING! freeshipper ...

The Free Shipping Option freeoptions is customized with this code to manage orders that are Free Shipping ...

Compare the code in:
/includes/classes/shipping.php

to a clean copy of:
/includes/classes/shipping.php

and make sure you only have the small piece of code in post #11 ...
28 Jul 2011, 15:44
#16
voltar avatar

voltar

New Zenner

Join Date:
Apr 2011
Posts:
80
Plugin Contributions:
0

Re: Shipping Module Programming Question about weight and free shipping

I am very sorry but I can't seem to isolate my problem. I went back and unzipped a fresh copy from v1.3.9h and verified with Beyond Compare the shipping.php to only have the small piece of code as in #11. I also did the same for the freeoptions.php file and the UPS.php file and they also only contained the additional code. I was unable to compare the USPS.php files since I am running a later release of the module. I run a pretty generic store.

I have also removed the Free Shipping freeshipper option and that option no longer displays but am still seeing the same results. As soon as I add a non-Free Shipping item, the weight get added back to the calculation. Thank you so much for your guidance.
28 Jul 2011, 15:58
#17
ajeh avatar

ajeh

Oba-san

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

Re: Shipping Module Programming Question about weight and free shipping

Okay let's do this step by step and note I cleaned up a pinch of code in the shipping class and freeoptions ... with all changes in RED:

The only shipping modules installed are:
UPS
USPS
Free Shipping Options freeoptions

Free Shipping Options freeoptions has the Zone set for the US only ...

If using Sort Orders, you have used Sort Orders on all 3 of these modules ...

All Products have Product Weight and/or Attribute Weight ...

All Products to be shipped Free to the US are marked as:
Always Free Shipping: Yes, Always Free Shipping

Code changes from original code are:

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


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


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

// bof: allow 1 zone only for Always Free Shipping when US ONLY
// Only allow Free Shipping when whole cart is Always Free Shipping
  if (!IS_ADMIN_FLAG && $this->enabled) {
    global $cart;
    $chk_weight = round($_SESSION['cart']->show_weight(),9);
    if ($chk_weight == 0) {
      $this->enabled = true;
    } else {
      $this->enabled = false;
    }
  }
// bof: allow 1 zone only for Always Free Shipping when US ONLY


      if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_FREEOPTIONS_ZONE > 0) ) {


/includes/classes/shipping.php
  function calculate_boxes_weight_and_tare() {
    global $total_weight, $shipping_weight, $shipping_quoted, $shipping_num_boxes;

// bof: allow 1 zone only for Always Free Shipping US ONLY
// add back in the Always Free Shipping Weight for everyone
    global $cart;
          $total_weight += $_SESSION['cart']->free_shipping_weight;
// bof: allow 1 zone only for Always Free Shipping US ONLY


    if (is_array($this->modules)) {
28 Jul 2011, 16:42
#18
voltar avatar

voltar

New Zenner

Join Date:
Apr 2011
Posts:
80
Plugin Contributions:
0

Re: Shipping Module Programming Question about weight and free shipping

I meticulously followed each step and the results are the same. Once I add a non Free Shipping items the cost calculated goes up when increasing the Free Ship item quantity but the displayed weight remains the same.

I did note however that the Free Shipping Options freeoptions module indicator is yellow whereas the UPS and USPS are green. Is this normal or am I not setting it up properly thus causing my problem?
28 Jul 2011, 16:45
#19
ajeh avatar

ajeh

Oba-san

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

Re: Shipping Module Programming Question about weight and free shipping

It should be yellow as there is a Zone set on it ...

Have you an URL to your site that I can see this? :unsure:
28 Jul 2011, 16:52
#20
voltar avatar

voltar

New Zenner

Join Date:
Apr 2011
Posts:
80
Plugin Contributions:
0

Re: Shipping Module Programming Question about weight and free shipping

The site is www.OliveBranchSkinCare.com. The Airbrush Tattoo Ink products are all free shipping and the stencils are not. If you need admin access just let me know.