Shopping cart component includes a fully intergratable shopping cart with lots of rich features.
Laravel 5.4 Support for version 0.2.0
To install through composer simply use the following command:
composer require mathewberry/cart
Next add
Cart` => \Mathewberry\Cart\Facades\Cart::class
to config/app.php
- Get the subtotal
- Get the total
- Get the delivery price
- Get the voucher price
- Get the quantity
- Get the cart total
- Add a product
- Add a voucher
- Check if the cart has a product
- Update the cart
- Remove an item from the cart
- Clear the cart
$product = Cart::get($product_id);
// Example
[
"id" => 24,
"price" => 99.99,
"quantity" => 2,
"options" => [...]
]
{{ $product['options']['name'] }} <small>{{ $product['options']['model'] }}</small><br>
<img src="{{ $product['options']['image'] }}">
<a href="{{ route('products', ['id' => $product['id']]) }}"><br>
$products = Cart::content();
// Example
[
[
"id" => 24,
"price" => 99.99,
"quantity" => 2,
"options" => [...]
],
[
"id" => 34,
"price" => 79.99,
"quantity" => 1,
"options" => [...]
]
]
// Return the total with shipping or voucher
Cart::subtotal();
/* DATABASE ROW
*
* Id: 24
* Name: 'My Product'
* Model: 'AAA900'
* Price: 99.99
*
*/
$product = \App\Models\Product::select(['id', 'model', 'price'])->find(24);
$product_id = $product->id;
$price = $product->price;
$quantity = 1;
// You may add any options you wish.
$options = [
'name' => $product->name,
'image' => asset('images/my-product-image.jpg'),
'model' => $product->model
];
Cart::add($product_id, $price, $quantity, $options)
// Returns the total of the cart
Cart::total();
// Returns the delivery cost
Cart::delivery();
// Example Data
$id = 24;
$code = "MB25OFF"; // 25% Off
$discount = 25.00; // 25%
$is_fixed = false; // Percentage
$display = '-' . number_format($discount, 2) . '%'; // How it should be displayed to the customer.
Cart::voucher($id, $code, $discount, $is_fixed, $display);
Cart::voucher();
[
"id" => $voucher_id, // Voucher id
"code" => $voucher_code, // Voucher code
"display" => $voucher_display, // Customer friendly, e.g: "25%"
"is_fixed" => $voucher_fixed, // Percentage voucher or fixed price
"discount" => $voucher_discount_value // Value of voucher
]
Code: {{ Cart::voucher()['code'] }}<br>
Deducted: {{ Cart::voucher()['display'] }}
// Returns true or false whether or not the product exists in the cart.
Cart::has($product_id);
// Calculates the product price times quantity.
Cart::sum($product_id);
// Return a list of all the products in the cart.
Cart::products();
// Add one to the current quantity
Cart::update($product_id);
// Custom quantity to add to existing quantity
Cart::update($product_id, $quantity);
// Remove a specific product from the cart.
Cart::remove($product_id);
// Clear the cart of ALL of it's data.
Cart::clear();