Skip to content
This repository has been archived by the owner on Jan 17, 2024. It is now read-only.

juliobitencourt/laravel-cart

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

Code Climate

A lightweight PHP Shopping Cart for Laravel 5.

Installation

With Composer

$ composer require juliobitencourt/laravel-cart
{
    "require": {
        "juliobitencourt/laravel-cart": "1.0.*"
    }
}

Add the service provider to your app/config/app.php in the service providers array

'JulioBitencourt\Cart\CartServiceProvider',

Publish the resources

php artisan vendor:publish

Check the config/laravel-cart.php file. The storage-driver config can have the values Session (default) or Database.

In case you use Database as the storage driver you have to run the migrations

php artisan migrate

Usage

Inject the class into the constructor.

use JulioBitencourt\Cart\Cart;

class CartController extends Controller {

	protected $cart;

	public function __construct(Cart $cart)
	{
		$this->cart = $cart;
	}

Insert a new Item to the cart.

If you insert an item with the same SKU twice, the item quantity will be updated.

$item = [
	'sku' => '123456',
	'description' => 'PlayStation 4',
	'price' => 300,
	'quantity' => 1
];

$result = $this->cart->insert($item);

Insert a Child Item.

$item = [
	'sku' => '111111',
	'description' => '2 Year Protection',
	'price' => 30.50,
	'quantity' => 1
];

$result = $this->cart->insertChild($parentId, $item);

Update an item

If you update an item with 0 quantity, it will be removed from the cart's list of items

$result = $this->cart->update($id, $quantity);

Remove an item

$this->cart->delete($id);

Destroy the cart

$this->cart->destroy();

Checking if the cart is empty

$this->cart->isEmpty(); // Returns true or false

Returning an array with the list of items

$this->cart->all();

Count the total of items

$this->cart->totalItems();

Sum the cart total price

$this->cart->total();

Identify the cart with the e-mail.

This is useful if you want to implement abandoned cart recovery.

$this->cart->setEmail($email)

About

A lightweight PHP Shopping Cart for Laravel 5.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages