function basic_cart_get_total_price in Basic cart 7.3
Same name and namespace in other branches
- 7.2 basic_cart.cart.inc \basic_cart_get_total_price()
Returns the final price for the shopping cart.
Return value
mixed $total_price The total price for the shopping cart.
4 calls to basic_cart_get_total_price()
- basic_cart_block_view in ./
basic_cart.module - Implements hook_block_view().
- basic_cart_order_checkout in basic_cart_order/
basic_cart_order.module - Checkout form implementation.
- basic_cart_order_node_insert in basic_cart_order/
basic_cart_order.module - Implements hook_node_insert().
- theme_basic_cart_cart_total_price in ./
basic_cart.theme.inc - Theme implementation for rendering the total price.
File
- ./
basic_cart.cart.inc, line 185 - Basic cart shopping cart implementation functions.
Code
function basic_cart_get_total_price() {
// Building the return array.
$return = array(
'price' => 0,
'vat' => 0,
'total' => 0,
);
$cart = basic_cart_get_cart();
if (empty($cart)) {
return (object) $return;
}
$total_price = 0;
foreach ($cart as $nid => $node) {
if (isset($node->basic_cart_quantity) && isset($node->basic_cart_unit_price)) {
$total_price += $node->basic_cart_quantity * $node->basic_cart_unit_price;
}
}
$return['price'] = $total_price;
// Checking whether to apply the VAT or not.
$vat_is_enabled = (int) variable_get('basic_cart_vat_state');
if (!empty($vat_is_enabled) && $vat_is_enabled) {
$vat_value = (double) variable_get('basic_cart_vat_value');
$vat_value = $total_price * $vat_value / 100;
$total_price += $vat_value;
// Adding VAT and total price to the return array.
$return['vat'] = $vat_value;
}
$return['total'] = $total_price;
return (object) $return;
}