Zen Cart Logo
If this is your first visit, check our documentation. To post, register or login.
Forums / Customizing the Look of Your Shop / Templates, Stylesheets, Page Layout / Visually Highlight/Flag "Always Free Shipping" products in the shopping cart

Visually Highlight/Flag "Always Free Shipping" products in the shopping cart

Started by divavocals on 17 Jun 2014, 2:20 PM · Views: 1,937

Results 1 to 14 of 14
17 Jun 2014, 2:20 PM
#1
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Post #1 by divavocals

I have my settings so that the free shipping image appears on product info pages for products that are configured to have "always free shipping". And that's perfect.. Works as expected..

Here's the what I'm trying to do however...

The "always free shipping" only applies to certain products. UPS is the primary shipping method for anything not specifically set to "always free shipping".

How can I visually flag/mark the "always free shipping" products in the shopping cart/checkout pages so that it's CLEAR that the calculated shipping costs will apply to all other items in the shopping cart and NOT the items flagged "always free shipping". Ideally what I would like to do is to add an asterisk "*****" next to each one of the "always free shipping" products and have some text below the products list that explains what the asterisk means.

Any thoughts??

My Site - Zen Cart & WordPress integration specialist
I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.

17 Jun 2014, 3:43 PM
#2
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,833
Plugin Contributions:
29

Post #2 by balihr

If I'm understanding it correctly, you just want to check if cart contains any products that are marked as "always free shipping" and add a disclaimer if so - correct?

My site - Pro ZC Help
My portfolio | My plugins

17 Jun 2014, 4:59 PM
#3
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Post #3 by divavocals

balihr:

If I'm understanding it correctly, you just want to check if cart contains any products that are marked as "always free shipping" and add a disclaimer if so - correct?

EXACTLY! and WHY you may be asking?? I don't want customers choosing UPS Next Day and expect that the entire order will be shipping that way.. In this particular case, the "always free shipping" items may in fact be shipped separately using a different carrier altogether (USPS Priority most likely).. We will include text in the order confirmation email, shipping policy and the product description for clarity.. We MAY use product attributes to allow customers to select a shipping "upgrade" for these items if they wish to pay the additional cost for expedited shipping.

The disclaimer is a way of making sure that if the customer somehow misses the explanation in the shipping policy or the blurb in the product description which tells them this, they will know FOR SURE when they check out..

My Site - Zen Cart & WordPress integration specialist
I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.

17 Jun 2014, 5:12 PM
#4
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,833
Plugin Contributions:
29

Post #4 by balihr

DivaVocals:

EXACTLY! and WHY you may be asking??

Well, honestly, I don't care. :P

includes/modules/pages/shopping_cart/header_php.php

Around line 59 find:

$flagAnyOutOfStock = false;

and add after:

// BOF Free Shipping Flag 1/3
$flagAnyFreeShipping = false;
// EOF Free Shipping Flag 1/3

Around line 130 find:

if (STOCK_CHECK == 'true') {
    $flagStockCheck = zen_check_stock($products[$i]['id'], $products[$i]['quantity']);
    if ($flagStockCheck == true) {
      $flagAnyOutOfStock = true;
    }
  }

and add after:

// BOF Free Shipping Flag 2/3
  $flagFreeShipping = zen_get_product_is_always_free_shipping($products[$i]['id']) == true ? '*' : '';
  if(zen_not_null($flagFreeShipping)) $flagAnyFreeShipping = true;
  // EOF Free Shipping Flag 2/3

Around line 161 find:

'flagShowFixedQuantity'=>$showFixedQuantity,

and add after:

// BOF Free Shipping Flag 3/3
'flagFreeShipping'=>$flagFreeShipping,
// EOF Free Shipping Flag 3/3

Next, includes/templates/YOUR_TEMPLATE/templates/tpl_shopping_cart_default.php
Find:

<a href="<?php echo $product['linkProductsName']; ?>"><span id="cartImage" class="back"><?php echo $product['productsImage']; ?></span><span id="cartProdTitle"><?php echo $product['productsName'] . '<span class="alert bold">' . $product['flagStockCheck'] . '</span>'; ?></span></a>

and replace with:

