From cadbdf23ac268ae51cdd172e6ea638a7a5815a58 Mon Sep 17 00:00:00 2001 From: jrmessias Date: Tue, 16 Jul 2019 15:04:15 -0300 Subject: [PATCH 1/5] Feature and fix Create method to get price of condition in item Fix error "A non well formed numeric value..." in getValue at Cart --- src/Darryldecode/Cart/Cart.php | 2 +- src/Darryldecode/Cart/ItemCollection.php | 35 ++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/Darryldecode/Cart/Cart.php b/src/Darryldecode/Cart/Cart.php index 5f5eaf3..c3afed4 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); diff --git a/src/Darryldecode/Cart/ItemCollection.php b/src/Darryldecode/Cart/ItemCollection.php index 2596c31..e5de4bd 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,35 @@ 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) + { + $originalPrice = $this->price; + $newPrice = 0.00; + $processed = 0; + $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($originalPrice, $formatted, $this->config); + } } From 6cff1e2cfe5618befa2fadd671e6037da003254e Mon Sep 17 00:00:00 2001 From: jrmessias Date: Thu, 18 Jul 2019 08:49:59 -0300 Subject: [PATCH 2/5] :pencil: Get total items individual Added method to return quantity of individual item in cart --- src/Darryldecode/Cart/Cart.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Darryldecode/Cart/Cart.php b/src/Darryldecode/Cart/Cart.php index c3afed4..c7d0173 100644 --- a/src/Darryldecode/Cart/Cart.php +++ b/src/Darryldecode/Cart/Cart.php @@ -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 * From e4ceaa481103b118614ca729e3a8a5a09a24ffc2 Mon Sep 17 00:00:00 2001 From: jrmessias Date: Thu, 18 Jul 2019 13:12:20 -0300 Subject: [PATCH 3/5] :pencil: Fix calc in conditions for item Ajust calc when item do not have conditions --- src/Darryldecode/Cart/ItemCollection.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Darryldecode/Cart/ItemCollection.php b/src/Darryldecode/Cart/ItemCollection.php index e5de4bd..fd0443c 100644 --- a/src/Darryldecode/Cart/ItemCollection.php +++ b/src/Darryldecode/Cart/ItemCollection.php @@ -128,9 +128,7 @@ public function getPriceSumWithConditions($formatted = true) */ public function getPriceOfCondition($type, $multiple = true, $formatted = true) { - $originalPrice = $this->price; - $newPrice = 0.00; - $processed = 0; + $zero = 0.00; $quantity = ($multiple == true) ? $this->quantity : 1; if ($this->hasConditions()) { @@ -147,6 +145,6 @@ public function getPriceOfCondition($type, $multiple = true, $formatted = true) return Helpers::formatValue($conditionValue, $formatted, $this->config); } - return Helpers::formatValue($originalPrice, $formatted, $this->config); + return Helpers::formatValue($zero, $formatted, $this->config); } } From 96f36ffe85733978ea83a92787f105c1b23e550d Mon Sep 17 00:00:00 2001 From: jrmessias Date: Mon, 12 Aug 2019 10:14:10 -0300 Subject: [PATCH 4/5] :package: Update composer --- composer.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 0582f5d..2891770 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "darryldecode/cart", + "name": "jrmessias/cart", "description": "Laravel 5 Shopping cart", "keywords": ["laravel", "shopping cart", "cart"], "license": "MIT", @@ -7,6 +7,10 @@ { "name": "Darryl Fernandez", "email": "engrdarrylfernandez@gmail.com" + }, + { + "name": "Junior Messias", + "email": "jrmessias@gmail.com" } ], "require": { From 24859cdca077dfe24be1ef0cc9c530d0d90f3fa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAnior=20Messias?= Date: Tue, 15 Oct 2019 08:17:28 -0300 Subject: [PATCH 5/5] Update composer.json Remove my name --- composer.json | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 2891770..0582f5d 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "jrmessias/cart", + "name": "darryldecode/cart", "description": "Laravel 5 Shopping cart", "keywords": ["laravel", "shopping cart", "cart"], "license": "MIT", @@ -7,10 +7,6 @@ { "name": "Darryl Fernandez", "email": "engrdarrylfernandez@gmail.com" - }, - { - "name": "Junior Messias", - "email": "jrmessias@gmail.com" } ], "require": {