Updated readme with syntax highlighting

This commit is contained in:
Rob Gloudemans
2013-05-30 17:13:16 +02:00
parent fd7fe0a617
commit e0fc3f0145

View File

@@ -2,10 +2,12 @@
Install the package through [Composer](http://getcomposer.org/). Edit your project's `composer.json` file by adding: Install the package through [Composer](http://getcomposer.org/). Edit your project's `composer.json` file by adding:
```php
"require": { "require": {
"laravel/framework": "4.0.*", "laravel/framework": "4.0.*",
"gloudemans/shoppingcart": "dev-master" "gloudemans/shoppingcart": "dev-master"
} }
```
Next, run the Composer update command from the Terminal: Next, run the Composer update command from the Terminal:
@@ -45,6 +47,7 @@ Cart::add('293ad', 'Product 1', 1, 9.99, array('size' => 'large'));
**Cart::addBatch()** **Cart::addBatch()**
```php
/** /**
* Add multiple rows to the cart * Add multiple rows to the cart
* *
@@ -55,9 +58,11 @@ Cart::add('293ad', 'Product 1', 1, 9.99, array('size' => 'large'));
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'))
)); ));
```
**Cart::update()** **Cart::update()**
```php
/** /**
* Update the quantity of one row of the cart * Update the quantity of one row of the cart
* *
@@ -72,9 +77,11 @@ Cart::add('293ad', 'Product 1', 1, 9.99, array('size' => 'large'));
OR OR
Cart::update($rowId, array('name' => 'Product 1')); Cart::update($rowId, array('name' => 'Product 1'));
```
**Cart::remove()** **Cart::remove()**
```php
/** /**
* Remove a row from the cart * Remove a row from the cart
* *
@@ -85,9 +92,11 @@ Cart::add('293ad', 'Product 1', 1, 9.99, array('size' => 'large'));
$rowId = 'da39a3ee5e6b4b0d3255bfef95601890afd80709'; $rowId = 'da39a3ee5e6b4b0d3255bfef95601890afd80709';
Cart::remove($rowId); Cart::remove($rowId);
```
**Cart::get()** **Cart::get()**
```php
/** /**
* Get a row of the cart by its ID * Get a row of the cart by its ID
* *
@@ -98,9 +107,11 @@ Cart::add('293ad', 'Product 1', 1, 9.99, array('size' => 'large'));
$rowId = 'da39a3ee5e6b4b0d3255bfef95601890afd80709'; $rowId = 'da39a3ee5e6b4b0d3255bfef95601890afd80709';
Cart::get($rowId); Cart::get($rowId);
```
**Cart::content()** **Cart::content()**
```php
/** /**
* Get the cart content * Get the cart content
* *
@@ -108,9 +119,11 @@ Cart::add('293ad', 'Product 1', 1, 9.99, array('size' => 'large'));
*/ */
Cart::content(); Cart::content();
```
**Cart::destroy()** **Cart::destroy()**
```php
/** /**
* Empty the cart * Empty the cart
* *
@@ -118,9 +131,11 @@ Cart::add('293ad', 'Product 1', 1, 9.99, array('size' => 'large'));
*/ */
Cart::destroy(); Cart::destroy();
```
**Cart::total()** **Cart::total()**
```php
/** /**
* Get the price total * Get the price total
* *
@@ -128,9 +143,11 @@ Cart::add('293ad', 'Product 1', 1, 9.99, array('size' => 'large'));
*/ */
Cart::total(); Cart::total();
```
**Cart::count()** **Cart::count()**
```php
/** /**
* Get the number of items in the cart * Get the number of items in the cart
* *
@@ -140,6 +157,7 @@ Cart::add('293ad', 'Product 1', 1, 9.99, array('size' => 'large'));
Cart::count(); // Total items Cart::count(); // Total items
Cart::count(false); // Total rows Cart::count(false); // Total rows
```
## Collections ## Collections
@@ -156,6 +174,7 @@ If you want to switch instances, you just call `Cart::instance('otherInstance')`
So a little example: So a little example:
```php
Cart::instance('shopping')->add('192ao12', 'Product 1', 1, 9.99); Cart::instance('shopping')->add('192ao12', 'Product 1', 1, 9.99);
// Get the content of the 'shopping' cart // Get the content of the 'shopping' cart
@@ -171,6 +190,7 @@ So a little example:
// 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.
@@ -180,6 +200,7 @@ N.B.2 The default cart instance is called `main`, so when you're not using insta
Below is a little example of how to list the cart content in a table: Below is a little example of how to list the cart content in a table:
```php
// Controller // Controller
Cart::add('192ao12', 'Product 1', 1, 9.99); Cart::add('192ao12', 'Product 1', 1, 9.99);
@@ -215,3 +236,4 @@ Below is a little example of how to list the cart content in a table:
</tbody> </tbody>
</table> </table>
```