Skip to content

baboot/laravel-cart

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cart package for laravel

Installation

Add provider to config/app.php file.

'providers' => [
    ...
    \Baboot\CartServiceProvider::class
];

Add alias to config/app.php file.

'aliases' => [
    ...
    'Cart' => \Baboot\Facades\Cart::class
];

Setup

Publishing config

php artisan vendor:publish

Import migrations

php artisan migrate

Specify model that beign used for adding to cart. For that, in model class insert trait and specify attributes. For example:

<?php

class Product extends  Illuminate\Database\Eloquent\Model
{
    use App\Package\src\Mixins\Cartable;

    protected $cart_price_arrtibute = 'price';
    protected $cart_item_id = 'id';
    
    ...
}

In this case Cart will used price attribute for price and id from attribute id. If price is aggregatable attribute you may specify an accessor of price attribute

Usage

init

First thing you need to do is init the cart:

\Cart::init($key)

where $key is a key for a cart for current user. You need to specify them dependings on your application rules. $key is a primary key varchar(12)

add

Adding item to cart

\Cart::add($model)

remove

Removing item to cart

\Cart::remove($model)

count

Count of all items in cart

\Cart::totalQuantity()

sub total

get total in cart without price modifacators(coupons)

\Cart::subTotal()

total

get total in cart with price modifacators(coupons)

\Cart::total()

change quantity

set quantity for a product

\Cart::setQuantity($model, $quantity)

Events

cart.inited

cart.action.added

cart.action.removed

cart.action.flush

cart.action.coupon.added

Storage

You can store cart in DB ot Redis. Specify CART_STORAGE var in your .env file, or change it config (cart.php) Also you can create your own driver(implementing Baboot\Contracts\Storage ) and add it in storageDrivers directive in config and use them.

About

Cart Module

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages