mirror of
https://github.com/kevin-DL/LaravelShoppingcart.git
synced 2026-01-11 18:54:33 +00:00
added CartItem::priceTotal for rounded total (from internal calculation)
This commit is contained in:
30
src/Cart.php
30
src/Cart.php
@@ -401,11 +401,11 @@ class Cart
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the price of the items in the cart.
|
||||
* Get the price of the items in the cart (not rounded).
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function initialFloat() // TODO: rename and use priceTotal
|
||||
public function initialFloat()
|
||||
{
|
||||
return $this->getContent()->reduce(function ($initial, CartItem $cartItem) {
|
||||
return $initial + ($cartItem->qty * $cartItem->price);
|
||||
@@ -426,6 +426,32 @@ class Cart
|
||||
return $this->numberFormat($this->initialFloat(), $decimals, $decimalPoint, $thousandSeperator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the price of the items in the cart (previously rounded).
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function priceTotalFloat()
|
||||
{
|
||||
return $this->getContent()->reduce(function ($initial, CartItem $cartItem) {
|
||||
return $initial + $cartItem->priceTotal;
|
||||
}, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the price of the items in the cart as formatted string.
|
||||
*
|
||||
* @param int $decimals
|
||||
* @param string $decimalPoint
|
||||
* @param string $thousandSeperator
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function priceTotal($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
||||
{
|
||||
return $this->numberFormat($this->priceTotalFloat(), $decimals, $decimalPoint, $thousandSeperator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total weight of the items in the cart.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user