mirror of
https://github.com/kevin-DL/LaravelShoppingcart.git
synced 2026-01-23 07:31:31 +00:00
Merge pull request #13 from bumbummen99/master
Merge latest updates to backport
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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": {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -30,6 +30,6 @@ class ShoppingcartServiceProvider extends ServiceProvider
|
||||
|
||||
$this->publishes([
|
||||
realpath(__DIR__.'/Database/migrations') => $this->app->databasePath().'/migrations',
|
||||
]);
|
||||
], 'migrations');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user