<commit_before>LaraCart
========

Laravel Cart package coded based on the Codeigniter Cart library

 * The used class was originally written by the team EllisLab Dev Team, then as I needed same 
 * class to use in laravel , I decided to modify this class and make it composer package for Laravel.
 *
 * I am also planning to add more features to this class such as
 * - Taxes 
 * - Coupons,
 * - Remove multiple items 
 * - Check if Item exists
 * - Cart SubTotal
 * - Cart Quantity : total number of items that are in the cart
 * - Cart seIdentity : Cart Identifier in case we want to use different Cart Identity in the same Session
 * - Cart getIdentity : the cart identifier.

## Introduction

The Cart package permits items to be added to a session that stays active while a user is browsing your site. These items can be retrieved and displayed in a standard "shopping cart" format, allowing the user to update the quantity or remove items from the cart.

Please note that the Cart package ONLY provides the core "cart" methodality. It does not provide shipping, credit card authorization, or other processing components.

Install this package through Composer. To your `composer.json` file, add:

```js
"require-dev": {
	"kamaro/cart": "dev-master"
}
```

Next, run `composer install --dev` to download it.

Finally, add the service provider to `app/config/app.php`, within the `providers` array.

```php
'providers' => array(
	// ...

	'Kamaro\Cart\CartServiceProvider'
)


'aliases' => array(
	// ...

	'Cart'=> 'Kamaro\Cart\Facades\Cart'
)
```

That's it! Run `php artisan` to view the three new Guard commands:

To add an item to the shopping cart, simply pass an array with the product information to the ```php  cart->insert() method, as shown below:

```php  
$data = array(
               'id'      => 'sku_123ABC',
               'qty'     => 1,
               'price'   => 39.95,
               'name'    => 'T-Shirt',
               'options' => array('Size' => 'L', 'Color' => 'Red')
            );

cart::insert($data);

```

Important: The first four array indexes above (id, qty, price, and name) are required. If you omit any of them the data will not be saved to the cart. The fifth index (options) is optional. It is intended to be used in cases where your product has options associated with it. Use an array for options, as shown above.
The five reserved indexes are:

id - Each product in your store must have a unique identifier. Typically this will be an "sku" or other such identifier.
qty - The quantity being purchased.
price - The price of the item.
name - The name of the item.
options - Any additional attributes that are needed to identify the product. These must be passed via an array.
In addition to the five indexes above, there are two reserved words: rowid and subtotal. These are used internally by the Cart class, so please do NOT use those words as index names when inserting data into the cart.

Your array may contain additional data. Anything you include in your array will be stored in the session. However, it is best to standardize your data among all your products in order to make displaying the information in a table easier.

The insert() method will return the $rowid if you successfully insert a single item.

## Adding Multiple Items to The Cart

By using a multi-dimensional array, as shown below, it is possible to add multiple products to the cart in one action. This is useful in cases where you wish to allow people to select from among several items on the same page.

```php  
$data = array(
               array(
                       'id'      => 'sku_123ABC',
                       'qty'     => 1,
                       'price'   => 39.95,
                       'name'    => 'T-Shirt',
                       'options' => array('Size' => 'L', 'Color' => 'Red')
                    ),
               array(
                       'id'      => 'sku_567ZYX',
                       'qty'     => 1,
                       'price'   => 9.95,
                       'name'    => 'Coffee Mug'
                    ),
               array(
                       'id'      => 'sku_965QRS',
                       'qty'     => 1,
                       'price'   => 29.95,
                       'name'    => '<NAME>'
                    )
            );

  cart::insert($data);
```

## Displaying the Cart

To display the cart you will create a view file with code similar to the one shown below.



## Updating The Cart

To update the information in your cart, you must pass an array containing the Row ID and quantity to the   
cart::update() method:

#### Note: If the quantity is set to zero, the item will be removed from the cart.

```php
$data = array(
               'rowid' => 'b99ccdf16028f015540f341130b6d8ec',
               'qty'   => 3
            );

cart::update($data); 
<commit_msg>Added update example in document<commit_after>LaraCart
========

Laravel Cart package coded based on the Codeigniter Cart library

 * The used class was originally written by the team EllisLab Dev Team, then as I needed same 
 * class to use in laravel , I decided to modify this class and make it composer package for Laravel.
 *
 * I am also planning to add more features to this class such as
 * - Taxes 
 * - Coupons,
 * - Remove multiple items 
 * - Check if Item exists
 * - Cart SubTotal
 * - Cart Quantity : total number of items that are in the cart
 * - Cart seIdentity : Cart Identifier in case we want to use different Cart Identity in the same Session
 * - Cart getIdentity : the cart identifier.

## Introduction

The Cart package permits items to be added to a session that stays active while a user is browsing your site. These items can be retrieved and displayed in a standard "shopping cart" format, allowing the user to update the quantity or remove items from the cart.

Please note that the Cart package ONLY provides the core "cart" methodality. It does not provide shipping, credit card authorization, or other processing components.

