2017 © Pedro Peláez
 

library laravel-cart

A lightweight PHP Shopping Cart for Laravel 5.

image

juliobitencourt/laravel-cart

A lightweight PHP Shopping Cart for Laravel 5.

  • Saturday, October 10, 2015
  • by juliobitencourt
  • Repository
  • 3 Watchers
  • 36 Stars
  • 1,203 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 19 Forks
  • 4 Open issues
  • 3 Versions
  • 1 % Grown

The README.md

Build Status Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

Code Climate, (*2)

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, (*3)

'JulioBitencourt\Cart\CartServiceProvider',

Publish the resources, (*4)

php artisan vendor:publish

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

In case you use Database as the storage driver you have to run the migrations, (*6)

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., (*7)

$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, (*8)

$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., (*9)

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

The Versions

10/10 2015

dev-master

9999999-dev http://github.com/juliobitencourt/laravel-cart

A lightweight PHP Shopping Cart for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel cart

10/10 2015

v1.0.1

1.0.1.0 http://github.com/juliobitencourt/laravel-cart

A lightweight PHP Shopping Cart for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel cart

12/06 2015

1.0.0

1.0.0.0 http://github.com/juliobitencourt/laravel-cart

A lightweight PHP Shopping Cart for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel cart