ankurk91/laravel-shopping-cart

Shopping cart manager for Laravel

1.5.0 2024-03-07 15:25 UTC

This package is auto-updated.

Last update: 2024-11-27 11:40:04 UTC


README

Packagist GitHub-tag License Downloads GH-Actions codecov

Shopping cart manager for Laravel.

Installation

You can install the package via composer:

composer require "ankurk91/laravel-shopping-cart"

Usage

You can use Facade

<?php
use Ankurk91\LaravelShoppingCart\Facades\ShoppingCart;
use App\Models\Product;

$product = Product::find(1);
$quantity = request('quantity');
$attributes = [
    'image_url' => asset('image.webp'),
];
$item = ShoppingCart::add(
    $product, 
    $product->name,
    $product->unit_price,
    $quantity, 
    $attributes,
);

ShoppingCart::find(1);
ShoppingCart::update($product->id, 3);
ShoppingCart::all();
ShoppingCart::count();
ShoppingCart::has($product);
ShoppingCart::isEmpty();
ShoppingCart::subtotal();
ShoppingCart::remove($product->getKey());
ShoppingCart::clear();

Or you can locate it from container

<?php
use Ankurk91\LaravelShoppingCart;

$shoppingCart = app(ShoppingCartManager::class);
$shoppingCart->all();

Note The cart items will be stored in default session storage.

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

composer test

Security

If you discover any security issues, please email pro.ankurk1[at]gmail[dot]com instead of using the issue tracker.

Attribution

This package is highly inspired by overtrue/laravel-shopping-cart

License

The MIT License.