diff --git a/src/Darryldecode/Cart/Cart.php b/src/Darryldecode/Cart/Cart.php index 5f5eaf3..c7d0173 100644 --- a/src/Darryldecode/Cart/Cart.php +++ b/src/Darryldecode/Cart/Cart.php @@ -544,7 +544,7 @@ public function getSubTotalWithoutConditions($formatted = true) $cart = $this->getContent(); $sum = $cart->sum(function ($item) { - return $item->getPriceSum(); + return $item->getPriceSum(false); }); return Helpers::formatValue(floatval($sum), $formatted, $this->config); @@ -647,6 +647,18 @@ public function getTotalQuantity() return $count; } + /** + * get total quantity of items individual in the cart + * + * @return int + */ + public function getTotalQuantityIndividual() + { + $items = $this->getContent(); + + return $items->count(); + } + /** * get the cart * diff --git a/src/Darryldecode/Cart/ItemCollection.php b/src/Darryldecode/Cart/ItemCollection.php index 2596c31..fd0443c 100644 --- a/src/Darryldecode/Cart/ItemCollection.php +++ b/src/Darryldecode/Cart/ItemCollection.php @@ -36,9 +36,9 @@ public function __construct($items, $config) * * @return mixed|null */ - public function getPriceSum() + public function getPriceSum($formatted = true) { - return Helpers::formatValue($this->price * $this->quantity, $this->config['format_numbers'], $this->config); + return Helpers::formatValue($this->price * $this->quantity, $formatted, $this->config); } @@ -118,4 +118,33 @@ public function getPriceSumWithConditions($formatted = true) { return Helpers::formatValue($this->getPriceWithConditions(false) * $this->quantity, $formatted, $this->config); } + + /** + * get the sum of condition type + * @param string $type + * @param bool $multiple + * @param bool $formatted + * @return mixed|null + */ + public function getPriceOfCondition($type, $multiple = true, $formatted = true) + { + $zero = 0.00; + $quantity = ($multiple == true) ? $this->quantity : 1; + + if ($this->hasConditions()) { + if (is_array($this->conditions)) { + foreach ($this->conditions as $condition) { + if ($condition->getType() == $type) { + $conditionValue = $condition->getValue() * $quantity; + } + } + } else { + $conditionValue = $this['conditions']->getValue() * $quantity; + } + + return Helpers::formatValue($conditionValue, $formatted, $this->config); + } + + return Helpers::formatValue($zero, $formatted, $this->config); + } }