Download the PHP package mugenzo/laravel-shopping-cart without Composer
On this page you can find all versions of the php package mugenzo/laravel-shopping-cart. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mugenzo/laravel-shopping-cart
More information about mugenzo/laravel-shopping-cart
Files in mugenzo/laravel-shopping-cart
Package laravel-shopping-cart
Short Description Shopping cart for laravel
License MIT
Informations about the package laravel-shopping-cart
LaravelShoppingCart
Installation
Run the Composer require command from the Terminal:
composer require mugenzo/laravel-shopping-cart
Now you're ready to start using the shoppingcart in your application.
Table of Contents
Look at one of the following topics to learn more about LaravelShoppingCart
- Usage
- Collections
- Instances
- Models
Usage
The shoppingcart gives you the following methods to use:
Cart::add()
Adding an item to the cart is really simple, you just use the add()
method, which accepts a variety of parameters.
In its most basic form you can specify the id, name, quantity, price and weight of the product you'd like to add to the cart.
As an optional fifth parameter you can pass it options, so you can add multiple items with the same id, but with (for instance) a different size.
The add()
method will return an CartItem instance of the item you just added to the cart.
Maybe you prefer to add the item using an array? As long as the array contains the required keys, you can pass it to the method. The options key is optional.
Cart::update()
To update an item in the cart, you'll first need the rowId of the item.
Next you can use the update()
method to update it.
If you simply want to update the quantity, you'll pass the update method the rowId and the new quantity:
If you would like to update options of an item inside the cart,
Cart::remove()
To remove an item for the cart, you'll again need the rowId. This rowId you simply pass to the remove()
method and it will remove the item from the cart.
Cart::get()
If you want to get an item from the cart using its rowId, you can simply call the get()
method on the cart and pass it the rowId.
Cart::content()
Of course you also want to get the carts content. This is where you'll use the content
method. This method will return a Collection of CartItems which you can iterate over and show the content to your customers.
Cart::destroy()
Cart::total()
The total()
method can be used to get the calculated total of all items in the cart, given there price and quantity.
Cart::discount()
The discount()
method can be used to get the total discount of all items in the cart.
Cart::initial()
The initial()
method can be used to get the total price of all items in the cart before applying discount.
Cart::count()
If you want to know how many items there are in your cart, you can use the count()
method. This method will return the total number of items in the cart. So if you've added 2 books and 1 shirt, it will return 3 items.
Cart::search()
To find an item in the cart, you can use the search()
method.
Cart::setDiscount($type, $value)
You can use the setDiscount()
method to change the discount type and value that applies to Cart.
Configuration
If you want to change Cart options, you'll have to publish the config
file.
php artisan vendor:publish --provider="Mugenzo\LaravelShoppingCart\ShoppingCartServiceProvider" --tag="config"
This will give you a shopping_cart_config.php
config file in which you can make the changes.
All versions of laravel-shopping-cart with dependencies
illuminate/session Version 5.4.*||5.5.*||5.6.*||5.7.*||5.8.*||^6.0||^7.0
illuminate/events Version 5.4.*||5.5.*||5.6.*||5.7.*||5.8.*||^6.0||^7.0
nesbot/carbon Version ~1.20||^1.26.3||^2.0
ext-json Version *