public static function Settings::getTotalPrice in Basic cart 8.2
Same name and namespace in other branches
- 8.6 src/Settings.php \Drupal\basic_cart\Settings::getTotalPrice()
- 8 src/Settings.php \Drupal\basic_cart\Settings::getTotalPrice()
- 8.0 src/Settings.php \Drupal\basic_cart\Settings::getTotalPrice()
- 8.3 src/Settings.php \Drupal\basic_cart\Settings::getTotalPrice()
- 8.4 src/Settings.php \Drupal\basic_cart\Settings::getTotalPrice()
- 8.5 src/Settings.php \Drupal\basic_cart\Settings::getTotalPrice()
Returns the final price for the shopping cart.
Return value
mixed The total price for the shopping cart.
1 call to Settings::getTotalPrice()
- Utility::getCartData in src/
Utility.php - Get Cart Data.
File
- src/
Settings.php, line 126
Class
- Settings
- Settings file for basic cart.
Namespace
Drupal\basic_cartCode
public static function getTotalPrice() {
$config = self::cartSettings();
$vat = $config
->get('vat_state');
// Building the return array.
$return = array(
'price' => 0,
'vat' => 0,
'total' => 0,
);
$cart = static::getCart();
if (empty($cart)) {
return (object) $return;
}
$total_price = 0;
foreach ($cart['cart'] as $nid => $node) {
$langcode = $node
->language()
->getId();
$value = $node
->getTranslation($langcode)
->get('add_to_cart_price')
->getValue();
if (isset($cart['cart_quantity'][$nid]) && isset($value[0]['value'])) {
$total_price += $cart['cart_quantity'][$nid] * $value[0]['value'];
}
$value = 0;
}
$return['price'] = $total_price;
// Checking whether to apply the VAT or not.
$vat_is_enabled = (int) $config
->get('vat_state');
if (!empty($vat_is_enabled) && $vat_is_enabled) {
$vat_value = (double) $config
->get('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;
}