mirror of
https://github.com/kevin-DL/LaravelShoppingcart.git
synced 2026-01-11 18:54:33 +00:00
Updated readme with syntax highlighting
This commit is contained in:
22
README.md
22
README.md
@@ -2,10 +2,12 @@
|
||||
|
||||
Install the package through [Composer](http://getcomposer.org/). Edit your project's `composer.json` file by adding:
|
||||
|
||||
```php
|
||||
"require": {
|
||||
"laravel/framework": "4.0.*",
|
||||
"gloudemans/shoppingcart": "dev-master"
|
||||
}
|
||||
```
|
||||
|
||||
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()**
|
||||
|
||||
```php
|
||||
/**
|
||||
* 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' => '4832k', 'name' => 'Product 2', 'qty' => 1, 'price' => 10.00, 'options' => array('size' => 'large'))
|
||||
));
|
||||
```
|
||||
|
||||
**Cart::update()**
|
||||
|
||||
```php
|
||||
/**
|
||||
* 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
|
||||
|
||||
Cart::update($rowId, array('name' => 'Product 1'));
|
||||
```
|
||||
|
||||
**Cart::remove()**
|
||||
|
||||
```php
|
||||
/**
|
||||
* Remove a row from the cart
|
||||
*
|
||||
@@ -85,9 +92,11 @@ Cart::add('293ad', 'Product 1', 1, 9.99, array('size' => 'large'));
|
||||
$rowId = 'da39a3ee5e6b4b0d3255bfef95601890afd80709';
|
||||
|
||||
Cart::remove($rowId);
|
||||
```
|
||||
|
||||
**Cart::get()**
|
||||
|
||||
```php
|
||||
/**
|
||||
* 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';
|
||||
|
||||
Cart::get($rowId);
|
||||
```
|
||||
|
||||
**Cart::content()**
|
||||
|
||||
```php
|
||||
/**
|
||||
* Get the cart content
|
||||
*
|
||||
@@ -108,9 +119,11 @@ Cart::add('293ad', 'Product 1', 1, 9.99, array('size' => 'large'));
|
||||
*/
|
||||
|
||||
Cart::content();
|
||||
```
|
||||
|
||||
**Cart::destroy()**
|
||||
|
||||
```php
|
||||
/**
|
||||
* Empty the cart
|
||||
*
|
||||
@@ -118,9 +131,11 @@ Cart::add('293ad', 'Product 1', 1, 9.99, array('size' => 'large'));
|
||||
*/
|
||||
|
||||
Cart::destroy();
|
||||
```
|
||||
|
||||
**Cart::total()**
|
||||
|
||||
```php
|
||||
/**
|
||||
* Get the price total
|
||||
*
|
||||
@@ -128,9 +143,11 @@ Cart::add('293ad', 'Product 1', 1, 9.99, array('size' => 'large'));
|
||||
*/
|
||||
|
||||
Cart::total();
|
||||
```
|
||||
|
||||
**Cart::count()**
|
||||
|
||||
```php
|
||||
/**
|
||||
* 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(false); // Total rows
|
||||
```
|
||||
|
||||
## Collections
|
||||
|
||||
@@ -156,6 +174,7 @@ If you want to switch instances, you just call `Cart::instance('otherInstance')`
|
||||
|
||||
So a little example:
|
||||
|
||||
```php
|
||||
Cart::instance('shopping')->add('192ao12', 'Product 1', 1, 9.99);
|
||||
|
||||
// Get the content of the 'shopping' cart
|
||||
@@ -171,6 +190,7 @@ So a little example:
|
||||
|
||||
// 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.
|
||||
|
||||
@@ -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:
|
||||
|
||||
```php
|
||||
// Controller
|
||||
|
||||
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>
|
||||
</table>
|
||||
```
|
||||
Reference in New Issue
Block a user