PHP code example of itemvirtual / ecommerce-cart

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

    

itemvirtual / ecommerce-cart example snippets


'EcommerceCart' => Itemvirtual\EcommerceCart\Facades\EcommerceCart::class,

use Itemvirtual\EcommerceCart\Facades\EcommerceCart;

EcommerceCart::addToCart([
    'id' => $Product->id,
    'title' => $Product->name,
    'price' => floatval($Product->price),
    'tax' => 21.0,
    'amount' => 1,
    'data' => [ // add your custom data here
        'tax_id' => 1
    ]
]);

EcommerceCart::incrementCartItem($Product->id);
EcommerceCart::decrementCartItem($Product->id);

EcommerceCart::removeCartItem($Product->id);

EcommerceCart::setTax($float);

EcommerceCart::setCustomCartData('tax', floatval($tax));

EcommerceCart::updateCartItemsDataValue($key, $value);
// EcommerceCart::updateCartItemsDataValue('tax_id', 1);

EcommerceCart::setApplyTax($boolean);

$cartItems = EcommerceCart::getItems();

EcommerceCart::getTotal();
EcommerceCart::getSubtotal();
// return taxes array
EcommerceCart::getTaxTotals();
// return total tax amount
EcommerceCart::getTaxTotalValue();

// Get total without shipping
EcommerceCart::getTotalWithoutShipping();

$ShippingData = [
    'id' => $Shipping->id,
    'title' => $Shipping->title,
    'value' => $Shipping->value,
    'free_from' => $Shipping->free_from,
];
EcommerceCart::setShipping($ShippingData);

EcommerceCart::removeShipping();

EcommerceCart::getShipping();

// Returns an object with 4 or 5 properties
{
  +"id": 3
  +"title": "Europe"
  +"value": 10
  +"free_from": 200
  +"free": true
}

$cartItems = EcommerceCart::getItems();

EcommerceCart::hasItems();
EcommerceCart::countItems();


EcommerceCart::destroyCart();
 bash
php artisan vendor:publish --provider="Itemvirtual\EcommerceCart\EcommerceCartServiceProvider" --tag=config