<a href="<?php echo $product['linkProductsName']; ?>"><span id="cartImage" class="back"><?php echo $product['productsImage']; ?></span><span id="cartProdTitle"><?php echo $product['productsName'] . '<span class="alert bold">' . $product['flagFreeShipping'] . '</span>' . '<span class="alert bold">' . $product['flagStockCheck'] . '</span>'; ?></span></a>

Find:

<!--bof shopping cart buttons-->

and add before:

<?php if($flagAnyFreeShipping) echo '<div id="freeShippingDisclaimer">some free shipping disclaimer here</div>'; ?>

If you want some info on the checkout pages, I'd probably add a parameter in $_SESSION (set it includes/modules/pages/shopping_cart/header.php) and then just set an if-else in the checkout pages...

My site - Pro ZC Help
My portfolio | My plugins

17 Jun 2014, 5:30 PM
#5
lhungil avatar

lhungil

Totally Zenned

Join Date:
Feb 2012
Location:
mostly harmless
Posts:
1,816
Plugin Contributions:
4

Post #5 by lhungil

Or one could just query the shopping cart directly. As usual, many different ways to get the same information :-)

// Check against the database directly using the shopping cart
$cart_includes_free_shipping_product = $_SESSION['cart']->in_cart_check('product_is_always_free_shipping','1');

// Calculate totals and return number of items in the shopping cart w/ free shipping
$cart_includes_free_shipping_product  = (count($_SESSION['cart']->free_shipping_items()) > 0);

The glass is not half full. The glass is not half empty. The glass is simply too big!
Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
Zen Cart related projects maintained by lhûngîl : Plugin / Module Tracker

17 Jun 2014, 5:43 PM
#6
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,833
Plugin Contributions:
29

Post #6 by balihr

lhungil:

Or one could just query the shopping cart directly. As usual, many different ways to get the same information :-)

:blink:

I was never really a fan of simple. If there's a complicated solution, I'll be the first to take it. :D I mean, why use "1+1" when you can use " (sin(45)^2)((4π) / π)" and get the same result... Now, if you'll excuse me, I'll be in the basement banging my head against the wall...

My site - Pro ZC Help
My portfolio | My plugins

17 Jun 2014, 5:53 PM
#7
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Post #7 by divavocals

lhungil:

Or one could just query the shopping cart directly. As usual, many different ways to get the same information :-)

// Check against the database directly using the shopping cart
$cart_includes_free_shipping_product = $_SESSION['cart']->in_cart_check('product_is_always_free_shipping','1');

// Calculate totals and return number of items in the shopping cart w/ free shipping
$cart_includes_free_shipping_product = (count($_SESSION['cart']->free_shipping_items()) > 0);


> **balihr:**
>
> :blink:
> 
> I was never really a fan of simple. If there's a complicated solution, I'll be the first to take it. :D I mean, why use "1+1" when you can use " (sin(45)^2)((4π) / π)" and get the same result... Now, if you'll excuse me, I'll be in the basement banging my head against the wall...

You guys are funny!!!:laugh:

So lhungil if I understand this correctly, I could use either of these snippets to determine if "always free shipping" products are in the cart.. could I add a conditional that say "if this is true, then display this text"?? Something like this:

// Check against the database directly using the shopping cart

<?php if $cart_includes_free_shipping_product = $_SESSION['cart']->in_cart_check('product_is_always_free_shipping','1'); echo '<div id="freeShippingDisclaimer">some free shipping disclaimer here</div>'; ?>

