added CartItem::priceTotal for rounded total (from internal calculation)

This commit is contained in:
sartoric
2020-01-15 12:44:58 +01:00
parent 9cdacf901c
commit 1a34bda8ab

View File

@@ -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.
*