Updated README

This commit is contained in:
Rob Gloudemans
2013-07-09 15:16:24 +02:00
parent 5aa48468e2
commit 5097bf9314

View File

@@ -12,17 +12,17 @@ Install the package through [Composer](http://getcomposer.org/). Edit your proje
Next, run the Composer update command from the Terminal: Next, run the Composer update command from the Terminal:
composer update composer update
Now all you have to do is add the service provider of the package and alias the package. To do this open your `app/config/app.php` file. Now all you have to do is add the service provider of the package and alias the package. To do this open your `app/config/app.php` file.
Add a new line to the `service providers` array: Add a new line to the `service providers` array:
'\Gloudemans\Shoppingcart\ShoppingcartServiceProvider' '\Gloudemans\Shoppingcart\ShoppingcartServiceProvider'
And finally add a new line to the `aliases` array: And finally add a new line to the `aliases` array:
'Cart' => 'Gloudemans\Shoppingcart\Facades\Cart', 'Cart' => 'Gloudemans\Shoppingcart\Facades\Cart',
Now you're ready to start using the shoppingcart in your application. Now you're ready to start using the shoppingcart in your application.
## Usage ## Usage
@@ -34,29 +34,41 @@ The shoppingcart gives you the following methods to use:
```php ```php
/** /**
* Add a row to the cart * Add a row to the cart
* *
* @param string $id Unique ID of the item * @param string|Array $id Unique ID of the item|Item formated as array|Array of items
* @param string $name Name of the item * @param string $name Name of the item
* @param int $qty Item qty to add to the cart * @param int $qty Item qty to add to the cart
* @param float $price Price of one item * @param float $price Price of one item
* @param Array $options Array of additional options, such as 'size' or 'color' * @param Array $options Array of additional options, such as 'size' or 'color'
*/ */
// Basic form
Cart::add('293ad', 'Product 1', 1, 9.99, array('size' => 'large')); Cart::add('293ad', 'Product 1', 1, 9.99, array('size' => 'large'));
// Array form
Cart::add(array('id' => '293ad', 'name' => 'Product 1', 'qty' => 1, 'price' => 9.99, 'options' => array('size' => 'large')));
// Batch method
Cart::add(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::addBatch()** **Cart::addBatch()**
Don't use this anymore, just pass a multidimensional array to the `Cart::add()` method
```php ```php
/** /**
* Add multiple rows to the cart * 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 * @param Array $items An array of items to add, use array keys corresponding to the 'add' method's parameters
*/ */
Cart::addBatch(array( Cart::addBatch(array(
array('id' => '293ad', 'name' => 'Product 1', 'qty' => 1, 'price' => 10.00), 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')) array('id' => '4832k', 'name' => 'Product 2', 'qty' => 1, 'price' => 10.00, 'options' => array('size' => 'large'))
)); ));
``` ```
@@ -65,17 +77,17 @@ Cart::addBatch(array(
```php ```php
/** /**
* Update the quantity of one row of the cart * Update the quantity of one row of the cart
* *
* @param string $rowId The rowid of the item you want to update * @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 * @param integer|Array $attribute New quantity of the item|Array of attributes to update
* @return boolean * @return boolean
*/ */
$rowId = 'da39a3ee5e6b4b0d3255bfef95601890afd80709'; $rowId = 'da39a3ee5e6b4b0d3255bfef95601890afd80709';
Cart::update($rowId, 2); Cart::update($rowId, 2);
OR OR
Cart::update($rowId, array('name' => 'Product 1')); Cart::update($rowId, array('name' => 'Product 1'));
``` ```
@@ -84,31 +96,31 @@ Cart::update($rowId, array('name' => 'Product 1'));
```php ```php
/** /**
* Remove a row from the cart * Remove a row from the cart
* *
* @param string $rowId The rowid of the item * @param string $rowId The rowid of the item
* @return boolean * @return boolean
*/ */
$rowId = 'da39a3ee5e6b4b0d3255bfef95601890afd80709'; $rowId = 'da39a3ee5e6b4b0d3255bfef95601890afd80709';
Cart::remove($rowId); Cart::remove($rowId);
``` ```
**Cart::get()** **Cart::get()**
```php ```php
/** /**
* Get a row of the cart by its ID * Get a row of the cart by its ID
* *
* @param string $rowId The ID of the row to fetch * @param string $rowId The ID of the row to fetch
* @return CartRowCollection * @return CartRowCollection
*/ */
$rowId = 'da39a3ee5e6b4b0d3255bfef95601890afd80709'; $rowId = 'da39a3ee5e6b4b0d3255bfef95601890afd80709';
Cart::get($rowId); Cart::get($rowId);
``` ```
**Cart::content()** **Cart::content()**
```php ```php
@@ -119,8 +131,8 @@ Cart::get($rowId);
*/ */
Cart::content(); Cart::content();
``` ```
**Cart::destroy()** **Cart::destroy()**
```php ```php
@@ -129,22 +141,22 @@ Cart::content();
* *
* @return boolean * @return boolean
*/ */
Cart::destroy(); Cart::destroy();
``` ```
**Cart::total()** **Cart::total()**
```php ```php
/** /**
* Get the price total * Get the price total
* *
* @return float * @return float
*/ */
Cart::total(); Cart::total();
``` ```
**Cart::count()** **Cart::count()**
```php ```php
@@ -154,7 +166,7 @@ Cart::total();
* @param boolean $totalItems Get all the items (when false, will return the number of rows) * @param boolean $totalItems Get all the items (when false, will return the number of rows)
* @return int * @return int
*/ */
Cart::count(); // Total items Cart::count(); // Total items
Cart::count(false); // Total rows Cart::count(false); // Total rows
``` ```
@@ -164,14 +176,14 @@ Cart::total();
```php ```php
/** /**
* Search if the cart has a item * Search if the cart has a item
* *
* @param Array $search An array with the item ID and optional options * @param Array $search An array with the item ID and optional options
* @return Array|boolean * @return Array|boolean
*/ */
Cart::search(array('id' => 1, 'options' => array('size' => 'L'))); // Returns an array of rowid(s) of found item(s) or false on failure Cart::search(array('id' => 1, 'options' => array('size' => 'L'))); // Returns an array of rowid(s) of found item(s) or false on failure
``` ```
## Collections ## Collections
As you might have seen, the `Cart::content()` and `Cart::get()` methods both return a Collection, a `CartCollection` and a `CartRowCollection`. As you might have seen, the `Cart::content()` and `Cart::get()` methods both return a Collection, a `CartCollection` and a `CartRowCollection`.
@@ -204,7 +216,7 @@ Cart::instance('shopping')->content();
// And the count of the 'wishlist' cart again // And the count of the 'wishlist' cart again
Cart::instance('wishlist')->count(); 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. 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.
N.B.2 The default cart instance is called `main`, so when you're not using instances,`Cart::content();` is the same as `Cart::instance('main')->content()`. N.B.2 The default cart instance is called `main`, so when you're not using instances,`Cart::content();` is the same as `Cart::instance('main')->content()`.