create smarty attribute for cart

This commit is contained in:
Manuel Raynaud
2013-09-13 15:17:43 +02:00
parent ea1ee4932d
commit 50a5fd166b
3 changed files with 32 additions and 1 deletions

View File

@@ -37,6 +37,7 @@ use Thelia\Model\Product;
use Thelia\Model\ProductQuery; use Thelia\Model\ProductQuery;
use Thelia\Model\Tools\ModelCriteriaTools; use Thelia\Model\Tools\ModelCriteriaTools;
use Thelia\Tools\DateTimeFormat; use Thelia\Tools\DateTimeFormat;
use Thelia\Cart\CartTrait;
/** /**
* Implementation of data access to main Thelia objects (users, cart, etc.) * Implementation of data access to main Thelia objects (users, cart, etc.)
@@ -46,6 +47,8 @@ use Thelia\Tools\DateTimeFormat;
*/ */
class DataAccessFunctions extends AbstractSmartyPlugin class DataAccessFunctions extends AbstractSmartyPlugin
{ {
use CartTrait;
private $securityContext; private $securityContext;
protected $parserContext; protected $parserContext;
protected $request; protected $request;
@@ -151,6 +154,20 @@ class DataAccessFunctions extends AbstractSmartyPlugin
} }
} }
public function cartDataAccess($params, $smarty)
{
$cart = $this->getCart($this->request);
$result = "";
switch($params["attr"]) {
case "count_item":
$result = $cart->getCartItems()->count();
break;
}
return $result;
}
/** /**
* Lang global data * Lang global data
* *
@@ -263,6 +280,7 @@ class DataAccessFunctions extends AbstractSmartyPlugin
new SmartyPluginDescriptor('function', 'folder', $this, 'folderDataAccess'), new SmartyPluginDescriptor('function', 'folder', $this, 'folderDataAccess'),
new SmartyPluginDescriptor('function', 'currency', $this, 'currencyDataAccess'), new SmartyPluginDescriptor('function', 'currency', $this, 'currencyDataAccess'),
new SmartyPluginDescriptor('function', 'lang', $this, 'langDataAccess'), new SmartyPluginDescriptor('function', 'lang', $this, 'langDataAccess'),
new SmartyPluginDescriptor('function', 'cart', $this, 'cartDataAccess'),
); );
} }
} }

View File

@@ -76,4 +76,17 @@ class Cart extends BaseCart
{ {
} }
public function getTotalAmount()
{
$total = 0;
foreach($this->getCartItems() as $cartItem) {
$total += $cartItem->getPrice()-$cartItem->getDiscount();
}
$total -= $this->getDiscount();
return $total;
}
} }

View File

@@ -95,7 +95,7 @@ URL: http://www.thelia.net
{/elseloop} {/elseloop}
<li class="dropdown"> <li class="dropdown">
<a href="cart.html" class="dropdown-toggle cart" data-toggle="dropdown"> <a href="cart.html" class="dropdown-toggle cart" data-toggle="dropdown">
Cart <span class="badge">2</span> Cart <span class="badge">{cart attr="count_item"}</span>
</a> </a>
</li> </li>
</ul> </ul>