Zen Cart Logo
Forums / All Other Contributions/Addons / Shoppingcart/Freeship in Header support

Shoppingcart/Freeship in Header support

Views: 19,391

Results 161 to 180 of 181
6 Mar 2013, 5:07 PM
#161
mvstudio avatar

mvstudio

Zen Follower

Join Date:
Apr 2008
Posts:
447
Plugin Contributions:
1

Shoppingcart/Freeship in Header support

Fabulous mode, but I have a situation, I don't use the ot_shipping to offer free shipping, instead we use the freeoptions for which we have 3 different clones depending on regional, national and international. How could I display the message Add $XXX to your order to qualify for Free Shipping! revealing the freeoptions instead? I tried changing MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING to MODULE_SHIPPING_FREEOPTIONS but doesn't work.

Thanks for the help!

6 Mar 2013, 7:42 PM
#162
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Shoppingcart/Freeship in Header support

The structure of the free shipping is odd, probably because the freeoptions code was added after the freeshipper and took over some of its function, but the underlying code was never reoptimized.
In Modules > Order Total > Shipping, this is the setting page you should have:

Shipping
This module is installed

true

Sort Order
Sort order of display.
[123] (whatever)

Allow Free Shipping
Do you want to allow free shipping?

( )true
(*)false

Free Shipping For Orders Over
Provide free shipping for orders over the set amount.
[50] (this number controls the freeship display calculations)Set the amount, and "false" here.

Then in Modules > Shipping > Free Shipping Options> Free Shipping Options

Enable Free Options Shipping
...
Do you want to offer per freeoptions rate shipping?

(*)True
( )False

Shipping Cost
The shipping cost will be $0.00
[0.00]

Handling Fee
Handling fee for this shipping method.
[0]

Total >=
Free Shipping when Total >=
[50] (this number controls the actual threshold) Messy, and it ought to be cleaned up for future versions of both Zen Cart and this mod.

7 Mar 2013, 3:25 PM
#163
mvstudio avatar

mvstudio

Zen Follower

Join Date:
Apr 2008
Posts:
447
Plugin Contributions:
1

Re: Shoppingcart/Freeship in Header support

Thank you for the quick reply!
I see how it works and how it doesn't work with the freeoptions module.
Maybe I would need a work around.

Here is the situation. We offer 3 different free shipping options, a regional for michigan only on orders over $45, a national for the entire US on orders over $85, and to Canada for orders over $125.

So what we did was clone the freeoptions module to offer and trigger the 3 different options.

Since using the freeoptions modules instead of the ot_shipping is out of the question, I'm thinking maybe adding the other amounts would work?...

Something like "Add $XXX to your order to qualify for Free Shipping in Michigan, add $XXX to for Free Continental USA or add $XXX for Free Shipping to Canada"

Now I'm trying to figure out how to code this.

Any ideas??

7 Mar 2013, 3:57 PM
#164
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Shoppingcart/Freeship in Header support

Since the freeoptions setting is what actually controls the threshold, it would be best to recode the alert to use that (and its clones in your case). I haven't examined it in depth to see how to do that, but it should be feasible. If you want to look into it, that would be great, as I don't have much spare time right now.

7 Mar 2013, 4:10 PM
#165
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Shoppingcart/Freeship in Header support

It appears that /includes/modules/shipping/freeoptions.php uses MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN to determine the minimum price for free shipping to be offered. Substituting that in tpl_cart_header.php here might do the job:```php

<?php $free_ship_on = MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING; if ($free_ship_on == 'false') { echo '<div id="cartFreeShip">'; $free_limit = MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER;//substitute MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN if ($cart_count) { ```
7 Mar 2013, 4:12 PM
#166
mvstudio avatar

mvstudio

Zen Follower

Join Date:
Apr 2008
Posts:
447
Plugin Contributions:
1

Re: Shoppingcart/Freeship in Header support

Easier than I thought, so I'm sharing in case someone else needs a similar workaround.

Just for informative purposes.
I needed to display 3 different free shipping parameters as we offer free shipping over $45 for Michigan orders, over $85 for Continental US orders and over $125 for Canada. To set up the whole scenario we cloned the freeoptions.php module which I'm not explaining here how to do. There is plenty of info on how to accomplish this throughout the forum. Next we installed the Modules>Order Total>Shipping as explained above and set it up to false with the lowest free shipping amount we offer which is $45.

On the tpl_cart_header.php find

