create smarty attribute for cart
This commit is contained in:
@@ -37,6 +37,7 @@ use Thelia\Model\Product;
|
||||
use Thelia\Model\ProductQuery;
|
||||
use Thelia\Model\Tools\ModelCriteriaTools;
|
||||
use Thelia\Tools\DateTimeFormat;
|
||||
use Thelia\Cart\CartTrait;
|
||||
|
||||
/**
|
||||
* Implementation of data access to main Thelia objects (users, cart, etc.)
|
||||
@@ -46,6 +47,8 @@ use Thelia\Tools\DateTimeFormat;
|
||||
*/
|
||||
class DataAccessFunctions extends AbstractSmartyPlugin
|
||||
{
|
||||
use CartTrait;
|
||||
|
||||
private $securityContext;
|
||||
protected $parserContext;
|
||||
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
|
||||
*
|
||||
@@ -263,6 +280,7 @@ class DataAccessFunctions extends AbstractSmartyPlugin
|
||||
new SmartyPluginDescriptor('function', 'folder', $this, 'folderDataAccess'),
|
||||
new SmartyPluginDescriptor('function', 'currency', $this, 'currencyDataAccess'),
|
||||
new SmartyPluginDescriptor('function', 'lang', $this, 'langDataAccess'),
|
||||
new SmartyPluginDescriptor('function', 'cart', $this, 'cartDataAccess'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ URL: http://www.thelia.net
|
||||
{/elseloop}
|
||||
<li class="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>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
Reference in New Issue
Block a user