PHP code example of tomshaw / shopcart

1. Go to this page and download the library: Download tomshaw/shopcart library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tomshaw / shopcart example snippets


use TomShaw\ShopCart\{Cart, CartItem};

$cartItem = CartItem::make(id: $product->id, name: $product->name, quantity: 1, price: $product->price);

Cart::add($cartItem);

$cartItem = CartItem::make($product->id, $product->name, 1, $product->price);

$cartItem->size = 'XL';
$cartItem->logo = 'Laravel Rocks';

Cart::add($cartItem);

$cartItem = Cart::where('id', '===', $id)->first();

$cartItem->quantity = 5;
$cartItem->size = '2XL';

Cart::update($cartItem);

Cart::remove(Cart::get($rowId));

Cart::forget();

$totalPrice = Cart::total('price');

$totalQuantity = Cart::total(property: 'quantity', numberFormat: false);

$subTotal = Cart::total('subtotal');

$totalTax = Cart::total('tax');

use TomShaw\ShopCart\{Cart, CartItem};

Cart::add(CartItem::make(tax: 6.250, ...));

$cartItem = Cart::get($rowId);

$boolean = Cart::has($rowId);

$cartItems = Cart::all(bool $toArray = false);

$cartItems = Cart::where('id', '===', $productId);

Cart::isEmpty();

Cart::isNotEmpty();

Cart::toArray();

Cart::toJson();

php artisan vendor:publish --provider="TomShaw\ShopCart\Providers\ShopCartServiceProvider" --tag=config