<?php 
$free_ship_on = MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING;
if ($free_ship_on == 'false') {
  echo '<div id="cartFreeShip">';
  $free_limit = MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER;
  if ($cart_count) { 
   // $_SESSION['cart']->get_products(); 
    $cart_total = $_SESSION['cart']->show_total(); 
    if ($cart_total < $free_limit) { 
      $diff_to_free = ($free_limit - $cart_total); 
      echo CART_HEADER_DIFF_PRE . $currencies->format($diff_to_free) . CART_HEADER_DIFF_POST; 
    } else { 
      echo CART_HEADER_QUALIFIES; 
    } 
  } else { 
    echo CART_HEADER_FREE_LIMIT_PRE . $currencies->format($free_limit) . CART_HEADER_FREE_LIMIT_POST; 
  }
  echo '</div>';
} ?>

and replace for

<?php 
$free_ship_on = MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING;
if ($free_ship_on == 'false') {
  echo '<div id="cartFreeShip">';
  $free_limit = MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER;
  if ($cart_count) { 
   // $_SESSION['cart']->get_products(); 
    $cart_total = $_SESSION['cart']->show_total(); 
    if ($cart_total < $free_limit) { 
      $diff_to_free = ($free_limit - $cart_total); 
      echo CART_HEADER_DIFF_PRE . $currencies->format($diff_to_free) . CART_HEADER_DIFF_POST; 
      $diff_to_free = ($free_limit + '40.00' - $cart_total); 
      echo CART_HEADER_DIFF_PRE_CONT . $currencies->format($diff_to_free) . CART_HEADER_DIFF_POST_CONT; 
      $diff_to_free = ($free_limit + '80.00' - $cart_total); 
      echo CART_HEADER_DIFF_PRE_CANADA . $currencies->format($diff_to_free) . CART_HEADER_DIFF_POST_CANADA; 
    } else { 
      echo CART_HEADER_QUALIFIES; 
    } 
  } else { 
    echo CART_HEADER_FREE_LIMIT_PRE . $currencies->format($free_limit) . CART_HEADER_FREE_LIMIT_POST; 
  }
  echo '</div>';
} ?>

We've commented the

// $_SESSION['cart']->get_products(); 

as we don't want to display the entire list of products.

Next on cart_header_defines.php add the following
define ('CART_HEADER_DIFF_PRE_CONT',', ');
define ('CART_HEADER_DIFF_PRE_CANADA',' or ');
define ('CART_HEADER_DIFF_POST_CONT',' for Free Continental Shipping, ');
define ('CART_HEADER_DIFF_POST_CANADA',' for Free Shipping to Canada.');

Upload everything to the server.

The result is a message that looks like this for a shopping bag with $28
"Total: $28.00 (1 item)
Add $17.00 to qualify for Free Shipping in Michigan, $57.00 for Free Continental Shipping, or $97.00 for Free Shipping to Canada."

Hope this works for someone else.

7 Mar 2013, 4:20 PM
#167
mvstudio avatar

mvstudio

Zen Follower

Join Date:
Apr 2008
Posts:
447
Plugin Contributions:
1

Re: Shoppingcart/Freeship in Header support

Ah! We posted at the same time :)
Actually although your suggestion worked, it gives the wrong message when the cart has more than the minimum amount to trigger the first free shipping option.
It would need to trigger 3 different messages, one for "add $XXX for Michigan" until it reaches the michigan mark, another for when it passes the michigan mark "add $xxx for free continental shipping" until it reaches the continental mark and another for when it passes the continental mark "add $xxx for free shipping to canada" until it reaches the canada mark.

7 Mar 2013, 4:24 PM
#168
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Shoppingcart/Freeship in Header support

Just tested this and it does work, displaying and using the freeoptions setting for calculations.
So change this line in /includes/templates/your_template/templates/tpl_cart_header.php```php
$free_limit = MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER;

to```php
  $free_limit = MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN;

Presumably your freeoptions clones have modified versions of this constant, so you would use those and an expanded text string to output them all as you described.

7 Mar 2013, 4:32 PM
#169
mvstudio avatar

mvstudio

Zen Follower

Join Date:
Apr 2008
Posts:
447
Plugin Contributions:
1

Re: Shoppingcart/Freeship in Header support

Got it! It works the same either way.
Thank you so much!

7 Mar 2013, 4:38 PM
#170
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Shoppingcart/Freeship in Header support

Read through your post and it looks like you have the mechanics of this well in hand. Thanks for posting the full directions.

Your situation does get complicated, as you can't say simply "you qualify for free shipping" without knowing which zone your customer is in. You would have to do some more sorting and output something like "you qualify for free shipping in Michigan; add $17.00 to qualify for Free Continental Shipping, or $57.00 for Free Shipping to Canada." as the case may be.

