PHP code example of cyvelnet / laravel-easycart

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

    

cyvelnet / laravel-easycart example snippets


Cyvelnet\EasyCart\EasyCartServiceProvider::class,
 

// Add product to cart
EasyCart::add($id, $name, $price, $qty);

// Add product to cart with attributes & weight
EasyCart::add($id, $name, $price, $qty, $attributes = [], $weight);

// Add multiple products
EasyCart::add([
    [
        'id' => '1'
        'name' => 'Product 1'
        'price' => '199.99'
        'qty' => '1',
        'attributes' => ['color' => 'red'],
        'weight' => 0.5
    ],
    [
        'id' => '2'
        'name' => 'Product 2'
        'price' => '299.99'
        'qty' => '1'
    ]
]);

 

// update qty
EasyCart::update($rowId, $qty);

// update other 
EasyCart::update($rowId, [

    'attributes' => ['color' => 'green'],
    'qty' => 2,
    'price' => 399.99
    
]);



EasyCart::remove($rowId);



EasyCart::get($rowId);



EasyCart::destroy();

 

EasyCart::qty();

 

EasyCart::subtotal();

 

EasyCart::total();

 

EasyCart::items()

 

EasyCart::weight()

 

EasyCart::find($id);

 

EasyCart::findByIds($ids = []);

 
// Add a 50% discount to cart

$fiftyPercentDiscount = new CartCondition($name = '$50 Off', $value = '-50') // you have to use a - (minus sign) to indicate a discount is expected

EasyCart::condition($fiftyPercentDiscount);

 

$fiftyPercentDiscount = new CartCondition($name = '$50 Off', $value = '-50');
$fiftyPercentDiscount->onProduct([1,2,3,4]);

EasyCart::condition($fiftyPercentDiscount);

 

$fiftyPercentDiscount = new CartCondition($name = '20% Off', $value = '-20');
$fiftyPercentDiscount->maxAt(50);

EasyCart::condition($fiftyPercentDiscount);

 

EasyCart::removeConditionByType($type);

 

EasyCart::removeConditionByName($name);

 

EasyCart::instance('wishlist')->add($id, $name, $price, $qty);
EasyCart::instance('wishlist')->destroy();

 

// create a new instances with 15 minutes expiration
EasyCart::instance('reservation', \Carbon::now()->addMinutes(15));

 

EasyCart::instance('reservation')->expirationTimestamp();

 php 

// check if a cart is expired
EasyCart::instance('reservation')->isExpired();