Post by ogomo » Sat Mar 24, 2012 12:14 am

Hi,
I am using OC 1.4.9.4, and I would like to add a notice on the cart page (catalog/view/theme/mytheme/template/checkout/cart.tpl) that displays one of two notices to a user depending on the sub-total in their shopping cart.
I offer free shipping on orders with sub-totals over $50 (i.e. tax is not taken into consideration for free shipping calculation). So when a customer's sub-total is $50 or more, I want a notice to say "Congratulations, your order qualifies for free shipping!". When the sub-total is less than $50, I want the notice to say "You are only $(50 - sub-total amount) away from receiving free shipping!".

In the cart.tpl file, I included the following code as a new row in the table after the <?php foreach ($totals as $total) block.

Code: Select all

<?php foreach ($totals as $total) { ?>
          <tr>
            <td align="right"><b><?php echo $total['title']; ?></b></td>
            <td align="right"><?php echo $total['text']; ?></td>
		  </tr>
       <?php } ?>
                    <tr>            
			<td colspan="2" align="right">
				<?php 
					$disp_tot=$total['text'];
					$freeship="50";
					$is_freeship=$freeship-$disp_tot;
					if ($is_freeship<="0") {
						echo 'Congratulations, your order qualifies for free shipping!';
					} else {
						echo 'You are only $';
						echo "$is_freeship";
						echo ' away from receiving free shipping!';
						}		
				?>
			</td>
		  </tr>
			</table>
The result doesn't exactly work as I want it to. For orders under $50 (lets say $45), the code returns the following:
You are only $50 away from receiving free shipping!
I'd like it to do the math, and display "You are only $5 away from receiving free shipping".
Likewise, for orders over $50 (lets say $100), the code returns the same message (obviously the math and/or the "if" statement isn't working correctly):
You are only $50 away from receiving free shipping!
It doesn't display the "Congratulations" message as I want it to.
Also, the $45, and $100 in the above examples are the totals (including sales tax), not sub-totals. For an order that has a sub-total of $49, and roughly $3 in taxes, the $52 total will incorrectly display the congratulations message.

Any help would be greatly appreciated!
Thanks in advance.

New member

Posts

Joined
Thu Aug 04, 2011 1:35 am

Post by Avvici » Sat Mar 24, 2012 1:27 am

No, if you want a real "notice" then you will need to use the Ajax already written for you with the Ajax Cart. Otherwise your customers will need to refresh their browser to see any kind of notice. That defeats the purpose. :)

User avatar
Expert Member

Posts

Joined
Tue Apr 05, 2011 12:09 pm
Location - Asheville, NC

Post by ogomo » Sat Mar 24, 2012 2:15 am

UPDATE:
I think I figured out the error. In between <?php } ?> and </table>, I put the following:

Code: Select all

<tr>            
			<td colspan="2" align="right">
				<?php 
					$disp_tot=$this->cart->getSubTotal();
					$freeship="50";
					$is_freeship=$freeship-$disp_tot;
					if ($is_freeship<="0") {
						echo 'Congratulations, your order qualifies for free shipping!';
					} else {
						echo 'You are only $';
						echo "$is_freeship";
						echo ' away from receiving free shipping!';
						}		
				?>
			</td>
		  </tr>
This accurately calculates and displays the remaining amount to reach $50, or displays the Congratulations message depending on the sub-total amount.

New member

Posts

Joined
Thu Aug 04, 2011 1:35 am

Post by ogomo » Sat Mar 24, 2012 3:18 am

avvici wrote:No, if you want a real "notice" then you will need to use the Ajax already written for you with the Ajax Cart. Otherwise your customers will need to refresh their browser to see any kind of notice. That defeats the purpose. :)
I'm not sure what you mean by this. If you go to http://ogomo.com, and add any product to the shopping cart. When you view the cart page, you will see the notice I was talking about, right below the total. Change the quantity so that the sub-total is greater than $50, and the notice will change.
Is there something technically wrong with the way this was done? I am unfamiliar with Ajax, so I really don't know exactly what you meant by users will have to refresh their browser...

New member

Posts

Joined
Thu Aug 04, 2011 1:35 am
Who is online

Users browsing this forum: Baidu [Spider] and 69 guests