Download the PHP package ozanmuyes/laravel5cart without Composer
On this page you can find all versions of the php package ozanmuyes/laravel5cart. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ozanmuyes/laravel5cart
More information about ozanmuyes/laravel5cart
Files in ozanmuyes/laravel5cart
Informations about the package laravel5cart
Laravel 5 Cart
A Shopping Cart Implementation for Laravel Framework (Based on the impressive work of darryldecode)
Installation
Install the package through Composer. Edit your project's composer.json
file by adding:
Next, run the Composer update command from the Terminal:
composer update
or
composer update "ozanmuyes/cart"
Configuration
-
Open config/app.php and addd this line to your Service Providers Array
- Open config/app.php and addd this line to your Aliases
Table of Contents
- Usage
- Conditions
- Instances
- Exceptions
- Events
- Examples
- Changelogs
- License
Usage
Adding Item on Cart: Cart::add()
There are several ways you can add items on your cart, see below:
Updating an item on a cart: Cart::update()
Updating an item on a cart is very simple:
Removing an item on a cart: Cart::remove()
Removing an item on a cart is very easy:
Getting an item on a cart: Cart::get()
Getting cart's contents and count: Cart::getContent()
Check if cart is empty: Cart::isEmpty()
Get cart total quantity: Cart::getTotalQuantity()
Get cart subtotal: Cart::getSubTotal()
Get cart total: Cart::getTotal()
Clearing the Cart: Cart::clear()
Conditions
Laravel Shopping Cart supports cart conditions. Conditions are very useful in terms of (coupons,discounts,sale,per-item sale and discounts etc.) See below carefully on how to use conditions.
Conditions can be added on:
1.) Whole Cart Value bases
2.) Per-Item Bases
First let's add a condition on a Cart Bases:
There are also several ways of adding a condition on a cart: NOTE:
When adding a condition on a cart bases, the 'target' should have value of 'subtotal'. And when adding a condition on an item, the 'target' should be 'item'. The order of operation also during calculation will vary on the order you have added the conditions.
Also, when adding conditions, the 'value' field will be the bases of calculation.
NOTE: All cart based conditions should be applied before calling Cart::getTotal()
Then Finally you can call Cart::getTotal() to get the Cart Total with the applied conditions.
Next is the Condition on Per-Item Bases.
This is very useful if you have coupons to be applied specifically on an item and not on the whole cart value.
NOTE: When adding a condition on a per-item bases, the 'target' should have value of 'item'.
Now let's add condition on an item.
NOTE: All cart per-item conditions should be applied before calling Cart::getSubTotal()
Then Finally you can call Cart::getSubTotal() to get the Cart sub total with the applied conditions.
Add condition to exisiting Item on the cart: Cart::addItemCondition($productId, $itemCondition)
Adding Condition to an existing Item on the cart is simple as well.
This is very useful when adding new conditions on an item during checkout process like coupons and promo codes. Let's see the example how to do it:
Clearing Cart Conditions: Cart::clearCartConditions()
Remove Specific Cart Condition: Cart::removeCartCondition($conditionName)
Remove Specific Item Condition: Cart::removeItemCondition($itemId, $conditionName)
Get conditions by type: Cart::getConditionsByType($type)
Remove conditions by type: Cart::removeConditionsByType($type)
Instances
You may also want multiple cart instances on the same page without conflicts. To do that,
Create a new Service Provider and then on register() method, you can put this like so:
Exceptions
There are currently only two exceptions.
Exception | Description |
---|---|
InvalidConditionException | When there is an invalid field value during instantiating a new Condition |
InvalidItemException | When a new product has invalid field values (id,name,price,quantity) |
Events
The cart has currently 9 events you can listen and hook some actons.
Event | Fired |
---|---|
cart.created($cart) | When a cart is instantiated |
cart.adding($items, $cart) | When an item is attempted to be added |
cart.added($items, $cart) | When an item is added on cart |
cart.updating($items, $cart) | When an item is being updated |
cart.updated($items, $cart) | When an item is updated |
cart.removing($id, $cart) | When an item is being remove |
cart.removed($id, $cart) | When an item is removed |
cart.clearing($cart) | When a cart is attempted to be cleared |
cart.cleared($cart) | When a cart is cleared |
NOTE: If you have changed your application's namespace then correct the default namespace on published listeners.
Examples
Changelogs
**2.4.0
- added new method on a condition: $condition->getAttributes(); (Please see Conditions section)
**2.3.0
- added new Cart Method: Cart::addItemCondition($productId, $itemCondition)
- added new Cart Method: Cart::getTotalQuantity()
**2.2.1
- bug fixes
**2.2.0
- added new Cart Method: Cart::getConditionsByType($type)
- added new Item Method: Cart::removeConditionsByType($type)
**2.1.1
- when a new product with the same ID is added on a cart and a quantity is provided, it will increment its current quantity instead of overwriting it. There's a chance that you will also need to update an item's quantity but not incrementing it but reducing it, please just see the documentation (Please see Cart::update() section, and read carefully)
**2.1.0
- added new Cart Method: getCalculatedValue($totalOrSubTotalOrPrice)
- added new Item Method: getPriceSum()
**2.0.0 (breaking change)
- major changes in dealing with conditions (Please see Conditions section, and read carefully)
- All conditions added on per item bases should have now target => 'item' instead of 'subtotal'
- All conditions added on per cart bases should have now target => 'subtotal' instead of 'total'
**1.1.0
- added new method: clearCartConditions()
- added new method: removeItemCondition($itemId, $conditionName)
- added new method: removeCartCondition($conditionName)
License
The Laravel Shopping Cart is open-sourced software licensed under the MIT license
Disclaimer
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR, OR ANY OF THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
All versions of laravel5cart with dependencies
illuminate/support Version 5.0.x|5.1.x
illuminate/validation Version 5.0.x|5.1.x