7 Mar 2013, 4:52 PM
#171
mvstudio avatar

mvstudio

Zen Follower

Join Date:
Apr 2008
Posts:
447
Plugin Contributions:
1

Re: Shoppingcart/Freeship in Header support

Yes, it's going to get a little complicated, but if it helps others, that's all it matters.
I'll post the final once I know it works.
Thanks for the help! =o)

7 Mar 2013, 5:23 PM
#172
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Shoppingcart/Freeship in Header support

Assuming you have constants for freeoptions and its clones like
MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN
MODULE_SHIPPING_FREEOPTIONS2_TOTAL_MIN
MODULE_SHIPPING_FREEOPTIONS3_TOTAL_MIN
you could do something like ```php

<?php $free_ship_on = MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING; if ($free_ship_on == 'false') { echo '<div id="cartFreeShip">'; $free_limit = MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN; //mi $free_limit2 = MODULE_SHIPPING_FREEOPTIONS2_TOTAL_MIN; //cont $free_limit3 = MODULE_SHIPPING_FREEOPTIONS3_TOTAL_MIN; //canada $diff_to_free = ($free_limit - $cart_total); $diff_to_free2 = ($free_limit2 - $cart_total); $diff_to_free3 = ($free_limit3 - $cart_total); //if ($cart_count) { //hopefully this is not needed in order to evaluate $_SESSION['cart']->show_total() which can == 0 for this code // $_SESSION['cart']->get_products(); //this was leftover from old code and has no current function in any case, so just delete it $cart_total = $_SESSION['cart']->show_total(); if ($cart_total >= $free_limit3) { echo CART_HEADER_QUALIFIES; } elseif ($cart_total >= $free_limit2) { echo CART_HEADER_QUALIFIES_MI_CONT . $currencies->format($diff_to_free3) . CART_HEADER_DIFF_POST_CANADA; } elseif ($cart_total >= $free_limit) { echo CART_HEADER_QUALIFIES_MI . $currencies->format($diff_to_free2) . CART_HEADER_DIFF_POST_CONT . $currencies->format($diff_to_free3) . CART_HEADER_DIFF_POST_CANADA; } else { echo CART_HEADER_DIFF_PRE . $currencies->format($diff_to_free) . CART_HEADER_DIFF_POST . CART_HEADER_DIFF_PRE_CONT . $currencies->format($diff_to_free2) . CART_HEADER_DIFF_POST_CONT . CART_HEADER_DIFF_PRE_CANADA . $currencies->format($diff_to_free3) . CART_HEADER_DIFF_POST_CANADA; } //} else { //doesn't work for 3 zones // echo CART_HEADER_FREE_LIMIT_PRE . $currencies->format($free_limit) . CART_HEADER_FREE_LIMIT_POST; //} //if need to use $cart_count, expand the above like the previous else case substituting $free_limit/2/3 for $diff_to_free/2/3 echo '</div>'; } ?>
7 Mar 2013, 5:56 PM
#173
mvstudio avatar

mvstudio

Zen Follower

Join Date:
Apr 2008
Posts:
447
Plugin Contributions:
1

Re: Shoppingcart/Freeship in Header support

You're a genius!!!
Thank you!! It works perfectly!

7 Mar 2013, 6:16 PM
#174
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Shoppingcart/Freeship in Header support

Good to hear that. So the commented-out if() is not needed, I take it?

7 Mar 2013, 7:39 PM
#175
mvstudio avatar

mvstudio

Zen Follower

Join Date:
Apr 2008
Posts:
447
Plugin Contributions:
1

Re: Shoppingcart/Freeship in Header support

Correct. Not needed. It actually breaks the page.

In the spirit of sharing, I made some other changes that work for my case. I wanted so display Free Shipping Over $XXX when shopping cart is 0 instead of the whole message "add $xx for free shipping etc."

So I added a conditional if the cart is 0 which triggers a different message

 <?php 
$free_ship_on = MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING;
if ($free_ship_on == 'false') {
  echo '<div id="cartFreeShip">';
  $free_limit = MODULE_SHIPPING_FREEOPTIONS_MICHIGAN_TOTAL_MIN; //mi
  $free_limit2 = MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN; //continental us
  $free_limit3 = MODULE_SHIPPING_FREEOPTIONSINT_TOTAL_MIN; //canada
      $diff_to_free = ($free_limit - $cart_total); 
      $diff_to_free2 = ($free_limit2 - $cart_total); 
      $diff_to_free3 = ($free_limit3 - $cart_total); 
  //if ($cart_count) { //hopefully this is not needed in order to evaluate $_SESSION['cart']->show_total() which can == 0 for this code
   // $_SESSION['cart']->get_products(); //this was leftover from old code and has no current function in any case, so just delete it
    $cart_total = $_SESSION['cart']->show_total(); 
    if ($cart_total >= $free_limit3) { 
      echo CART_HEADER_QUALIFIES_CANADA;
    } elseif ($cart_total >= $free_limit2) {
      echo CART_HEADER_QUALIFIES_CONT . CART_HEADER_DIFF_PRE . $currencies->format($diff_to_free3) . CART_HEADER_DIFF_POST_CANADA;
    } elseif ($cart_total >= $free_limit) {
      echo CART_HEADER_QUALIFIES . CART_HEADER_DIFF_PRE . $currencies->format($diff_to_free2) . CART_HEADER_DIFF_POST_CONT . $currencies->format($diff_to_free3) . CART_HEADER_DIFF_POST_CANADA;
    } elseif ($cart_total == '0') { 
      echo CART_HEADER;
	} else {
      echo CART_HEADER_DIFF_PRE . $currencies->format($diff_to_free) . CART_HEADER_DIFF_POST . CART_HEADER_DIFF_PRE_CONT . $currencies->format($diff_to_free2) . CART_HEADER_DIFF_POST_CONT . CART_HEADER_DIFF_PRE_CANADA . $currencies->format($diff_to_free3) . CART_HEADER_DIFF_POST_CANADA;     }

  //} else { //doesn't work for 3 zones
  //  echo CART_HEADER_FREE_LIMIT_PRE . $currencies->format($free_limit) . CART_HEADER_FREE_LIMIT_POST; 
  //} //if need to use $cart_count, expand the above like the previous else case substituting $free_limit/2/3 for $diff_to_free/2/3
  echo '</div>';
} ?>

The define CART_HEADER can be any shorter message. In my case it just displays "Free Continental Shipping over $85"

22 Jan 2014, 7:47 PM
#176
willy12 avatar

willy12

New Zenner

Join Date:
Nov 2010
Posts:
64
Plugin Contributions:
0

Re: Shoppingcart/Freeship in Header support

Hello everyone,

Has anyone suggestions on how to exclude certain category id's and product id's from being calculated in the free shipping header?

  // bof This is to remove Category from free shipping always
  if (!IS_ADMIN_FLAG) {
    global $cart;
    $chk_cat = 0;
    $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id', '9');
    $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id', '21');
    if ($chk_cat > 0) {
      $this->enabled = false;
    }
  }
  // eof This is to remove Category from free shipping always

The above code works in freeoptions.php but not in the freeship header.

Thanks

22 Jan 2014, 10:00 PM
#177
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Shoppingcart/Freeship in Header support

That code appears to be part of a class file, and will not work as is outside of the class.
$this->enabled = false;
is not applicable or meaningful in the shoppingcart/freeship files. You would have to rework the action based on the test and the new file context.

15 Feb 2014, 10:35 AM
#178
limey avatar

limey

New Zenner

Join Date:
Dec 2005
Posts:
44
Plugin Contributions:
0

Re: Shoppingcart/Freeship in Header support

I'd like to hide the header cart unless there is something in the cart. Any ideas on the code for that? Thank you in advance. Limey

16 Feb 2014, 5:52 AM
#179
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Shoppingcart/Freeship in Header support

That is pretty easy. Find this at the top of tpl_cart_header.php: ```php
$cart_count = $_SESSION['cart']->count_contents();
?>

<div id="cartHeader"> ``` and change to ```php $cart_count = $_SESSION['cart']->count_contents(); if ($cart_count) { //only show if something in cart ?> <div id="cartHeader"> ``` At the bottom of the file, find this: ```php } ?> </div> ``` and change to ```php } ?> </div> <?php } // /only show ?> ```

If you want the wrapper div to remain as a placeholder for the layout, move the test inside the div, like this ```php
$cart_count = $_SESSION['cart']->count_contents();
?>

<div id="cartHeader"> <?php if ($cart_count) { //only show if something in cart ?>

//body of file

}
} // /only show
?>

</div> ```
16 Feb 2014, 10:25 PM
#180
limey avatar

limey

New Zenner

Join Date:
Dec 2005
Posts:
44
Plugin Contributions:
0

Re: Shoppingcart/Freeship in Header support

Thanks Glenn - that works a treat. Appreciate appreciate.

Limey