diff --git a/src/Cart.php b/src/Cart.php index 10a8795..d4280ec 100644 --- a/src/Cart.php +++ b/src/Cart.php @@ -253,7 +253,7 @@ class Cart $content = $this->getContent(); $total = $content->reduce(function ($total, CartItem $cartItem) { - return $total + ($cartItem->qty * $cartItem->priceTax); + return $total + $cartItem->total; }, 0); return $this->numberFormat($total, $decimals, $decimalPoint, $thousandSeperator); @@ -272,7 +272,7 @@ class Cart $content = $this->getContent(); $tax = $content->reduce(function ($tax, CartItem $cartItem) { - return $tax + ($cartItem->qty * $cartItem->tax); + return $tax + $cartItem->taxTotal; }, 0); return $this->numberFormat($tax, $decimals, $decimalPoint, $thousandSeperator); @@ -291,12 +291,50 @@ class Cart $content = $this->getContent(); $subTotal = $content->reduce(function ($subTotal, CartItem $cartItem) { - return $subTotal + ($cartItem->qty * $cartItem->price); + return $subTotal + $cartItem->subtotal; }, 0); return $this->numberFormat($subTotal, $decimals, $decimalPoint, $thousandSeperator); } + /** + * Get the subtotal (total - tax) of the items in the cart. + * + * @param int $decimals + * @param string $decimalPoint + * @param string $thousandSeperator + * @return float + */ + public function discount($decimals = null, $decimalPoint = null, $thousandSeperator = null) + { + $content = $this->getContent(); + + $discount = $content->reduce(function ($discount, CartItem $cartItem) { + return $discount + $cartItem->discountTotal; + }, 0); + + return $this->numberFormat($discount, $decimals, $decimalPoint, $thousandSeperator); + } + + /** + * Get the subtotal (total - tax) of the items in the cart. + * + * @param int $decimals + * @param string $decimalPoint + * @param string $thousandSeperator + * @return float + */ + public function initial($decimals = null, $decimalPoint = null, $thousandSeperator = null) + { + $content = $this->getContent(); + + $initial = $content->reduce(function ($initial, CartItem $cartItem) { + return $initial + ($cartItem->qty * $cartItem->price); + }, 0); + + return $this->numberFormat($initial, $decimals, $decimalPoint, $thousandSeperator); + } + /** * Search the cart content for a cart item matching the given search closure. * diff --git a/src/CartItem.php b/src/CartItem.php index b7a6efa..df3b403 100644 --- a/src/CartItem.php +++ b/src/CartItem.php @@ -334,7 +334,7 @@ class CartItem implements Arrayable, Jsonable } if($attribute === 'total') { - return $this->qty * ($this->priceTax); + return $this->qty * $this->priceTax; } if($attribute === 'taxTotal') {