diff --git a/src/Gloudemans/Shoppingcart/Cart.php b/src/Gloudemans/Shoppingcart/Cart.php index 6bf7fb7..20aa877 100644 --- a/src/Gloudemans/Shoppingcart/Cart.php +++ b/src/Gloudemans/Shoppingcart/Cart.php @@ -264,7 +264,15 @@ class Cart { 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')))) diff --git a/tests/CartTest.php b/tests/CartTest.php index fbe5fa2..cfe6637 100644 --- a/tests/CartTest.php +++ b/tests/CartTest.php @@ -57,6 +57,18 @@ class CartTest extends TestCase { $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() { Cart::add(1, 'test', 1, 10.00, ['size' => 'L']);