This is where your description should go. Try and limit it to a paragraph or two, and maybe throw in a mention of what PSRs you support to avoid any confusion with users and contributors.
Install the package via composer:
composer require itemvirtual/ecommerce-cartPublish config (with --force option to update)
php artisan vendor:publish --provider="Itemvirtual\EcommerceCart\EcommerceCartServiceProvider" --tag=configYou can change the config values for cart_session_name and taxes_included:
#ECOMMERCE_CART_SESSION_NAME="ecommerceCart"
ECOMMERCE_TAXES_INCLUDED=true
ECOMMERCE_CALCULATE_TOTALS=trueAdd EcommerceCart to your config/app aliases array
'EcommerceCart' => Itemvirtual\EcommerceCart\Facades\EcommerceCart::class,Use the EcommerceCart Facade
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);The tax value is set for each item in the cart. To set a global tax value, use setCustomCartData()
It will not affect the calculation of totals on the cartItem, It only serves as data to calculate your totals.
EcommerceCart::setCustomCartData('tax', floatval($tax));If you save the tax_id value, you can change it with updateCartItemsDataValue()
EcommerceCart::updateCartItemsDataValue($key, $value);
// EcommerceCart::updateCartItemsDataValue('tax_id', 1);EcommerceCart::setApplyTax($boolean);If you need to calculate your Cart Totals, set ECOMMERCE_CALCULATE_TOTALS to false in your .env file
ECOMMERCE_CALCULATE_TOTALS=falseCreate your service and use EcommerceCart::getItems() to get your cart contents
$cartItems = EcommerceCart::getItems();EcommerceCart::getTotal();
EcommerceCart::getSubtotal();
// return taxes array
EcommerceCart::getTaxTotals();
// return total tax amount
EcommerceCart::getTaxTotalValue();
// Get total without shipping
EcommerceCart::getTotalWithoutShipping();Add Global shipping
$ShippingData = [
'id' => $Shipping->id,
'title' => $Shipping->title,
'value' => $Shipping->value,
'free_from' => $Shipping->free_from,
];
EcommerceCart::setShipping($ShippingData);Remove Shipping data
EcommerceCart::removeShipping();Get Shipping data
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();composer testPlease see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.