haskadavid / laravel-cart by haska

Laravel cart package
14
3
3
Package Data
Maintainer Username: haska
Maintainer Contact: david.haska@seznam.cz (David Haska)
Package Create Date: 2014-05-24
Package Last Update: 2014-05-25
Language: PHP
License: MIT
Last Refreshed: 2024-04-29 15:06:21
Package Statistics
Total Downloads: 14
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 3
Total Watchers: 3
Total Forks: 2
Total Open Issues: 0

Laravel cart package

Informations

Provider:

'Haska\Cart\CartServiceProvider',

Alias:

'Cart' => 'Haska\Cart\Facade',

Config:

php artisan config:publish haska:laravel-cart

Examples:

Insert

// Format array of required info for item to be added to cart...
$items = array(
	'id' => 1,
	'name' => 'Product name',
	'price' => 120.00,
	'quantity' => 1
);

// Make the insert...
Cart::insert($items);

Insert with tax rate (in this example 20%)

Cart::insert(array(
    'id'       => 'foo',
    'name'     => 'bar',
    'price'    => 100,
    'quantity' => 1,
    'tax'      => 20
));

Updating items in the cart

foreach (Cart::contents() as $item) {
    $item->name = 'Foo';
    $item->quantity = 1;
}

Removing items in the cart

foreach (Cart::contents() as $item) {
    $item->remove();
}

Destroying/emptying the cart

Cart::destroy()

Retrieve the cart contents

Cart::contents();

Content passed like an array

Cart::contents(true);

Retrieving the total items in the cart

Cart::totalItems();

Get only unique items

Cart::totalItems(true);

Retrieving the cart total

Cart::total();

Passed without tax rates

Cart::total(false);

Check if the cart has an item

Cart::has($id);

Retreive an item object by identifier

$item = Cart::item($id);

Cart items (item objects)

Retrieving the total value of an item

$item->total();

Without tax rates

$item->total(false);

Check if an item has options

if ($item->hasOptions()) {
    // We have options
}

Remove an item from the cart

$item->remove();

Output the item data as an array

$item->toArray();