PHP code example of saasify / shopping-cart

1. Go to this page and download the library: Download saasify/shopping-cart 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/ */

    

saasify / shopping-cart example snippets


$cartItem = Cart::add($id, $name, $price, $quantity);
$cartItem = Cart::add($id, $name, $price, $quantity, [
    'color' => 'white',
]);

$cartItem = Cart::add($id, $name, $price, $quantity);

// ...

Cart::remove($cartItem->getUniqueId())

$cartItem = Cart::add($id, $name, $price, $quantity);

// ...

if (Cart::has($cartItem->getUniqueId())) {
    // Do smth.
}

$cartItem = Cart::add($id, $name, $price, $quantity);

// ...

$cartItem = Cart::get($cartItem->getUniqueId());

Cart::add(1, 'iPhone 7', 500, 1);
Cart::add(1, 'iPad Pro', 700, 2);
Cart::getTotal(); // return 1900

Cart::instance('shopping')->add('192ao12', 'Product 1', 100, 10);

// Store and get the content of the 'shopping' cart
Cart::store->content();

Cart::instance('wishlist')->add('sdjk922', 'Product 2', 50, 1, ['size' => 'medium']);

// Store and get the content of the 'wishlist' cart
Cart::store()->content();

// If you want to get the content of the 'shopping' cart again
Cart::instance('shopping')->restore()->content();

// config/cart.php

'repository' => \Saasify\Cart\Repositories\CartDatabaseRepository::class,
// or
'repository' => \Saasify\Cart\Repositories\CartRedisRepository::class,

Cart::store($user->id);
Cart::instance('cart')->store($user->id);
Cart::instance('wishlist')->store($user->id);

Cart::restore($user->id);
Cart::instance('cart')->restore($user->id);
Cart::instance('wishlist')->restore($user->id);

Cart::destroy($user->id);
Cart::instance('cart')->destroy($user->id);
Cart::instance('wishlist')->destroy($user->id);

Cart::addCoupon(new FixedDiscountCoupon($name, $discount));
Cart::addCoupon(new PercentDiscountCoupon($name, 0.1)); // 10% discount

Cart::add(1, 'iPhone 7', 500, 1);
Cart::add(1, 'iPad Pro', 700, 2);
Cart::addCoupon(new FixedDiscountCoupon($name, 300));
Cart::getTotal(); // return 1900 - 300 = 1600

php artisan vendor:publish --provider="Saasify\Cart\ServiceProvider"

php artisan migrate