Skip to content

Commit

Permalink
Merge pull request #16 from lukepolo/dev
Browse files Browse the repository at this point in the history
updating readme
  • Loading branch information
lukepolo committed Nov 8, 2015
2 parents 6c6454e + 4dce913 commit 461e50d
Showing 1 changed file with 55 additions and 29 deletions.
84 changes: 55 additions & 29 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
## LaraCart - Laravel 5.1 Shopping Cart Package
[![Latest Stable Version](https://poser.pugx.org/lukepolo/laracart/v/stable)](https://packagist.org/packages/lukepolo/laracart) [![Total Downloads](https://poser.pugx.org/lukepolo/laracart/downloads)](https://packagist.org/packages/lukepolo/laracart) [![Latest Unstable Version](https://poser.pugx.org/lukepolo/laracart/v/unstable)](https://packagist.org/packages/lukepolo/laracart) [![License](https://poser.pugx.org/lukepolo/laracart/license)](https://packagist.org/packages/lukepolo/laracart)

## !!WARNING!! Currently In Development
There are features that are incomplete and others that are not fully tested, please feel free to submit issues and enhancements

## Features
* Display Currency along with Locale
* Easy Session Base Usage
* Totals / SubTotals with taxes
* Items have locale and currency and tax separate from the cart
* Display Currency / Locale
* Easy Session Based Usage
* Taxation
* Multiple Cart Instances
* Unique Item Hash that is updated after every update to the item
* Option can have prices and are calculated in the totals and sub totals
* Coupons / Discounts
* Fees ex: delivery fees
* Price includes sub price attributes of items

## Installation

Expand All @@ -20,18 +18,21 @@ Install the package through [Composer](http://getcomposer.org/). Edit your proje
composer require lukepolo/laracart

Include Service Providers / Facade in `app/config/app.php`:

```php
LukePOLO\LaraCart\LaraCartServiceProvider::class,
```

Optionally include the Facade (suggested) :
Include the Facade :

```php
'LaraCart' => LukePOLO\LaraCart\Facades\LaraCart::class,
```

Copy over the configuration file by running the command :
```
php artisan vendor:publish

```
php artisan vendor:publish
```

Look through the configuration options and change as needed
Expand All @@ -40,19 +41,21 @@ Look through the configuration options and change as needed

* [Usage](#usage)
* [Instances](#instances)
* [Coupons](#coupons)
* [Fees](#fees)
* [Exceptions](#exceptions)
* [Events](#events)
* [Example](#example)


## Usage

Note : Because of the item hashing you must be careful how you update your items.Each change to an item will update its hash either continue to use the same item object or make sure to use the hash that is returned.

**Adding an Item to the cart**

```php
// First way we can just add like this
LaraCart::add(1, 'Burger', 5, 2.00, [
// Notice this is an array of arrays,
// Notice this is an array of arrays,
// this allows us to further expand the cart functions to the options
[
'Description' => 'Bacon',
Expand All @@ -72,6 +75,7 @@ Note : Because of the item hashing you must be careful how you update your items
```

**Cart Attributes**

```php
// Sometimes you want to give a cart some kind of attributes , such as labels
LaraCart::addAttribute('label', 'Luke's Cart');
Expand All @@ -84,47 +88,51 @@ Note : Because of the item hashing you must be careful how you update your items
```

**Updating an Items Attributes**

```php
LaraCart::updateItem($itemHash, 'name', 'CheeseBurger w/Bacon');
LaraCart::updateItem($itemHash, 'qty', 5);
LaraCart::updateItem($itemHash, 'price', '2.50');
```

**Removing an item**

```php
LaraCart::removeItem($itemHash);
```

**Empty / Destroying the Cart**

```php
// Empty will only empty the contents
LaraCart::emptyCart()

// Destroy will remove the entire instance of the cart including coupons ect.
LaraCart::destroyCart()
```

**Get the contents of the cart**
```php
LaraCart::getItems();
```

**Find a specific item in the cart**
```php
LaraCart::getItems();
LaraCart::findItem($itemHash);
```

**Gets the total number of items in the cart**

```php
LaraCart::count();
```

**Display Item Price with Locale**

```php
// $tax = false by default
$cartItem->getPrice($tax); // $24.23 | USD 24.23
$cartItem->getPrice($tax); // $24.23 | USD 24.23 depending on your settings
```

**Get the subtotal of the item**

```php
// $tax = false by default
$cartItem->subTotal($tax);
Expand All @@ -134,36 +142,43 @@ Note : Because of the item hashing you must be careful how you update your items
```

**Adding SubItems**

The reasoning behind sub items is to allow you add addiontal items without the all the nesscary thigns that a regular item needs. For instance if you really wanted the same item but in a differnt size and that size costs more, you can add it as a subitem so it caculates in the price.

```php
$cartItem->addSubItem([
'Description' => 'Fries',
'Price' => '.75'
]);
To update you can do on the item

To update you can do on the item
$cartItem->findSubItem($itemHash)->update('price') = 1.00;
```

**Get the Sub-Total of the cart** (This also includes the prices in the sub items and attributes!)
**Get the Sub-Total of the cart**

This also includes the prices in the sub items and attributes

```php
LaraCart::subTotal($tax = false, $formatted = true);
```
**Get the total of the cart**
```php
LaraCart::getTotalDiscount($formatted = false);
LaraCart::taxTotal($formatted = false);
LaraCart::total($formatted = false, $withDiscount = true);
```


## Instances
Instances is a way that we can use multiple carts within the same session. By using:

```php
LaraCart::setInstance('yourInstanceName');
```
Will switch to that instance of the cart. Each following request reuse the last instance of the cart set

## Coupons
Adding coupons could never be easier, currenlty there are a set of coupons inside LaraCart. To create new types of coupons just create a copy of one of the existing coupons and modifiy it!
````

```php
$coupon = new \LukePOLO\LaraCart\Coupons\Fixed($coupon->CouponCode, $coupon->CouponValue, [
'description' => $coupon->Description
]);
Expand All @@ -175,8 +190,19 @@ LaraCart::removeCoupon($code);

// Couppons themeslves also have nifty formatting options , for instance Fixed value coupons can have a money format
$fixedCoupon->getValue(); // $2.50
$percentCoupon->getValue; // 15%
````
$percentCoupon->getValue; // 15%
```

## Fees

Fees allow you to add extra charges to the cart for various reasons ex: delivery fees.

```php

LaraCart::addFee('deliveryFee', 5, $taxable = false, $options = []);
LaraCart::removeFee('deliveryFee');

```

## Exceptions
LaraCart packages can throw the following exceptions:
Expand Down

0 comments on commit 461e50d

Please sign in to comment.