From 9e35faece2dcc1497528cc0d7ae7b908a8d9e521 Mon Sep 17 00:00:00 2001 From: Patrick Henninger Date: Sun, 12 May 2019 17:23:14 +0200 Subject: [PATCH 1/9] Add validation and exception for weight to CartItem Constructor --- src/CartItem.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/CartItem.php b/src/CartItem.php index 0717ed7..e5ac8ac 100644 --- a/src/CartItem.php +++ b/src/CartItem.php @@ -97,6 +97,9 @@ class CartItem implements Arrayable, Jsonable if (strlen($price) < 0 || !is_numeric($price)) { throw new \InvalidArgumentException('Please supply a valid price.'); } + if (strlen($weight) < 0 || !is_numeric($weight)) { + throw new \InvalidArgumentException('Please supply a valid weight.'); + } $this->id = $id; $this->name = $name; From 8f186e5edfeca00d3ee6aa67756fb396f1402d37 Mon Sep 17 00:00:00 2001 From: Patrick Henninger Date: Wed, 19 Jun 2019 18:02:26 +0200 Subject: [PATCH 2/9] Added homepages to authors --- composer.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index daac79e..23a9b02 100644 --- a/composer.json +++ b/composer.json @@ -6,11 +6,13 @@ "authors": [ { "name": "Rob Gloudemans", - "email": "info@robgloudemans.nl" + "email": "info@robgloudemans.nl", + "homepage": "http://robgloudemans.nl/" }, { "name": "Patrick Henninger", - "email": "privat@skyraptor.eu" + "email": "privat@skyraptor.eu", + "homepage": "https://skyraptor.eu/" } ], "require": { From 9d6a5dab8c34c20a890157cf61b75607d2fb3ec4 Mon Sep 17 00:00:00 2001 From: Patrick Date: Sun, 23 Jun 2019 00:11:50 +0200 Subject: [PATCH 3/9] Update CartItem.php Remove strlen from weight --- src/CartItem.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CartItem.php b/src/CartItem.php index e5ac8ac..8066d8d 100644 --- a/src/CartItem.php +++ b/src/CartItem.php @@ -97,7 +97,7 @@ class CartItem implements Arrayable, Jsonable if (strlen($price) < 0 || !is_numeric($price)) { throw new \InvalidArgumentException('Please supply a valid price.'); } - if (strlen($weight) < 0 || !is_numeric($weight)) { + if (!is_numeric($weight)) { throw new \InvalidArgumentException('Please supply a valid weight.'); } From 0c36a1d72e498eac2e5924a56200a764e93a2497 Mon Sep 17 00:00:00 2001 From: Patrick Date: Sun, 23 Jun 2019 00:24:25 +0200 Subject: [PATCH 4/9] Update CartItem.php Revert last change --- src/CartItem.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CartItem.php b/src/CartItem.php index 8066d8d..16b448b 100644 --- a/src/CartItem.php +++ b/src/CartItem.php @@ -97,7 +97,7 @@ class CartItem implements Arrayable, Jsonable if (strlen($price) < 0 || !is_numeric($price)) { throw new \InvalidArgumentException('Please supply a valid price.'); } - if (!is_numeric($weight)) { + if (strlen($price) < 0 || !is_numeric($weight)) { throw new \InvalidArgumentException('Please supply a valid weight.'); } From ecb4d9717a805b5af19c99733742d6ad78494d49 Mon Sep 17 00:00:00 2001 From: Patrick Date: Sun, 23 Jun 2019 00:25:32 +0200 Subject: [PATCH 5/9] Update Cart.php Changed default value of $weight to 0 --- src/Cart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cart.php b/src/Cart.php index 0e2269c..97097a0 100644 --- a/src/Cart.php +++ b/src/Cart.php @@ -110,7 +110,7 @@ class Cart * * @return \Gloudemans\Shoppingcart\CartItem */ - public function add($id, $name = null, $qty = null, $price = null, $weight = null, array $options = []) + public function add($id, $name = null, $qty = null, $price = null, $weight = 0, array $options = []) { if ($this->isMulti($id)) { return array_map(function ($item) { From a464a240e8f0337f6f1f4a6e11a80ea4dbb118f2 Mon Sep 17 00:00:00 2001 From: Patrick Date: Wed, 26 Jun 2019 15:36:53 +0200 Subject: [PATCH 6/9] Update CartTest.php Added Test for CartItem.php invalid weight exception. --- tests/CartTest.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/CartTest.php b/tests/CartTest.php index 8c278e5..611ae37 100644 --- a/tests/CartTest.php +++ b/tests/CartTest.php @@ -263,6 +263,19 @@ class CartTest extends TestCase $cart->add(1, 'Some title', 1, 'invalid'); } + + /** + * @test + */ + public function it_will_validate_the_weight() + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Please supply a valid weight'); + + $cart = $this->getCart(); + + $cart->add(1, 'Some title', 1, 10.00, 'invalid'); + } /** @test */ public function it_will_update_the_cart_if_the_item_already_exists_in_the_cart() From d78b555aa17a8bbdec3b3b12bcad4b1c83bcb512 Mon Sep 17 00:00:00 2001 From: Patrick Date: Wed, 26 Jun 2019 15:38:40 +0200 Subject: [PATCH 7/9] Update CartTest.php Codestyle --- tests/CartTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CartTest.php b/tests/CartTest.php index 611ae37..fc8f6ab 100644 --- a/tests/CartTest.php +++ b/tests/CartTest.php @@ -263,7 +263,7 @@ class CartTest extends TestCase $cart->add(1, 'Some title', 1, 'invalid'); } - + /** * @test */ From 30cd02f5f883ffda4e1a74158b35347d138bddcd Mon Sep 17 00:00:00 2001 From: Patrick Date: Wed, 26 Jun 2019 15:48:14 +0200 Subject: [PATCH 8/9] Update README.md https://github.com/bumbummen99/LaravelShoppingcart/issues/11 Fixed copypasta in the Readme --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b0340e3..a8ceb0b 100644 --- a/README.md +++ b/README.md @@ -306,8 +306,8 @@ $cart->setTax($rowId, 21); You can use the `setGlobalTax()` method to change the tax rate for all items in the cart. New items will receive the setGlobalTax as well. ```php -Cart::setGlobalDiscount(21); -$cart->setGlobalDiscount(21); +Cart::setGlobalTax(21); +$cart->setGlobalTax(21); ``` ### Cart::setGlobalDiscount($discountRate) @@ -315,8 +315,8 @@ $cart->setGlobalDiscount(21); You can use the `setGlobalDiscount()` method to change the discount rate for all items in the cart. New items will receive the discount as well. ```php -Cart::setGlobalDiscount(21); -$cart->setGlobalDiscount(21); +Cart::setGlobalDiscount(50); +$cart->setGlobalDiscount(50); ``` ### Cart::setDiscount($rowId, $taxRate) From 74607eb5ebd513d5a87ab9fe0dd25987e05a6a1c Mon Sep 17 00:00:00 2001 From: Patrick Date: Wed, 26 Jun 2019 15:53:08 +0200 Subject: [PATCH 9/9] Update ShoppingcartServiceProvider.php https://github.com/bumbummen99/LaravelShoppingcart/issues/8 Added missing publish group parameter --- src/ShoppingcartServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ShoppingcartServiceProvider.php b/src/ShoppingcartServiceProvider.php index a26ef89..2e6b1b5 100644 --- a/src/ShoppingcartServiceProvider.php +++ b/src/ShoppingcartServiceProvider.php @@ -30,6 +30,6 @@ class ShoppingcartServiceProvider extends ServiceProvider $this->publishes([ realpath(__DIR__.'/Database/migrations') => $this->app->databasePath().'/migrations', - ]); + ], 'migrations'); } }