mirror of
https://github.com/kevin-DL/LaravelShoppingcart.git
synced 2026-01-24 07:55:35 +00:00
Updated Cart::update() method so you can also update the 'options', also added unit test for it
This commit is contained in:
@@ -264,7 +264,15 @@ class Cart {
|
|||||||
|
|
||||||
foreach($attributes as $key => $value)
|
foreach($attributes as $key => $value)
|
||||||
{
|
{
|
||||||
$row->put($key, $value);
|
if($key == 'options')
|
||||||
|
{
|
||||||
|
$options = $row->options->merge($value);
|
||||||
|
$row->put($key, $options);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$row->put($key, $value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ! is_null(array_keys($attributes, array('qty', 'price'))))
|
if( ! is_null(array_keys($attributes, array('qty', 'price'))))
|
||||||
|
|||||||
@@ -57,6 +57,18 @@ class CartTest extends TestCase {
|
|||||||
$this->assertInstanceOf('Gloudemans\Shoppingcart\CartCollection', Cart::content());
|
$this->assertInstanceOf('Gloudemans\Shoppingcart\CartCollection', Cart::content());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCartCanUpdateOptionsAttribute()
|
||||||
|
{
|
||||||
|
Cart::add(1, 'test', 1, 10.00, ['size' => 'L']);
|
||||||
|
|
||||||
|
$rowId = Cart::content()->first()->rowid;
|
||||||
|
|
||||||
|
Cart::update($rowId, ['options' => ['color' => 'yellow']]);
|
||||||
|
|
||||||
|
$this->assertEquals(Cart::get($rowId)->options, new Gloudemans\Shoppingcart\CartRowOptionsCollection(['size' => 'L', 'color' => 'yellow']));
|
||||||
|
$this->assertInstanceOf('Gloudemans\Shoppingcart\CartRowOptionsCollection', Cart::get($rowId)->options);
|
||||||
|
}
|
||||||
|
|
||||||
public function testCartCanRemove()
|
public function testCartCanRemove()
|
||||||
{
|
{
|
||||||
Cart::add(1, 'test', 1, 10.00, ['size' => 'L']);
|
Cart::add(1, 'test', 1, 10.00, ['size' => 'L']);
|
||||||
|
|||||||
Reference in New Issue
Block a user