Install this package through Composer. To your `composer.json` file, add:

```js
"require-dev": {
	"kamaro/cart": "dev-master"
}
```

Next, run `composer install --dev` to download it.

Finally, add the service provider to `app/config/app.php`, within the `providers` array.

```php
'providers' => array(
	// ...

	'Kamaro\Cart\CartServiceProvider'
)


'aliases' => array(
	// ...

	'Cart'=> 'Kamaro\Cart\Facades\Cart'
)
```

That's it! Run `php artisan` to view the three new Guard commands:

To add an item to the shopping cart, simply pass an array with the product information to the ```php  cart->insert() method, as shown below:

```php  
$data = array(
               'id'      => 'sku_123ABC',
               'qty'     => 1,
               'price'   => 39.95,
               'name'    => 'T-Shirt',
               'options' => array('Size' => 'L', 'Color' => 'Red')
            );

cart::insert($data);

```

Important: The first four array indexes above (id, qty, price, and name) are required. If you omit any of them the data will not be saved to the cart. The fifth index (options) is optional. It is intended to be used in cases where your product has options associated with it. Use an array for options, as shown above.
The five reserved indexes are:

id - Each product in your store must have a unique identifier. Typically this will be an "sku" or other such identifier.
qty - The quantity being purchased.
price - The price of the item.
name - The name of the item.
options - Any additional attributes that are needed to identify the product. These must be passed via an array.
In addition to the five indexes above, there are two reserved words: rowid and subtotal. These are used internally by the Cart class, so please do NOT use those words as index names when inserting data into the cart.

Your array may contain additional data. Anything you include in your array will be stored in the session. However, it is best to standardize your data among all your products in order to make displaying the information in a table easier.

The insert() method will return the $rowid if you successfully insert a single item.

## Adding Multiple Items to The Cart

By using a multi-dimensional array, as shown below, it is possible to add multiple products to the cart in one action. This is useful in cases where you wish to allow people to select from among several items on the same page.

```php  
$data = array(
               array(
                       'id'      => 'sku_123ABC',
                       'qty'     => 1,
                       'price'   => 39.95,
                       'name'    => 'T-Shirt',
                       'options' => array('Size' => 'L', 'Color' => 'Red')
                    ),
               array(
                       'id'      => 'sku_567ZYX',
                       'qty'     => 1,
                       'price'   => 9.95,
                       'name'    => 'Coffee Mug'
                    ),
               array(
                       'id'      => 'sku_965QRS',
                       'qty'     => 1,
                       'price'   => 29.95,
                       'name'    => 'Shot Glass'
                    )
            );

  cart::insert($data);
```

## Displaying the Cart

To display the cart you will create a view file with code similar to the one shown below.

```html

{{ Form::open(array('url' => 'ath/to/route/to/update')) }}

<table cellpadding="6" cellspacing="1" style="width:100%" border="0">

<tr>
  <th>QTY</th>
  <th>Item Description</th>
  <th style="text-align:right">Item Price</th>
  <th style="text-align:right">Sub-Total</th>
</tr>

<?php $i = 1; ?>

@foreach ($this->cart->contents() as $items):

	 {{Form::text($i.'[rowid]', $items['rowid'])}}

	<tr>
	  <td>
	  	{{Form::text(array('name' => $i.'[qty]', 'value' => $items['qty'], 'maxlength' => '3', 'size' => '5'))}}</td>
	  <td>
		{{$items['name']}}

			@if (cart::has_options($items['rowid']) == TRUE):

				<p>
					@foreach (cart::product_options($items['rowid']) as $option_name => $option_value):

						<strong>{{$option_name}}:</strong> {{$option_value}} <br />

					@endforeach; ?>
				</p>

			@endif;

	  </td>
	  <td style="text-align:right">{{cart::format_number($items['price']);}}</td>
	  <td style="text-align:right">{{cart::format_number($items['subtotal']);}}</td>
	</tr>

<?php $i++; ?>

@endforeach;

<tr>
  <td colspan="2"> </td>
  <td class="right"><strong>Total</strong></td>
  <td class="right">{{cart::format_number(cart::total())}}</td>
</tr>

</table>

<p>{{Form::submit('Update your cart')}}</p>
{{ Form::close() }}

```


## Updating The Cart

To update the information in your cart, you must pass an array containing the Row ID and quantity to the   
cart::update() method:

#### Note: If the quantity is set to zero, the item will be removed from the cart.

```php
$data = array(
               'rowid' => 'b99ccdf16028f015540f341130b6d8ec',
               'qty'   => 3
            );

cart::update($data); 

{'fraction_non_alphanumeric': 0.11092940855819024, 'fraction_numerical': 0.010538748069410376, 'mean_word_length': 2.49127814779575, 'pattern_counts': {'":': 4, '<': 45, '<?xml version=': 0, '>': 110, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '158813', 'n_tokens_mistral': 3263, 'n_tokens_neox': 3021, 'n_words': 1358}