(please say I guessed this correctly??![](http://www.zen-cart.com/images/smilies/laugh.gif))

My Site - Zen Cart & WordPress integration specialist
I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.

17 Jun 2014, 7:50 PM
#8
lhungil avatar

lhungil

Totally Zenned

Join Date:
Feb 2012
Location:
mostly harmless
Posts:
1,816
Plugin Contributions:
4

Post #8 by lhungil

balihr:

I was never really a fan of simple. If there's a complicated solution, I'll be the first to take it. :D I mean, why use "1+1" when you can use " (sin(45)^2)((4π) / π)" and get the same result... Now, if you'll excuse me, I'll be in the basement banging my head against the wall...
May I interest you in some MIPS assembly, LaTex, LISP, or Java bytecode? In the case of the last two, I'll even throw in some bonus code which rewrites itself while executing!

Coincidentally, I'm planning to use more bitwise arithmetic in some of my code. Why should I use separate options with "true / false" (or enable / disable) when a nice bitmask stored in a short unsigned integer (or byte) could be used?

DivaVocals:

... if I understand this correctly, I could use either of these snippets to determine if "always free shipping" products are in the cart.. could I add a conditional that say "if this is true, then display this text"?? ...
If all you want is to display a notice / link on the page(s) when "always free shipping" products are in the cart, yes. I would use the first snippet and separate out the code (header and template).

Perhaps even using an observer to listen for those pages (NOTIFY_HEADER_END_SHOPPING_CART, NOTIFY_HEADER_END_CHECKOUT_SHIPPING, NOTIFY_HEADER_END_CHECKOUT_PAYMENT, NOTIFY_HEADER_END_CHECKOUT_CONFIRMATION)...

Sadly the popup_shipping_estimator does not include a notify in header_php.php so would need to be directly added to the end of the file...

$cart_includes_free_shipping_product = false;
if(array_key_exists('cart', $_SESSION)) {
	$cart_includes_free_shipping_product = $_SESSION['cart']->in_cart_check('product_is_always_free_shipping','1');
}

But if you want an indicator on EACH product listed in the shopping cart, you'll have to use something like balihr's example to add the flag to the productsArray (so it is accessible for use when listing the shopping cart contents).

The glass is not half full. The glass is not half empty. The glass is simply too big!
Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
Zen Cart related projects maintained by lhûngîl : Plugin / Module Tracker

17 Jun 2014, 8:28 PM
#9
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Post #9 by divavocals

lhungil:

If all you want is to display a notice / link on the page(s) when "always free shipping" products are in the cart, yes. I would use the first snippet and separate out the code (header and template).:shocking: HUH?? :laugh:

lhungil:

Perhaps even using an observer to listen for those pages (NOTIFY_HEADER_END_SHOPPING_CART, NOTIFY_HEADER_END_CHECKOUT_SHIPPING, NOTIFY_HEADER_END_CHECKOUT_PAYMENT, NOTIFY_HEADER_END_CHECKOUT_CONFIRMATION)...

Sadly the popup_shipping_estimator does not include a notify in header_php.php so would need to be directly added to the end of the file...

lhungil:

$cart_includes_free_shipping_product = false;
if(array_key_exists('cart', $_SESSION)) {
$cart_includes_free_shipping_product = $_SESSION['cart']->in_cart_check('product_is_always_free_shipping','1');
}


Although I don't use the popup estimator.. I have always thought it was better to show the shipping estimator one the page versus some popup window.. So I set my settings accordingly..

> **lhungil:**
>
> But if you want an indicator on EACH product listed in the shopping cart, you'll have to use something like balihr's example to add the flag to the productsArray (so it is accessible for use when listing the shopping cart contents).I do in fact want an indicator next to each "always free shipping" product.. I might mess around and see if I can make myself a combo platter here.. :laugh:

My Site - Zen Cart & WordPress integration specialist
I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.

17 Jun 2014, 9:36 PM
#10
lhungil avatar

lhungil

Totally Zenned

Join Date:
Feb 2012
Location:
mostly harmless
Posts:
1,816
Plugin Contributions:
4

Post #10 by lhungil

... separate out the code (header and template).
:laugh: Code doing processing in an observer (or header files). Code displaying stuff (HTML / CSS) in the template files.

I do in fact want an indicator next to each "always free shipping" product [in the shopping cart and checkout].. I might mess around and see if I can make myself a combo platter here.. :laugh:
Sounds like fun! I'd probably do something like the following (untested):

Create "/includes/classes/observers/freeShippingObserver.php"

<?php
class freeShippingObserver extends base {

	protected $logfile;

	function __construct() {
		$this->attach($this, array(
			'NOTIFY_HEADER_END_SHOPPING_CART',
			'NOTIFY_HEADER_END_CHECKOUT_SHIPPING',
			'NOTIFY_HEADER_END_CHECKOUT_PAYMENT',
			'NOTIFY_HEADER_END_CHECKOUT_CONFIRMATION'
		));
	}

	function update(&$class, $eventID, $paramsArray = array()) {
		global $cart_includes_free_shipping_product;

		$cart_includes_free_shipping_product = false;
		if(array_key_exists('cart', $_SESSION)) {
			$cart_includes_free_shipping_product = $_SESSION['cart']->in_cart_check('product_is_always_free_shipping','1');

			global $products;
			$n=sizeof($products);
			if($n > 0) {
				switch($eventID) {
					case 'NOTIFY_HEADER_END_SHOPPING_CART':
						global $productArray;
						for ($i=0; $i<$n; $i++) {
							$productArray[$i]['product_is_always_free_shipping'] = $products[$i]['product_is_always_free_shipping'];
						}
						break;
					case 'NOTIFY_HEADER_END_CHECKOUT_CONFIRMATION':
						global $order;
						for ($i=0; $i<$n; $i++) {
							$order->products[$i]['product_is_always_free_shipping'] = $products[$i]['product_is_always_free_shipping'];
						}
					default:
				}
			}
		}
	}
}

Create "/includes/auto_loaders/config.freeShippingObserver.php"

<?php
if (!defined('IS_ADMIN_FLAG')) {
	die('Illegal Access');
}

$autoLoadConfig[10][] = array(
	'autoType'=>'class',
	'loadFile'=>'observers/freeShippingObserver.php'
);
$autoLoadConfig[200][] = array(
	'autoType'=>'classInstantiate',
	'className'=>'freeShippingObserver',
	'objectName'=>'freeShippingObserver'
);

Then in the templates for those four pages one can look use:

if($cart_includes_free_shipping_product) { // Do something }

In the shopping cart template (inside the foreach starting at line 63) one can use:

if($product['product_is_always_free_shipping'] == '1') { // Do something }

In the checkout_confirmation template one can use:

if($order->products[$i]['product_is_always_free_shipping'] == '1') { // Do something }

The glass is not half full. The glass is not half empty. The glass is simply too big!
Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
Zen Cart related projects maintained by lhûngîl : Plugin / Module Tracker

17 Jun 2014, 11:22 PM
#11
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,833
Plugin Contributions:
29

Post #11 by balihr

LOOOL, lhungil, talk about a simple solution... Now I wish I had a time machine and go just a few hours back to stop me from hitting my head... So, what do you do when you're not browsing the forums, teach Rocket Science over at MIT? :D

Although this is a brilliant solution (as most coming from you are), isn't it a bit of an overkill for the purpose? Personally, I'd use your first solution with in_cart_check and just put the results (conditional, of course) into $_SESSION for it to be used on any other inner page...

I might be missing something obvious here, but still - IMHO, a much simpler approach, and (possibly more important) understandable by most mortals, not just you MIT gals... :D

My site - Pro ZC Help
My portfolio | My plugins

18 Jun 2014, 12:07 AM
#12
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Post #12 by divavocals

balihr:

LOOOL, lhungil, talk about a simple solution... Now I wish I had a time machine and go just a few hours back to stop me from hitting my head... So, what do you do when you're not browsing the forums, teach Rocket Science over at MIT? :D

Although this is a brilliant solution (as most coming from you are), isn't it a bit of an overkill for the purpose? Personally, I'd use your first solution with in_cart_check and just put the results (conditional, of course) into $_SESSION for it to be used on any other inner page...

I might be missing something obvious here, but still - IMHO, a much simpler approach, and (possibly more important) understandable by most mortals, not just you MIT gals... :D
:laugh:

I have to give it to him.. He's brilliant isn't he!!!??? He and lat9 are soooooooo dagone smart.. (and you ain't no slouch either mister..:smile:)

But I keep telling him that I am not a developer.. I just play one on TV! :laugh:

My Site - Zen Cart & WordPress integration specialist
I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.

18 Jun 2014, 12:35 AM
#13
lhungil avatar

lhungil

Totally Zenned

Join Date:
Feb 2012
Location:
mostly harmless
Posts:
1,816
Plugin Contributions:
4

Post #13 by lhungil

balihr:

... isn't it a bit of an overkill ... I might be missing something obvious here, but still - IMHO, a much simpler approach, and (possibly more important) understandable by most mortals...
LOL, I definately have been enjoying reading your posts as of late. The humour (and possibly sarcasm) lately has been a very welcome beathe of fresh air.

As for my reasons... I have an aversion to modifying core files... Mostly because I spent WAY too much time merging during my last few ZC upgrades...

And since Zen Cart has an existing design pattern for just such a purpose, I figured "Why not"?

The glass is not half full. The glass is not half empty. The glass is simply too big!
Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
Zen Cart related projects maintained by lhûngîl : Plugin / Module Tracker

18 Jun 2014, 7:22 AM
#14
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Post #14 by divavocals

balihr:

LOOOL, lhungil, talk about a simple solution... Now I wish I had a time machine and go just a few hours back to stop me from hitting my head... So, what do you do when you're not browsing the forums, teach Rocket Science over at MIT? :D

Although this is a brilliant solution (as most coming from you are), isn't it a bit of an overkill for the purpose? Personally, I'd use your first solution with in_cart_check and just put the results (conditional, of course) into $_SESSION for it to be used on any other inner page...

I might be missing something obvious here, but still - IMHO, a much simpler approach, and (possibly more important) understandable by most mortals, not just you MIT gals... :D
I am sadly gonna have to agree and admit defeat.. Perhaps over the weekend, I'll spend some time trying to see if I can interpret lhungil's solution, but it's WAAAAY over my head to "figure out" on my own.... Your solution worked, and for now that's what I'm gonna go with 'cause I've got one other issue with this site launch to contend with that's giving me fits.. All my free shipping needs are firing on all cylinders now..

lhungil:

:laugh: Code doing processing in an observer (or header files). Code displaying stuff (HTML / CSS) in the template files.

Sounds like fun! I'd probably do something like the following (untested):

Create "/includes/classes/observers/freeShippingObserver.php"

<?php class freeShippingObserver extends base { protected $logfile; function __construct() { $this->attach($this, array( 'NOTIFY_HEADER_END_SHOPPING_CART', 'NOTIFY_HEADER_END_CHECKOUT_SHIPPING', 'NOTIFY_HEADER_END_CHECKOUT_PAYMENT', 'NOTIFY_HEADER_END_CHECKOUT_CONFIRMATION' )); } function update(&$class, $eventID, $paramsArray = array()) { global $cart_includes_free_shipping_product; $cart_includes_free_shipping_product = false; if(array_key_exists('cart', $_SESSION)) { $cart_includes_free_shipping_product = $_SESSION['cart']->in_cart_check('product_is_always_free_shipping','1'); global $products; $n=sizeof($products); if($n > 0) { switch($eventID) { case 'NOTIFY_HEADER_END_SHOPPING_CART': global $productArray; for ($i=0; $i<$n; $i++) { $productArray[$i]['product_is_always_free_shipping'] = $products[$i]['product_is_always_free_shipping']; } break; case 'NOTIFY_HEADER_END_CHECKOUT_CONFIRMATION': global $order; for ($i=0; $i<$n; $i++) { $order->products[$i]['product_is_always_free_shipping'] = $products[$i]['product_is_always_free_shipping']; } default: } } } } } ``` > > Create "/includes/auto_loaders/config.freeShippingObserver.php" > ``` <?php if (!defined('IS_ADMIN_FLAG')) { die('Illegal Access'); } $autoLoadConfig[10][] = array( 'autoType'=>'class', 'loadFile'=>'observers/freeShippingObserver.php' ); $autoLoadConfig[200][] = array( 'autoType'=>'classInstantiate', 'className'=>'freeShippingObserver', 'objectName'=>'freeShippingObserver' ); ``` > > Then in the templates for those four pages one can look use: > ``` if($cart_includes_free_shipping_product) { // Do something } ``` > > In the shopping cart template (inside the foreach starting at line 63) one can use: > ``` if($product['product_is_always_free_shipping'] == '1') { // Do something } ``` > > In the checkout_confirmation template one can use: > ``` if($order->products[$i]['product_is_always_free_shipping'] == '1') { // Do something } ```

My Site - Zen Cart & WordPress integration specialist
I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.