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) 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": { 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) { diff --git a/src/CartItem.php b/src/CartItem.php index 0717ed7..16b448b 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($price) < 0 || !is_numeric($weight)) { + throw new \InvalidArgumentException('Please supply a valid weight.'); + } $this->id = $id; $this->name = $name; 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'); } } diff --git a/tests/CartTest.php b/tests/CartTest.php index 8c278e5..fc8f6ab 100644 --- a/tests/CartTest.php +++ b/tests/CartTest.php @@ -264,6 +264,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() {