Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
avrahamappel committed Nov 26, 2019
1 parent 73b84a0 commit 049aa16
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to `shopping-cart` will be documented in this file.

## 1.1.1 - 2019-11-26

Added `updateOption` method

## 1.1.0 - 2019-11-26

Added:
Expand Down
31 changes: 28 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,40 @@ Cart::remove($item->id);
```

### Options
To add item-specific options (such as size or color) to an item in the cart, simply pass an associative array as the third parameter of `Cart::add`.
To add item-specific options (such as size or color) to an item in the cart, first register available options in your `Buyable` instance.
```php
class Product extends Model implements Buyable
{
// ...

public function getOptions(): array
{
return [
'size' => ['18 inch', '36 inch'],
'color' => ['white', 'blue', 'black'],
];
}
}
```

Then you just pass an associative array as the third parameter of `Cart::add`.
```php
Cart::add($product, 3, ['color' => 'white'];
```
You can also add or change options of an item currently in the cart by calling `Cart::updateOptions`.
Any invalid options will be silently removed from the array.

You can also add or change options of an item currently in the cart by calling `Cart::updateOption`.
```php
$item = Cart:content()->first();

Cart::updateOptions($item->id, ['color' => 'black']);
// Update a single option
Cart::updateOption($item->id, 'color', 'black');

// Update multiple options at once
Cart::updateOptions($item->id, [
'color' => 'black',
'size' => '36 inch',
]);
```
The options array will be available on the `CartItem` instance as `$item->options`.

Expand Down

0 comments on commit 049aa16

Please sign in to comment.