Shopping Cart Buttons

It's common practise on eCommerce websites to display information about the contents of the current cart. This article will explain how to code a "current cart".

Current Cart: Number Of Items In Cart

The following snippet of code displays the number of items in the current user's cart. The snippet checks to determine whether there are any items in the cart, if there are no items present in the cart, "No Items in Cart" will be displayed.

<p> <a href="/commerce/order/"> Cart ( <logic:if test="\Components\Commerce\Carts\Current::getCount()"> [? \Components\Commerce\Carts\Current::getCountProducts() ?] </logic:if> <logic:else>No Items in Cart</logic:else> ) </a> </p>

Current Cart: Current Order Total

The following snippet of code displays the total of the current user's cart. The snippet checks to determine whether there are any items in the cart, if there are no items present in the cart, "No Items in Cart" will be displayed.

<p> <a href="/commerce/order/"> Cart ( <logic:if test="\Components\Commerce\Carts\Current::getCount()"> [? \Components\Commerce\Products::renderPrice(\Components\Commerce\Carts\Current::getTotal(), 'strong') ?] </logic:if> <logic:else>No Items in Cart</logic:else> ) </a> </p>