You are here

function basic_cart_get_total_price in Basic cart 7.2

Same name and namespace in other branches
  1. 7.3 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.

5 calls to basic_cart_get_total_price()
basic_cart_block_view in ./basic_cart.module
Implements hook_block_view().
basic_cart_checkout in ./basic_cart.cart.inc
Checkout form implementation.
basic_cart_checkout_form_submit in ./basic_cart.cart.inc
Checkout form submit proccess. Register order and send emails.
basic_cart_order_register_order in basic_cart_order/basic_cart_order.module
Registers a new basic cart order to the database.
theme_basic_cart_cart_total_price in ./basic_cart.theme.inc
Theme implementation for rendering the total price.

File

./basic_cart.cart.inc, line 181
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;
}