mirror of
https://github.com/kevin-DL/LaravelShoppingcart.git
synced 2026-01-11 18:54:33 +00:00
Merge pull request #115 from geisi/master
Fixing InvalidArgumentException when adding buyable models
This commit is contained in:
@@ -21,16 +21,16 @@ trait CanBeBought
|
|||||||
*/
|
*/
|
||||||
public function getBuyableDescription($options = null)
|
public function getBuyableDescription($options = null)
|
||||||
{
|
{
|
||||||
if (property_exists($this, 'name')) {
|
if (($name = $this->getAttribute('name'))) {
|
||||||
return $this->name;
|
return $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property_exists($this, 'title')) {
|
if (($title = $this->getAttribute('title'))) {
|
||||||
return $this->title;
|
return $ttle;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property_exists($this, 'description')) {
|
if (($description = $this->getAttribute('description'))) {
|
||||||
return $this->description;
|
return $description;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,8 +41,8 @@ trait CanBeBought
|
|||||||
*/
|
*/
|
||||||
public function getBuyablePrice($options = null)
|
public function getBuyablePrice($options = null)
|
||||||
{
|
{
|
||||||
if (property_exists($this, 'price')) {
|
if (($price = $this->getAttribute('price'))) {
|
||||||
return $this->price;
|
return $price;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,8 +53,8 @@ trait CanBeBought
|
|||||||
*/
|
*/
|
||||||
public function getBuyableWeight($options = null)
|
public function getBuyableWeight($options = null)
|
||||||
{
|
{
|
||||||
if (property_exists($this, 'weight')) {
|
if (($weight = $this->getAttribute('weight'))) {
|
||||||
return $this->weight;
|
return $weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -82,9 +82,15 @@ class CartTest extends TestCase
|
|||||||
{
|
{
|
||||||
$cart = $this->getCart();
|
$cart = $this->getCart();
|
||||||
|
|
||||||
$cart->add(new BuyableProduct(1, 'First item'));
|
$cart->add(new BuyableProduct([
|
||||||
|
'id' => 1,
|
||||||
|
'name' => 'First item',
|
||||||
|
]));
|
||||||
|
|
||||||
$cart->instance('wishlist')->add(new BuyableProduct(2, 'Second item'));
|
$cart->instance('wishlist')->add(new BuyableProduct([
|
||||||
|
'id' => 2,
|
||||||
|
'name' => 'Second item',
|
||||||
|
]));
|
||||||
|
|
||||||
$this->assertItemsInCart(1, $cart->instance(Cart::DEFAULT_INSTANCE));
|
$this->assertItemsInCart(1, $cart->instance(Cart::DEFAULT_INSTANCE));
|
||||||
$this->assertItemsInCart(1, $cart->instance('wishlist'));
|
$this->assertItemsInCart(1, $cart->instance('wishlist'));
|
||||||
@@ -126,7 +132,11 @@ class CartTest extends TestCase
|
|||||||
|
|
||||||
$cart = $this->getCart();
|
$cart = $this->getCart();
|
||||||
|
|
||||||
$cart->add([new BuyableProduct(1), new BuyableProduct(2)]);
|
$cart->add([new BuyableProduct([
|
||||||
|
'id' => 1,
|
||||||
|
]), new BuyableProduct([
|
||||||
|
'id' => 2,
|
||||||
|
])]);
|
||||||
|
|
||||||
$this->assertEquals(2, $cart->count());
|
$this->assertEquals(2, $cart->count());
|
||||||
|
|
||||||
@@ -140,7 +150,11 @@ class CartTest extends TestCase
|
|||||||
|
|
||||||
$cart = $this->getCart();
|
$cart = $this->getCart();
|
||||||
|
|
||||||
$cartItems = $cart->add([new BuyableProduct(1), new BuyableProduct(2)]);
|
$cartItems = $cart->add([new BuyableProduct([
|
||||||
|
'id' => 1,
|
||||||
|
]), new BuyableProduct([
|
||||||
|
'id' => 2,
|
||||||
|
])]);
|
||||||
|
|
||||||
$this->assertTrue(is_array($cartItems));
|
$this->assertTrue(is_array($cartItems));
|
||||||
$this->assertCount(2, $cartItems);
|
$this->assertCount(2, $cartItems);
|
||||||
@@ -332,9 +346,14 @@ class CartTest extends TestCase
|
|||||||
|
|
||||||
$cart = $this->getCart();
|
$cart = $this->getCart();
|
||||||
|
|
||||||
$cart->add(new BuyableProduct());
|
$cart->add(new BuyableProductTrait([
|
||||||
|
'description' => 'Description',
|
||||||
|
]));
|
||||||
|
|
||||||
$cart->update('027c91341fd5cf4d2579b49c4b6a90da', new BuyableProduct(1, 'Different description'));
|
$cart->update('027c91341fd5cf4d2579b49c4b6a90da', new BuyableProductTrait([
|
||||||
|
'name' => '',
|
||||||
|
'description' => 'Different description',
|
||||||
|
]));
|
||||||
|
|
||||||
$this->assertItemsInCart(1, $cart);
|
$this->assertItemsInCart(1, $cart);
|
||||||
$this->assertEquals('Different description', $cart->get('027c91341fd5cf4d2579b49c4b6a90da')->name);
|
$this->assertEquals('Different description', $cart->get('027c91341fd5cf4d2579b49c4b6a90da')->name);
|
||||||
@@ -349,7 +368,9 @@ class CartTest extends TestCase
|
|||||||
|
|
||||||
$cart = $this->getCart();
|
$cart = $this->getCart();
|
||||||
|
|
||||||
$cart->add(new BuyableProduct());
|
$cart->add(new BuyableProductTrait([
|
||||||
|
'description' => 'Description',
|
||||||
|
]));
|
||||||
|
|
||||||
$cart->update('027c91341fd5cf4d2579b49c4b6a90da', ['name' => 'Different description']);
|
$cart->update('027c91341fd5cf4d2579b49c4b6a90da', ['name' => 'Different description']);
|
||||||
|
|
||||||
@@ -370,7 +391,9 @@ class CartTest extends TestCase
|
|||||||
|
|
||||||
$cart->add(new BuyableProduct());
|
$cart->add(new BuyableProduct());
|
||||||
|
|
||||||
$cart->update('none-existing-rowid', new BuyableProduct(1, 'Different description'));
|
$cart->update('none-existing-rowid', new BuyableProduct([
|
||||||
|
'description' => 'Different description',
|
||||||
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
@@ -484,8 +507,10 @@ class CartTest extends TestCase
|
|||||||
{
|
{
|
||||||
$cart = $this->getCart();
|
$cart = $this->getCart();
|
||||||
|
|
||||||
$cart->add(new BuyableProduct(1));
|
$cart->add(new BuyableProduct());
|
||||||
$cart->add(new BuyableProduct(2));
|
$cart->add(new BuyableProduct([
|
||||||
|
'id' => 2,
|
||||||
|
]));
|
||||||
|
|
||||||
$content = $cart->content();
|
$content = $cart->content();
|
||||||
|
|
||||||
@@ -509,8 +534,10 @@ class CartTest extends TestCase
|
|||||||
{
|
{
|
||||||
$cart = $this->getCart();
|
$cart = $this->getCart();
|
||||||
|
|
||||||
$cart->add(new BuyableProduct(1));
|
$cart->add(new BuyableProduct());
|
||||||
$cart->add(new BuyableProduct(2));
|
$cart->add(new BuyableProduct([
|
||||||
|
'id' => 2,
|
||||||
|
]));
|
||||||
|
|
||||||
$content = $cart->content();
|
$content = $cart->content();
|
||||||
|
|
||||||
@@ -562,8 +589,14 @@ class CartTest extends TestCase
|
|||||||
{
|
{
|
||||||
$cart = $this->getCart();
|
$cart = $this->getCart();
|
||||||
|
|
||||||
$cart->add(new BuyableProduct(1, 'First item', 10.00));
|
$cart->add(new BuyableProduct([
|
||||||
$cart->add(new BuyableProduct(2, 'Second item', 25.00), 2);
|
'name' => 'First item',
|
||||||
|
]));
|
||||||
|
$cart->add(new BuyableProduct([
|
||||||
|
'id' => 2,
|
||||||
|
'name' => 'Second item',
|
||||||
|
'price' => 25.00,
|
||||||
|
]), 2);
|
||||||
|
|
||||||
$this->assertItemsInCart(3, $cart);
|
$this->assertItemsInCart(3, $cart);
|
||||||
$this->assertEquals(60.00, $cart->subtotal());
|
$this->assertEquals(60.00, $cart->subtotal());
|
||||||
@@ -574,8 +607,15 @@ class CartTest extends TestCase
|
|||||||
{
|
{
|
||||||
$cart = $this->getCart();
|
$cart = $this->getCart();
|
||||||
|
|
||||||
$cart->add(new BuyableProduct(1, 'First item', 1000.00));
|
$cart->add(new BuyableProduct([
|
||||||
$cart->add(new BuyableProduct(2, 'Second item', 2500.00), 2);
|
'name' => 'First item',
|
||||||
|
'price' => 1000.00,
|
||||||
|
]));
|
||||||
|
$cart->add(new BuyableProduct([
|
||||||
|
'id' => 2,
|
||||||
|
'name' => 'Second item',
|
||||||
|
'price' => 2500.00,
|
||||||
|
]), 2);
|
||||||
|
|
||||||
$this->assertItemsInCart(3, $cart);
|
$this->assertItemsInCart(3, $cart);
|
||||||
$this->assertEquals('6.000,00', $cart->subtotal(2, ',', '.'));
|
$this->assertEquals('6.000,00', $cart->subtotal(2, ',', '.'));
|
||||||
@@ -586,8 +626,13 @@ class CartTest extends TestCase
|
|||||||
{
|
{
|
||||||
$cart = $this->getCart();
|
$cart = $this->getCart();
|
||||||
|
|
||||||
$cart->add(new BuyableProduct(1, 'Some item'));
|
$cart->add(new BuyableProduct([
|
||||||
$cart->add(new BuyableProduct(2, 'Another item'));
|
'name' => 'Some item',
|
||||||
|
]));
|
||||||
|
$cart->add(new BuyableProduct([
|
||||||
|
'id' => 2,
|
||||||
|
'name' => 'Another item',
|
||||||
|
]));
|
||||||
|
|
||||||
$cartItem = $cart->search(function ($cartItem, $rowId) {
|
$cartItem = $cart->search(function ($cartItem, $rowId) {
|
||||||
return $cartItem->name == 'Some item';
|
return $cartItem->name == 'Some item';
|
||||||
@@ -604,9 +649,17 @@ class CartTest extends TestCase
|
|||||||
{
|
{
|
||||||
$cart = $this->getCart();
|
$cart = $this->getCart();
|
||||||
|
|
||||||
$cart->add(new BuyableProduct(1, 'Some item'));
|
$cart->add(new BuyableProduct([
|
||||||
$cart->add(new BuyableProduct(2, 'Some item'));
|
'name' => 'Some item',
|
||||||
$cart->add(new BuyableProduct(3, 'Another item'));
|
]));
|
||||||
|
$cart->add(new BuyableProduct([
|
||||||
|
'id' => 2,
|
||||||
|
'name' => 'Some item',
|
||||||
|
]));
|
||||||
|
$cart->add(new BuyableProduct([
|
||||||
|
'id' => 3,
|
||||||
|
'name' => 'Another item',
|
||||||
|
]));
|
||||||
|
|
||||||
$cartItem = $cart->search(function ($cartItem, $rowId) {
|
$cartItem = $cart->search(function ($cartItem, $rowId) {
|
||||||
return $cartItem->name == 'Some item';
|
return $cartItem->name == 'Some item';
|
||||||
@@ -620,8 +673,13 @@ class CartTest extends TestCase
|
|||||||
{
|
{
|
||||||
$cart = $this->getCart();
|
$cart = $this->getCart();
|
||||||
|
|
||||||
$cart->add(new BuyableProduct(1, 'Some item'), 1, ['color' => 'red']);
|
$cart->add(new BuyableProduct([
|
||||||
$cart->add(new BuyableProduct(2, 'Another item'), 1, ['color' => 'blue']);
|
'name' => 'Some item',
|
||||||
|
]), 1, ['color' => 'red']);
|
||||||
|
$cart->add(new BuyableProduct([
|
||||||
|
'id' => 2,
|
||||||
|
'name' => 'Another item',
|
||||||
|
]), 1, ['color' => 'blue']);
|
||||||
|
|
||||||
$cartItem = $cart->search(function ($cartItem, $rowId) {
|
$cartItem = $cart->search(function ($cartItem, $rowId) {
|
||||||
return $cartItem->options->color == 'red';
|
return $cartItem->options->color == 'red';
|
||||||
@@ -694,7 +752,10 @@ class CartTest extends TestCase
|
|||||||
{
|
{
|
||||||
$cart = $this->getCart();
|
$cart = $this->getCart();
|
||||||
|
|
||||||
$cart->add(new BuyableProduct(1, 'Some title', 9.99), 3);
|
$cart->add(new BuyableProduct([
|
||||||
|
'name' => 'Some title',
|
||||||
|
'price' => 9.99,
|
||||||
|
]), 3);
|
||||||
|
|
||||||
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
|
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
|
||||||
|
|
||||||
@@ -706,7 +767,10 @@ class CartTest extends TestCase
|
|||||||
{
|
{
|
||||||
$cart = $this->getCart();
|
$cart = $this->getCart();
|
||||||
|
|
||||||
$cart->add(new BuyableProduct(1, 'Some title', 500), 3);
|
$cart->add(new BuyableProduct([
|
||||||
|
'name' => 'Some title',
|
||||||
|
'price' => 500,
|
||||||
|
]), 3);
|
||||||
|
|
||||||
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
|
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
|
||||||
|
|
||||||
@@ -718,7 +782,9 @@ class CartTest extends TestCase
|
|||||||
{
|
{
|
||||||
$cart = $this->getCart();
|
$cart = $this->getCart();
|
||||||
|
|
||||||
$cart->add(new BuyableProduct(1, 'Some title', 10.00), 1);
|
$cart->add(new BuyableProduct([
|
||||||
|
'name' => 'Some title',
|
||||||
|
]), 1);
|
||||||
|
|
||||||
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
|
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
|
||||||
|
|
||||||
@@ -730,7 +796,9 @@ class CartTest extends TestCase
|
|||||||
{
|
{
|
||||||
$cart = $this->getCart();
|
$cart = $this->getCart();
|
||||||
|
|
||||||
$cart->add(new BuyableProduct(1, 'Some title', 10.00), 1);
|
$cart->add(new BuyableProduct([
|
||||||
|
'name' => 'Some title',
|
||||||
|
]), 1);
|
||||||
|
|
||||||
$cart->setTax('027c91341fd5cf4d2579b49c4b6a90da', 19);
|
$cart->setTax('027c91341fd5cf4d2579b49c4b6a90da', 19);
|
||||||
|
|
||||||
@@ -744,7 +812,10 @@ class CartTest extends TestCase
|
|||||||
{
|
{
|
||||||
$cart = $this->getCart();
|
$cart = $this->getCart();
|
||||||
|
|
||||||
$cart->add(new BuyableProduct(1, 'Some title', 10000.00), 1);
|
$cart->add(new BuyableProduct([
|
||||||
|
'name' => 'Some title',
|
||||||
|
'price' => 10000.00,
|
||||||
|
]), 1);
|
||||||
|
|
||||||
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
|
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
|
||||||
|
|
||||||
@@ -756,8 +827,14 @@ class CartTest extends TestCase
|
|||||||
{
|
{
|
||||||
$cart = $this->getCart();
|
$cart = $this->getCart();
|
||||||
|
|
||||||
$cart->add(new BuyableProduct(1, 'Some title', 10.00), 1);
|
$cart->add(new BuyableProduct([
|
||||||
$cart->add(new BuyableProduct(2, 'Some title', 20.00), 2);
|
'name' => 'Some title',
|
||||||
|
]), 1);
|
||||||
|
$cart->add(new BuyableProduct([
|
||||||
|
'id' => 2,
|
||||||
|
'name' => 'Some title',
|
||||||
|
'price' => 20.00,
|
||||||
|
]), 2);
|
||||||
|
|
||||||
$this->assertEquals(10.50, $cart->tax);
|
$this->assertEquals(10.50, $cart->tax);
|
||||||
}
|
}
|
||||||
@@ -767,8 +844,15 @@ class CartTest extends TestCase
|
|||||||
{
|
{
|
||||||
$cart = $this->getCart();
|
$cart = $this->getCart();
|
||||||
|
|
||||||
$cart->add(new BuyableProduct(1, 'Some title', 1000.00), 1);
|
$cart->add(new BuyableProduct([
|
||||||
$cart->add(new BuyableProduct(2, 'Some title', 2000.00), 2);
|
'name' => 'Some title',
|
||||||
|
'price' => 1000.00,
|
||||||
|
]), 1);
|
||||||
|
$cart->add(new BuyableProduct([
|
||||||
|
'id' => 2,
|
||||||
|
'name' => 'Some title',
|
||||||
|
'price' => 2000.00,
|
||||||
|
]), 2);
|
||||||
|
|
||||||
$this->assertEquals('1.050,00', $cart->tax(2, ',', '.'));
|
$this->assertEquals('1.050,00', $cart->tax(2, ',', '.'));
|
||||||
}
|
}
|
||||||
@@ -778,7 +862,9 @@ class CartTest extends TestCase
|
|||||||
{
|
{
|
||||||
$cart = $this->getCart();
|
$cart = $this->getCart();
|
||||||
|
|
||||||
$cart->add(new BuyableProduct(1, 'Some title', 10.00), 1);
|
$cart->add(new BuyableProduct([
|
||||||
|
'name' => 'Some title',
|
||||||
|
]), 1);
|
||||||
|
|
||||||
$cart->setTax('027c91341fd5cf4d2579b49c4b6a90da', 19);
|
$cart->setTax('027c91341fd5cf4d2579b49c4b6a90da', 19);
|
||||||
|
|
||||||
@@ -792,8 +878,11 @@ class CartTest extends TestCase
|
|||||||
{
|
{
|
||||||
$cart = $this->getCart();
|
$cart = $this->getCart();
|
||||||
|
|
||||||
$cart->add(new BuyableProduct(1, 'Some title', 10.00), 1);
|
$cart->add(new BuyableProduct(), 1);
|
||||||
$cart->add(new BuyableProduct(2, 'Some title', 20.00), 2);
|
$cart->add(new BuyableProduct([
|
||||||
|
'id' => 2,
|
||||||
|
'price' => 20.00,
|
||||||
|
]), 2);
|
||||||
|
|
||||||
$this->assertEquals(50.00, $cart->subtotal);
|
$this->assertEquals(50.00, $cart->subtotal);
|
||||||
}
|
}
|
||||||
@@ -803,8 +892,13 @@ class CartTest extends TestCase
|
|||||||
{
|
{
|
||||||
$cart = $this->getCart();
|
$cart = $this->getCart();
|
||||||
|
|
||||||
$cart->add(new BuyableProduct(1, 'Some title', 1000.00), 1);
|
$cart->add(new BuyableProduct([
|
||||||
$cart->add(new BuyableProduct(2, 'Some title', 2000.00), 2);
|
'price' => 1000.00,
|
||||||
|
]), 1);
|
||||||
|
$cart->add(new BuyableProduct([
|
||||||
|
'id' => 2,
|
||||||
|
'price' => 2000.00,
|
||||||
|
]), 2);
|
||||||
|
|
||||||
$this->assertEquals('5000,00', $cart->subtotal(2, ',', ''));
|
$this->assertEquals('5000,00', $cart->subtotal(2, ',', ''));
|
||||||
}
|
}
|
||||||
@@ -816,8 +910,13 @@ class CartTest extends TestCase
|
|||||||
|
|
||||||
$cart = $this->getCart();
|
$cart = $this->getCart();
|
||||||
|
|
||||||
$cart->add(new BuyableProduct(1, 'Some title', 1000.00), 1);
|
$cart->add(new BuyableProduct([
|
||||||
$cart->add(new BuyableProduct(2, 'Some title', 2000.00), 2);
|
'price' => 1000.00,
|
||||||
|
]), 1);
|
||||||
|
$cart->add(new BuyableProduct([
|
||||||
|
'id' => 2,
|
||||||
|
'price' => 2000.00,
|
||||||
|
]), 2);
|
||||||
|
|
||||||
$this->assertEquals('5000,00', $cart->subtotal());
|
$this->assertEquals('5000,00', $cart->subtotal());
|
||||||
$this->assertEquals('1050,00', $cart->tax());
|
$this->assertEquals('1050,00', $cart->tax());
|
||||||
@@ -835,7 +934,9 @@ class CartTest extends TestCase
|
|||||||
|
|
||||||
$cart = $this->getCartDiscount(50);
|
$cart = $this->getCartDiscount(50);
|
||||||
|
|
||||||
$cart->add(new BuyableProduct(1, 'Some title', 2000.00), 2);
|
$cart->add(new BuyableProduct([
|
||||||
|
'price' => 2000.00,
|
||||||
|
]), 2);
|
||||||
|
|
||||||
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
|
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
|
||||||
|
|
||||||
@@ -988,7 +1089,9 @@ class CartTest extends TestCase
|
|||||||
{
|
{
|
||||||
$cart = $this->getCartDiscount(50);
|
$cart = $this->getCartDiscount(50);
|
||||||
|
|
||||||
$cart->add(new BuyableProduct(1, 'First item', 10.00), 2);
|
$cart->add(new BuyableProduct([
|
||||||
|
'name' => 'First item',
|
||||||
|
]), 2);
|
||||||
|
|
||||||
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
|
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
|
||||||
|
|
||||||
@@ -1009,7 +1112,9 @@ class CartTest extends TestCase
|
|||||||
public function it_can_calculate_all_values_after_updating_from_array()
|
public function it_can_calculate_all_values_after_updating_from_array()
|
||||||
{
|
{
|
||||||
$cart = $this->getCartDiscount(50);
|
$cart = $this->getCartDiscount(50);
|
||||||
$cart->add(new BuyableProduct(1, 'First item', 10.00), 1);
|
$cart->add(new BuyableProduct([
|
||||||
|
'name' => 'First item',
|
||||||
|
]), 1);
|
||||||
|
|
||||||
$cart->update('027c91341fd5cf4d2579b49c4b6a90da', ['qty' => 2]);
|
$cart->update('027c91341fd5cf4d2579b49c4b6a90da', ['qty' => 2]);
|
||||||
|
|
||||||
@@ -1032,9 +1137,14 @@ class CartTest extends TestCase
|
|||||||
public function it_can_calculate_all_values_after_updating_from_buyable()
|
public function it_can_calculate_all_values_after_updating_from_buyable()
|
||||||
{
|
{
|
||||||
$cart = $this->getCartDiscount(50);
|
$cart = $this->getCartDiscount(50);
|
||||||
$cart->add(new BuyableProduct(1, 'First item', 5.00), 2);
|
$cart->add(new BuyableProduct([
|
||||||
|
'name' => 'First item',
|
||||||
|
'price' => 5.00,
|
||||||
|
]), 2);
|
||||||
|
|
||||||
$cart->update('027c91341fd5cf4d2579b49c4b6a90da', new BuyableProduct(1, 'First item', 10.00));
|
$cart->update('027c91341fd5cf4d2579b49c4b6a90da', new BuyableProduct([
|
||||||
|
'name' => 'First item',
|
||||||
|
]));
|
||||||
|
|
||||||
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
|
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
|
||||||
|
|
||||||
@@ -1070,7 +1180,9 @@ class CartTest extends TestCase
|
|||||||
{
|
{
|
||||||
$cart = $this->getCart();
|
$cart = $this->getCart();
|
||||||
|
|
||||||
$cart->add(new BuyableProduct(1, 'Item', 10.00), 2);
|
$cart->add(new BuyableProduct([
|
||||||
|
'name' => 'Item',
|
||||||
|
]), 2);
|
||||||
|
|
||||||
$cart->setGlobalTax(0);
|
$cart->setGlobalTax(0);
|
||||||
|
|
||||||
@@ -1084,7 +1196,9 @@ class CartTest extends TestCase
|
|||||||
{
|
{
|
||||||
$cart = $this->getCart();
|
$cart = $this->getCart();
|
||||||
|
|
||||||
$cart->add(new BuyableProduct(1, 'Item', 10.00), 2);
|
$cart->add(new BuyableProduct([
|
||||||
|
'name' => 'Item',
|
||||||
|
]), 2);
|
||||||
|
|
||||||
$cart->setGlobalTax(0);
|
$cart->setGlobalTax(0);
|
||||||
$cart->setGlobalDiscount(50);
|
$cart->setGlobalDiscount(50);
|
||||||
@@ -1099,7 +1213,10 @@ class CartTest extends TestCase
|
|||||||
{
|
{
|
||||||
$cart = $this->getCart();
|
$cart = $this->getCart();
|
||||||
|
|
||||||
$cart->add(new BuyableProduct(1, 'Item', 10.004), 2);
|
$cart->add(new BuyableProduct([
|
||||||
|
'name' => 'Item',
|
||||||
|
'price' => 10.004,
|
||||||
|
]), 2);
|
||||||
|
|
||||||
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
|
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
|
||||||
|
|
||||||
@@ -1116,8 +1233,13 @@ class CartTest extends TestCase
|
|||||||
Event::fake();
|
Event::fake();
|
||||||
|
|
||||||
$cart = $this->getCartDiscount(50);
|
$cart = $this->getCartDiscount(50);
|
||||||
$cart->add(new BuyableProduct(1, 'Item', 10.00), 1);
|
$cart->add(new BuyableProduct([
|
||||||
$cart->add(new BuyableProduct(2, 'Item 2', 10.00), 1);
|
'name' => 'Item',
|
||||||
|
]), 1);
|
||||||
|
$cart->add(new BuyableProduct([
|
||||||
|
'id' => 2,
|
||||||
|
'name' => 'Item 2',
|
||||||
|
]), 1);
|
||||||
$cart->store('test');
|
$cart->store('test');
|
||||||
|
|
||||||
$cart2 = $this->getCart();
|
$cart2 = $this->getCart();
|
||||||
@@ -1150,8 +1272,13 @@ class CartTest extends TestCase
|
|||||||
]);
|
]);
|
||||||
Event::fake();
|
Event::fake();
|
||||||
$cart = $this->getCartDiscount(50);
|
$cart = $this->getCartDiscount(50);
|
||||||
$cart->add(new BuyableProduct(1, 'Item', 10.00), 1);
|
$cart->add(new BuyableProduct([
|
||||||
$cart->add(new BuyableProduct(2, 'Item 2', 10.00), 1);
|
'name' => 'Item',
|
||||||
|
]), 1);
|
||||||
|
$cart->add(new BuyableProduct([
|
||||||
|
'id' => 2,
|
||||||
|
'name' => 'Item 2',
|
||||||
|
]), 1);
|
||||||
$this->assertEquals(false, $cart->merge('doesNotExist'));
|
$this->assertEquals(false, $cart->merge('doesNotExist'));
|
||||||
$this->assertEquals(2, $cart->countItems());
|
$this->assertEquals(2, $cart->countItems());
|
||||||
}
|
}
|
||||||
@@ -1160,7 +1287,9 @@ class CartTest extends TestCase
|
|||||||
public function cart_can_calculate_all_values()
|
public function cart_can_calculate_all_values()
|
||||||
{
|
{
|
||||||
$cart = $this->getCartDiscount(50);
|
$cart = $this->getCartDiscount(50);
|
||||||
$cart->add(new BuyableProduct(1, 'First item', 10.00), 1);
|
$cart->add(new BuyableProduct([
|
||||||
|
'name' => 'First item',
|
||||||
|
]), 1);
|
||||||
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
|
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
|
||||||
$cart->setTax('027c91341fd5cf4d2579b49c4b6a90da', 19);
|
$cart->setTax('027c91341fd5cf4d2579b49c4b6a90da', 19);
|
||||||
$this->assertEquals('10.00', $cart->initial(2));
|
$this->assertEquals('10.00', $cart->initial(2));
|
||||||
@@ -1179,7 +1308,9 @@ class CartTest extends TestCase
|
|||||||
public function can_access_cart_item_propertys()
|
public function can_access_cart_item_propertys()
|
||||||
{
|
{
|
||||||
$cart = $this->getCartDiscount(50);
|
$cart = $this->getCartDiscount(50);
|
||||||
$cart->add(new BuyableProduct(1, 'First item', 10.00), 1);
|
$cart->add(new BuyableProduct([
|
||||||
|
'name' => 'First item',
|
||||||
|
]), 1);
|
||||||
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
|
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
|
||||||
$this->assertEquals(50, $cartItem->discountRate);
|
$this->assertEquals(50, $cartItem->discountRate);
|
||||||
}
|
}
|
||||||
@@ -1188,7 +1319,9 @@ class CartTest extends TestCase
|
|||||||
public function cant_access_non_existant_propertys()
|
public function cant_access_non_existant_propertys()
|
||||||
{
|
{
|
||||||
$cart = $this->getCartDiscount(50);
|
$cart = $this->getCartDiscount(50);
|
||||||
$cart->add(new BuyableProduct(1, 'First item', 10.00), 1);
|
$cart->add(new BuyableProduct([
|
||||||
|
'name' => 'First item',
|
||||||
|
]), 1);
|
||||||
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
|
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
|
||||||
$this->assertEquals(null, $cartItem->doesNotExist);
|
$this->assertEquals(null, $cartItem->doesNotExist);
|
||||||
$this->assertEquals(null, $cart->doesNotExist);
|
$this->assertEquals(null, $cart->doesNotExist);
|
||||||
@@ -1198,7 +1331,9 @@ class CartTest extends TestCase
|
|||||||
public function can_set_cart_item_discount()
|
public function can_set_cart_item_discount()
|
||||||
{
|
{
|
||||||
$cart = $this->getCart();
|
$cart = $this->getCart();
|
||||||
$cart->add(new BuyableProduct(1, 'First item', 10.00), 1);
|
$cart->add(new BuyableProduct([
|
||||||
|
'name' => 'First item',
|
||||||
|
]), 1);
|
||||||
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
|
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
|
||||||
$cart->setDiscount('027c91341fd5cf4d2579b49c4b6a90da', 50);
|
$cart->setDiscount('027c91341fd5cf4d2579b49c4b6a90da', 50);
|
||||||
$this->assertEquals(50, $cartItem->discountRate);
|
$this->assertEquals(50, $cartItem->discountRate);
|
||||||
@@ -1208,7 +1343,10 @@ class CartTest extends TestCase
|
|||||||
public function can_set_cart_item_weight_and_calculate_total_weight()
|
public function can_set_cart_item_weight_and_calculate_total_weight()
|
||||||
{
|
{
|
||||||
$cart = $this->getCart();
|
$cart = $this->getCart();
|
||||||
$cart->add(new BuyableProduct(1, 'First item', 10.00, 250), 2);
|
$cart->add(new BuyableProduct([
|
||||||
|
'name' => 'First item',
|
||||||
|
'weight' => 250,
|
||||||
|
]), 2);
|
||||||
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
|
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
|
||||||
$cart->setDiscount('027c91341fd5cf4d2579b49c4b6a90da', 50);
|
$cart->setDiscount('027c91341fd5cf4d2579b49c4b6a90da', 50);
|
||||||
$this->assertEquals('500.00', $cart->weight(2));
|
$this->assertEquals('500.00', $cart->weight(2));
|
||||||
@@ -1232,7 +1370,10 @@ class CartTest extends TestCase
|
|||||||
$cart->instance($identifier);
|
$cart->instance($identifier);
|
||||||
$this->assertEquals('User1', $cart->currentInstance());
|
$this->assertEquals('User1', $cart->currentInstance());
|
||||||
|
|
||||||
$cart->add(new BuyableProduct(1, 'First item', 10.00, 250), 2);
|
$cart->add(new BuyableProduct([
|
||||||
|
'name' => 'First item',
|
||||||
|
'weight' => 250,
|
||||||
|
]), 2);
|
||||||
$this->assertItemsInCart(2, $cart);
|
$this->assertItemsInCart(2, $cart);
|
||||||
|
|
||||||
$cart->store($identifier);
|
$cart->store($identifier);
|
||||||
@@ -1248,7 +1389,9 @@ class CartTest extends TestCase
|
|||||||
{
|
{
|
||||||
$cart = $this->getCartDiscount(50);
|
$cart = $this->getCartDiscount(50);
|
||||||
|
|
||||||
$cart->add(new BuyableProductTrait(1, 'First item', 10.00), 2);
|
$cart->add(new BuyableProductTrait([
|
||||||
|
'name' => 'First item',
|
||||||
|
]), 2);
|
||||||
|
|
||||||
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
|
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
|
||||||
|
|
||||||
@@ -1271,7 +1414,9 @@ class CartTest extends TestCase
|
|||||||
// https://github.com/Crinsane/LaravelShoppingcart/issues/544
|
// https://github.com/Crinsane/LaravelShoppingcart/issues/544
|
||||||
$cart = $this->getCart();
|
$cart = $this->getCart();
|
||||||
|
|
||||||
$cart->add(new BuyableProductTrait(1, 'First item', 10.00), 0.5);
|
$cart->add(new BuyableProductTrait([
|
||||||
|
'name' => 'First item',
|
||||||
|
]), 0.5);
|
||||||
|
|
||||||
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
|
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
|
||||||
|
|
||||||
@@ -1304,8 +1449,13 @@ class CartTest extends TestCase
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$cart = $this->getCartDiscount(50);
|
$cart = $this->getCartDiscount(50);
|
||||||
$cart->add(new BuyableProduct(1, 'Item', 10.00), 1);
|
$cart->add(new BuyableProduct([
|
||||||
$cart->add(new BuyableProduct(2, 'Item 2', 10.00), 1);
|
'name' => 'Item',
|
||||||
|
]), 1);
|
||||||
|
$cart->add(new BuyableProduct([
|
||||||
|
'id' => 2,
|
||||||
|
'name' => 'Item 2',
|
||||||
|
]), 1);
|
||||||
$cart->store('test');
|
$cart->store('test');
|
||||||
|
|
||||||
Event::fakeFor(function () {
|
Event::fakeFor(function () {
|
||||||
@@ -1334,8 +1484,13 @@ class CartTest extends TestCase
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$cart = $this->getCartDiscount(50);
|
$cart = $this->getCartDiscount(50);
|
||||||
$cart->add(new BuyableProduct(1, 'Item', 10.00), 1);
|
$cart->add(new BuyableProduct([
|
||||||
$cart->add(new BuyableProduct(2, 'Item 2', 10.00), 1);
|
'name' => 'Item',
|
||||||
|
]), 1);
|
||||||
|
$cart->add(new BuyableProduct([
|
||||||
|
'id' => 2,
|
||||||
|
'name' => 'Item 2',
|
||||||
|
]), 1);
|
||||||
$cart->store('test');
|
$cart->store('test');
|
||||||
|
|
||||||
Event::fakeFor(function () {
|
Event::fakeFor(function () {
|
||||||
@@ -1362,9 +1517,20 @@ class CartTest extends TestCase
|
|||||||
|
|
||||||
$cart = $this->getCartDiscount(6);
|
$cart = $this->getCartDiscount(6);
|
||||||
|
|
||||||
$cartItem = $cart->add(new BuyableProduct(1, 'First item', 0.18929), 1000);
|
$cartItem = $cart->add(new BuyableProduct([
|
||||||
$cart->add(new BuyableProduct(2, 'Second item', 4.41632), 5);
|
'name' => 'First item',
|
||||||
$cart->add(new BuyableProduct(3, 'Third item', 0.37995), 25);
|
'price' => 0.18929,
|
||||||
|
]), 1000);
|
||||||
|
$cart->add(new BuyableProduct([
|
||||||
|
'id' => 2,
|
||||||
|
'name' => 'Second item',
|
||||||
|
'price' => 4.41632,
|
||||||
|
]), 5);
|
||||||
|
$cart->add(new BuyableProduct([
|
||||||
|
'id' => 3,
|
||||||
|
'name' => 'Third item',
|
||||||
|
'price' => 0.37995,
|
||||||
|
]), 25);
|
||||||
|
|
||||||
$cart->setGlobalTax(22);
|
$cart->setGlobalTax(22);
|
||||||
|
|
||||||
@@ -1381,7 +1547,10 @@ class CartTest extends TestCase
|
|||||||
$cart = $this->getCartDiscount(0);
|
$cart = $this->getCartDiscount(0);
|
||||||
config(['cart.calculator' => GrossPrice::class]);
|
config(['cart.calculator' => GrossPrice::class]);
|
||||||
|
|
||||||
$cartItem = $cart->add(new BuyableProduct(1, 'First item', 100), 2);
|
$cartItem = $cart->add(new BuyableProduct([
|
||||||
|
'name' => 'First item',
|
||||||
|
'price' => 100,
|
||||||
|
]), 2);
|
||||||
|
|
||||||
$cart->setGlobalTax(22);
|
$cart->setGlobalTax(22);
|
||||||
|
|
||||||
@@ -1397,9 +1566,20 @@ class CartTest extends TestCase
|
|||||||
|
|
||||||
$cart = $this->getCartDiscount(6);
|
$cart = $this->getCartDiscount(6);
|
||||||
|
|
||||||
$cartItem = $cart->add(new BuyableProduct(1, 'First item', 0.23093), 1000);
|
$cartItem = $cart->add(new BuyableProduct([
|
||||||
$cart->add(new BuyableProduct(2, 'Second item', 5.38791), 5);
|
'name' => 'First item',
|
||||||
$cart->add(new BuyableProduct(3, 'Third item', 0.46354), 25);
|
'price' => 0.23093,
|
||||||
|
]), 1000);
|
||||||
|
$cart->add(new BuyableProduct([
|
||||||
|
'id' => 2,
|
||||||
|
'name' => 'Second item',
|
||||||
|
'price' => 5.38791,
|
||||||
|
]), 5);
|
||||||
|
$cart->add(new BuyableProduct([
|
||||||
|
'id' => 3,
|
||||||
|
'name' => 'Third item',
|
||||||
|
'price' => 0.46354,
|
||||||
|
]), 25);
|
||||||
|
|
||||||
$cart->setGlobalTax(22);
|
$cart->setGlobalTax(22);
|
||||||
|
|
||||||
@@ -1492,7 +1672,10 @@ class CartTest extends TestCase
|
|||||||
{
|
{
|
||||||
$cart = $this->getCart();
|
$cart = $this->getCart();
|
||||||
|
|
||||||
$cart->add(new BuyableProduct(1, 'first item', $price = 1000), $qty = 5);
|
$cart->add(new BuyableProduct([
|
||||||
|
'name' => 'first item',
|
||||||
|
'price' => 1000,
|
||||||
|
]), $qty = 5);
|
||||||
$this->assertEquals(5000, $cart->priceTotalFloat());
|
$this->assertEquals(5000, $cart->priceTotalFloat());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1501,7 +1684,10 @@ class CartTest extends TestCase
|
|||||||
{
|
{
|
||||||
$cart = $this->getCart();
|
$cart = $this->getCart();
|
||||||
|
|
||||||
$cart->add(new BuyableProduct(1, 'first item', 1000), 5);
|
$cart->add(new BuyableProduct([
|
||||||
|
'name' => 'first item',
|
||||||
|
'price' => 1000,
|
||||||
|
]), 5);
|
||||||
$this->assertEquals('5,000.00', $cart->priceTotal());
|
$this->assertEquals('5,000.00', $cart->priceTotal());
|
||||||
$this->assertEquals('5,000.0000', $cart->priceTotal(4, '.', ','));
|
$this->assertEquals('5,000.0000', $cart->priceTotal(4, '.', ','));
|
||||||
}
|
}
|
||||||
@@ -1516,8 +1702,13 @@ class CartTest extends TestCase
|
|||||||
Event::fake();
|
Event::fake();
|
||||||
|
|
||||||
$cart = $this->getCart();
|
$cart = $this->getCart();
|
||||||
$cart->add(new BuyableProduct(1, 'Item', 10.00), 1);
|
$cart->add(new BuyableProduct([
|
||||||
$cart->add(new BuyableProduct(2, 'Item 2', 10.00), 1);
|
'name' => 'Item',
|
||||||
|
]), 1);
|
||||||
|
$cart->add(new BuyableProduct([
|
||||||
|
'id' => 2,
|
||||||
|
'name' => 'Item 2',
|
||||||
|
]), 1);
|
||||||
$cart->store($identifier = 'test');
|
$cart->store($identifier = 'test');
|
||||||
$cart->erase($identifier);
|
$cart->erase($identifier);
|
||||||
Event::assertDispatched('cart.erased');
|
Event::assertDispatched('cart.erased');
|
||||||
|
|||||||
@@ -3,43 +3,30 @@
|
|||||||
namespace Gloudemans\Tests\Shoppingcart\Fixtures;
|
namespace Gloudemans\Tests\Shoppingcart\Fixtures;
|
||||||
|
|
||||||
use Gloudemans\Shoppingcart\Contracts\Buyable;
|
use Gloudemans\Shoppingcart\Contracts\Buyable;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class BuyableProduct implements Buyable
|
class BuyableProduct extends Model implements Buyable
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var int|string
|
* The attributes that are mass assignable.
|
||||||
*/
|
|
||||||
private $id;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $name;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var float
|
|
||||||
*/
|
|
||||||
private $price;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var float
|
|
||||||
*/
|
|
||||||
private $weight;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* BuyableProduct constructor.
|
|
||||||
*
|
*
|
||||||
* @param int|string $id
|
* @var array
|
||||||
* @param string $name
|
|
||||||
* @param float $price
|
|
||||||
*/
|
*/
|
||||||
public function __construct($id = 1, $name = 'Item name', $price = 10.00, $weight = 0)
|
protected $fillable = [
|
||||||
{
|
'id',
|
||||||
$this->id = $id;
|
'name',
|
||||||
$this->name = $name;
|
'title',
|
||||||
$this->price = $price;
|
'description',
|
||||||
$this->weight = $weight;
|
'price',
|
||||||
}
|
'weight',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $attributes = [
|
||||||
|
'id' => 1,
|
||||||
|
'name' => 'Item name',
|
||||||
|
'price' => 10.00,
|
||||||
|
'weight' => 0,
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the identifier of the Buyable item.
|
* Get the identifier of the Buyable item.
|
||||||
|
|||||||
@@ -3,43 +3,30 @@
|
|||||||
namespace Gloudemans\Tests\Shoppingcart\Fixtures;
|
namespace Gloudemans\Tests\Shoppingcart\Fixtures;
|
||||||
|
|
||||||
use Gloudemans\Shoppingcart\Contracts\Buyable;
|
use Gloudemans\Shoppingcart\Contracts\Buyable;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class BuyableProductTrait implements Buyable
|
class BuyableProductTrait extends Model implements Buyable
|
||||||
{
|
{
|
||||||
use \Gloudemans\Shoppingcart\CanBeBought;
|
use \Gloudemans\Shoppingcart\CanBeBought;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int|string
|
* The attributes that are mass assignable.
|
||||||
*/
|
|
||||||
private $id;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $name;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var float
|
|
||||||
*/
|
|
||||||
private $price;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var float
|
|
||||||
*/
|
|
||||||
private $weight;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* BuyableProduct constructor.
|
|
||||||
*
|
*
|
||||||
* @param int|string $id
|
* @var array
|
||||||
* @param string $name
|
|
||||||
* @param float $price
|
|
||||||
*/
|
*/
|
||||||
public function __construct($id = 1, $name = 'Item name', $price = 10.00, $weight = 0)
|
protected $fillable = [
|
||||||
{
|
'id',
|
||||||
$this->id = $id;
|
'name',
|
||||||
$this->name = $name;
|
'title',
|
||||||
$this->price = $price;
|
'description',
|
||||||
$this->weight = $weight;
|
'price',
|
||||||
}
|
'weight',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $attributes = [
|
||||||
|
'id' => 1,
|
||||||
|
'name' => 'Item name',
|
||||||
|
'price' => 10.00,
|
||||||
|
'weight' => 0,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user