Location: PHPKode > projects > Selling Made Simple E-commerce Solution > sms/app/vendors/smarty/sms_plugins/function.shopping_cart.php
<?php
/** SMS - Selling Made Simple
 * Copyright 2007 by Kevin Grandon (hide@address.com)
 * This project's homepage is: http://sellingmadesimple.org
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * BUT withOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
**/

function default_template_shopping_cart()
{
$template = '
<div class="cart">
	<table style="width:100%;">
		<tr>	
			<th> </th>
			<th>{lang}product{/lang}</th>
			<th>{lang}price-ea{/lang}</th>
			<th>{lang}qty{/lang}</th>
			<th>{lang}total{/lang}</th>
		</tr>
				
		{foreach from=$order_items item=product}			
			<tr>
				<td><a href="/cart/remove_product/{$product.id}" class="remove">x</a></td>
				<td><a href="{$product.link}">{$product.name}</a></td>
				<td>{$product.price}</td>
				<td>{$product.qty}</td>
				<td>{$product.line_total}</td>
			</tr>				
		{foreachelse}	
			<tr>
				<td colspan="5">{lang}no-cart-items{/lang}</td>
			</tr>
		{/foreach}				
				
		<tr class="cart_total">
			<td colspan="5">
				{lang}shipping{/lang}: {$shipping_total}<br />
				<strong>{lang}total{/lang}:</strong> {$order_total}
			</td>
		</tr>
	</table>
	<a class="checkout" href="{$checkout_link}">{lang}checkout{/lang}</a>
</div>
';		

return $template;
}


function smarty_function_shopping_cart($params, &$smarty)
{
	loadComponent('Smarty');
		$Smarty =& new SmartyComponent();
	
	loadComponent('OrderBase');
		$OrderBase =& new OrderBaseComponent();		
	
	loadComponent('CurrencyBase');
		$CurrencyBase =& new CurrencyBaseComponent();		
		
	global $order;		
	global $config;
	
	
	$order_items = array();
	if(!isset($order['OrderProduct']))
	{
		// Quit if we passed the param and the cart is empty
		if((!isset($params['showempty']))||($params['showempty'] == false))
			return;

		$order['Order']['total'] = 0;
		$order['OrderProduct'] = array();
	}
		
	foreach($order['OrderProduct'] AS $cart_item)
	{
		$content_id = $cart_item['content_id'];
		$order_items[$content_id] = array('id' => $cart_item['content_id'],
										  'link' => BASE . '/Product/' . $content_id . $config['URL_EXTENSION'],
										  'name' => $cart_item['name'],
										  'price' => $CurrencyBase->display_price($cart_item['price']),
										  'qty' => $cart_item['quantity'],
										  'url' => BASE . '/Product/' . $cart_item['content_id'] . $config['URL_EXTENSION'],										  
										  'line_total' => $CurrencyBase->display_price($cart_item['quantity']*$cart_item['price']));

	}	
	
	$assignments = array('checkout_link' => BASE . '/Page/checkout' . $config['URL_EXTENSION'],
						 'order_total' => $CurrencyBase->display_price($order['Order']['total']),
						 'shipping_total' => $CurrencyBase->display_price($order['Order']['shipping']),
						 'order_items' => $order_items,
						 'cart_link' => BASE . '/Page/cart-contents' . $config['URL_EXTENSION']
						 );								 

	$display_template = $Smarty->load_template($params,'shopping_cart');
	$Smarty->display($display_template,$assignments);
	
}

function smarty_help_function_shopping_cart() {
	?>
	<h3>What does this do?</h3>
	<p>Displays a more detailed version of the user's cart.</p>
	<h3>How do I use it?</h3>
	<p>Just insert the tag into your template/page like: <code>{shopping_cart}</code></p>
	<h3>What parameters does it take?</h3>
	<ul>
		<li><em>(template)</em> - Overrides the default template.</li>
		<li><em>(showempty)</em> - (true or false) If set to false does not display the cart if the user has not added any items.  Defaults to false.</li>		
	</ul>
	<?php
}

function smarty_about_function_shopping_cart() {
	?>
	<p>Author: Kevin Grandon&lt;hide@address.com&gt;</p>
	<p>Version: 0.1</p>
	<p>
	Change History:<br/>
	None
	</p>
	<?php
}
?>
Return current item: Selling Made Simple E-commerce Solution