PHP code example of basketin / cart

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

    

basketin / cart example snippets




use Basketin\Component\Cart\Facades\CartManagement;

$cart = CartManagement::initCart('01HF7V7N1MG9SDFPQYWXDNHR9Q', 'USD'); // <- ULID



use Basketin\Component\Cart\Facades\CartManagement;

$cart = CartManagement::openCart('01HF7V7N1MG9SDFPQYWXDNHR9Q'); // <- ULID

$cart->getUlid();

$cart->getCurrency();

$cart->getCountProducts();

$cart->getCountItems();

// Product model


...
use Basketin\Component\Cart\Contracts\IQuote;
use Basketin\Component\Cart\Traits\HasQuote;
use Basketin\Component\Cart\Traits\HasTotal;

class Product extends Model implements IQuote
{
    use HasFactory;
    use HasQuote;
    use HasTotal;

    public function getOriginalPriceAttribute(): float
    {
        return (float) $this->price;
    }

    public function getSpecialPriceAttribute(): float|null
    {
        return null;
    }
}



use App\Models\Product;
use Basketin\Component\Cart\Facades\CartManagement;

$product = Product::first();

$cart = CartManagement::openCart('01HF7V7N1MG9SDFPQYWXDNHR9Q'); // <- ULID
$cart->quote()->addQuote($product, 1);



use App\Models\Product;
use Basketin\Component\Cart\Facades\CartManagement;

$product = Product::first();

$cart = CartManagement::openCart('01HF7V7N1MG9SDFPQYWXDNHR9Q'); // <- ULID
$cart->quote()->increaseQuote($product, 5);



use App\Models\Product;
use Basketin\Component\Cart\Facades\CartManagement;

$product = Product::first();

$cart = CartManagement::openCart('01HF7V7N1MG9SDFPQYWXDNHR9Q'); // <- ULID
$cart->quote()->decreaseQuote($product, 2);



use App\Models\Product;
use Basketin\Component\Cart\Facades\CartManagement;

$product = Product::first();

$cart = CartManagement::openCart('01HF7V7N1MG9SDFPQYWXDNHR9Q'); // <- ULID
$cart->quote()->hasQuote($product);



use App\Models\Product;
use Basketin\Component\Cart\Facades\CartManagement;

$product = Product::first();

$cart = CartManagement::openCart('01HF7V7N1MG9SDFPQYWXDNHR9Q'); // <- ULID
$cart->quote()->removeQuote($product);



use Basketin\Component\Cart\Facades\CartManagement;

$cart = CartManagement::initCart('01HF7V7N1MG9SDFPQYWXDNHR9Q'); // <- ULID
$cart->getCart();



use Basketin\Component\Cart\Facades\CartManagement;

$cart = CartManagement::initCart('01HF7V7N1MG9SDFPQYWXDNHR9Q'); // <- ULID
$cart->quote()->getQuotes();



use Basketin\Component\Cart\Facades\CartManagement;

$cart = CartManagement::initCart('01HF7V7N1MG9SDFPQYWXDNHR9Q'); // <- ULID
$totals = $cart->totals();
$totals->getSubTotal();
$totals->getDiscountTotal();
$totals->getGrandTotal();

$totals->setGlobalDiscountTotal(500.00)
    ->getGrandTotal();

use Illuminate\Database\Eloquent\Model;
use Basketin\Component\Cart\Contracts\ICoupon;

class Coupon extends Model implements ICoupon
{
    protected $fillable = [
        'coupon_name',
        'coupon_code',
        'discount_type',
        'discount_value',
        'start_at',
        'ends_at',
    ];

    public function discountType(): String
    {
        return $this->discount_type;
    }

    public function discountValue(): Int
    {
        return $this->discount_value;
    }
}

$coupon = Coupon::first();
$cart->coupon($coupon);

return $cart->fields()->set('key', 'value');

return $cart->fields()->get('key');

return $cart->fields()->remove('key');

return $cart->fields()->has('key');
bash
php artisan migrate --path=/vendor/basketin/cart/database/migrations
bash
php artisan vendor:publish --tag=basketin-cart-config