diff --git a/README.md b/README.md index fb67b70..d468bcc 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,12 @@ Install the package through [Composer](http://getcomposer.org/). Edit your project's `composer.json` file by adding: - "require": { - "laravel/framework": "4.0.*", - "gloudemans/shoppingcart": "dev-master" - } +```php +"require": { + "laravel/framework": "4.0.*", + "gloudemans/shoppingcart": "dev-master" +} +``` Next, run the Composer update command from the Terminal: @@ -45,101 +47,117 @@ Cart::add('293ad', 'Product 1', 1, 9.99, array('size' => 'large')); **Cart::addBatch()** - /** - * Add multiple rows to the cart - * - * @param Array $items An array of items to add, use array keys corresponding to the 'add' method's parameters - */ - - Cart::addBatch(array( - array('id' => '293ad', 'name' => 'Product 1', 'qty' => 1, 'price' => 10.00), - array('id' => '4832k', 'name' => 'Product 2', 'qty' => 1, 'price' => 10.00, 'options' => array('size' => 'large')) - )); +```php +/** + * Add multiple rows to the cart + * + * @param Array $items An array of items to add, use array keys corresponding to the 'add' method's parameters + */ + +Cart::addBatch(array( + array('id' => '293ad', 'name' => 'Product 1', 'qty' => 1, 'price' => 10.00), + array('id' => '4832k', 'name' => 'Product 2', 'qty' => 1, 'price' => 10.00, 'options' => array('size' => 'large')) +)); +``` **Cart::update()** - /** - * Update the quantity of one row of the cart - * - * @param string $rowId The rowid of the item you want to update - * @param integer|Array $attribute New quantity of the item|Array of attributes to update - * @return boolean - */ - $rowId = 'da39a3ee5e6b4b0d3255bfef95601890afd80709'; - - Cart::update($rowId, 2); - - OR - - Cart::update($rowId, array('name' => 'Product 1')); +```php +/** + * Update the quantity of one row of the cart + * + * @param string $rowId The rowid of the item you want to update + * @param integer|Array $attribute New quantity of the item|Array of attributes to update + * @return boolean + */ + $rowId = 'da39a3ee5e6b4b0d3255bfef95601890afd80709'; + +Cart::update($rowId, 2); + +OR + +Cart::update($rowId, array('name' => 'Product 1')); +``` **Cart::remove()** - - /** - * Remove a row from the cart - * - * @param string $rowId The rowid of the item - * @return boolean - */ - - $rowId = 'da39a3ee5e6b4b0d3255bfef95601890afd80709'; - - Cart::remove($rowId); + +```php +/** + * Remove a row from the cart + * + * @param string $rowId The rowid of the item + * @return boolean + */ + + $rowId = 'da39a3ee5e6b4b0d3255bfef95601890afd80709'; + +Cart::remove($rowId); +``` **Cart::get()** - /** - * Get a row of the cart by its ID - * - * @param string $rowId The ID of the row to fetch - * @return CartRowCollection - */ - - $rowId = 'da39a3ee5e6b4b0d3255bfef95601890afd80709'; - - Cart::get($rowId); +```php +/** + * Get a row of the cart by its ID + * + * @param string $rowId The ID of the row to fetch + * @return CartRowCollection + */ + +$rowId = 'da39a3ee5e6b4b0d3255bfef95601890afd80709'; + +Cart::get($rowId); +``` **Cart::content()** - /** - * Get the cart content - * - * @return CartCollection - */ - - Cart::content(); +```php +/** + * Get the cart content + * + * @return CartCollection + */ + +Cart::content(); +``` **Cart::destroy()** - - /** - * Empty the cart - * - * @return boolean - */ - - Cart::destroy(); + +```php +/** + * Empty the cart + * + * @return boolean + */ + +Cart::destroy(); +``` **Cart::total()** - - /** - * Get the price total - * - * @return float - */ - - Cart::total(); + +```php +/** + * Get the price total + * + * @return float + */ + +Cart::total(); +``` **Cart::count()** - /** - * Get the number of items in the cart - * - * @param boolean $totalItems Get all the items (when false, will return the number of rows) - * @return int - */ - - Cart::count(); // Total items - Cart::count(false); // Total rows +```php +/** + * Get the number of items in the cart + * + * @param boolean $totalItems Get all the items (when false, will return the number of rows) + * @return int + */ + + Cart::count(); // Total items + Cart::count(false); // Total rows +``` ## Collections @@ -156,21 +174,23 @@ If you want to switch instances, you just call `Cart::instance('otherInstance')` So a little example: - Cart::instance('shopping')->add('192ao12', 'Product 1', 1, 9.99); +```php +Cart::instance('shopping')->add('192ao12', 'Product 1', 1, 9.99); - // Get the content of the 'shopping' cart - Cart::content(); +// Get the content of the 'shopping' cart +Cart::content(); - Cart::instance('wishlist')->add('sdjk922', 'Product 2', 1, 19.95, array('size' => 'medium')); +Cart::instance('wishlist')->add('sdjk922', 'Product 2', 1, 19.95, array('size' => 'medium')); - // Get the content of the 'wishlist' cart - Cart::content(); +// Get the content of the 'wishlist' cart +Cart::content(); - // If you want to get the content of the 'shopping' cart again... - Cart::instance('shopping')->content(); +// If you want to get the content of the 'shopping' cart again... +Cart::instance('shopping')->content(); - // And the count of the 'wishlist' cart again - Cart::instance('wishlist')->count(); +// And the count of the 'wishlist' cart again +Cart::instance('wishlist')->count(); +``` N.B. Keep in mind that the cart stays in the last set instance for as long as you don't set a different one during script execution. @@ -179,39 +199,41 @@ N.B.2 The default cart instance is called `main`, so when you're not using insta ## Example Below is a little example of how to list the cart content in a table: - - // Controller - Cart::add('192ao12', 'Product 1', 1, 9.99); - Cart::add('1239ad0', 'Product 2', 2, 5.95, array('size' => 'large')); +```php +// Controller - // View +Cart::add('192ao12', 'Product 1', 1, 9.99); +Cart::add('1239ad0', 'Product 2', 2, 5.95, array('size' => 'large')); -
| Product | -Qty | -Item Price | -Subtotal | -
|---|
| Product | +Qty | +Item Price | +Subtotal | +
|---|---|---|---|
|
- name;?> -options->has('size') ? $row->options->size : '');?> - |
- - | $price;?> | -$subtotal;?> | -
|
+ name;?> +options->has('size') ? $row->options->size : '');?> + |
+ + | $price;?> | +$subtotal;?> | +