Merge pull request #13 from bumbummen99/master

Merge latest updates to backport
This commit is contained in:
Patrick
2019-06-26 17:37:43 +02:00
committed by GitHub
6 changed files with 26 additions and 8 deletions

View File

@@ -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)

View File

@@ -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": {

View File

@@ -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) {

View File

@@ -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;

View File

@@ -30,6 +30,6 @@ class ShoppingcartServiceProvider extends ServiceProvider
$this->publishes([
realpath(__DIR__.'/Database/migrations') => $this->app->databasePath().'/migrations',
]);
], 'migrations');
}
}

View File

@@ -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()
{