Download the PHP package lachezargrigorov/laravel-shopping-cart without Composer
On this page you can find all versions of the php package lachezargrigorov/laravel-shopping-cart. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lachezargrigorov/laravel-shopping-cart
More information about lachezargrigorov/laravel-shopping-cart
Files in lachezargrigorov/laravel-shopping-cart
Package laravel-shopping-cart
Short Description An easy to use more advanced shopping cart for Laravel applications.
License MIT
Homepage https://github.com/lachezargrigorov/laravel-shopping-cart
Informations about the package laravel-shopping-cart
Laravel Shopping Cart
An easy to use more advanced shopping cart for Laravel applications.
Installation
Via Composer
Laravel 5.5 and above uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider and Facade to the array in config/app.php
If you don't use auto-discovery, add the CartServiceProvider to the providers array in config/app.php
If you want to use the Cart facade, add this to the aliases array in app.php:
Implement the Item interface in your product model. The Cart and Item uses getCartPrice method to calculate the totals.
Publish the package config to your local config with the publish command and configure them:
Set the item_class in local package config (cart.php)
Legend
Elements
- Cart : class Lachezargrigorov\Cart\Cart
- Item : class Lachezargrigorov\Cart\Item
- Condition : abstract class Lachezargrigorov\Cart\Condition;
- ItemCondition : class Lachezargrigorov\Cart\ItemCondition extends Condition
- CartCondition : class Lachezargrigorov\Cart\CartCondition extends Condition
Interfaces
- Item : interface Lachezargrigorov\Cart\Interfaces\Item
Collections
- LaravelCollection : class Illuminate\Support\Collection
- Collection : class Lachezargrigorov\Cart\Collections\Collection extends LaravelCollection
- ItemAttributesCollection : class Lachezargrigorov\Cart\Collections\ItemAttributesCollection extends Collection
- ConditionAttributesCollection : class Lachezargrigorov\Cart\Collections\ConditionAttributesCollection extends Collection
Exceptions
- CartException : class Lachezargrigorov\Cart\Exceptions\CartException
Usage`
Cart
Item
Add or get Item
This method add or get an Item if exist.
- $id : int - the id of the item (product) model
- return : Item
Models loading process
For better performance models are lazy associated to the items on first '$item->model' call after init or item addition in single DB request so you don't need to add any extra data like name, price, etc.
Remove Item
-return : removed Item
Get items
- return : LaravelCollection with Items
Has item (Item)
- id : int - the id of the item (product) model
- return : bool
Get items count
- return : int
Remove items (Item)
- ids : [] - array with ids
- return : Cart
Remove all cart items
- return : Cart
Is empty for items
- return : bool
Get item keys
- return : LaravelCollection with keys
Empty the item models
This will case the cart to reload the models on next model call.
- return : Cart
CartCondition
Add or get CartCondition
This method add or get an CartCondition if exist.
- name : condition name
- return : CartCondition
Add or set CartConditions as array
This will rewrite the existing conditions.
- return : Cart
Get conditions
- return : LaravelCollection with CartConditions
Has condition
- name : condition name
- return : bool
Get conditions count
- return : int
Remove conditions
- names : array - array with names
- return : Cart
Remove all cart conditions
- return : Cart
Is empty for conditions
- return : bool
Get condition keys (names)
- return : LaravelCollection with keys
Total methods
Get total quantity
- return : int
Get cart subtotal without applied ItemConditions and CartConditions
- return : double
Get cart subtotal without applied CartConditions
- return : double
Get cart total with applied ItemConditions and CartConditions
- return : double
Item
Properties
- id : int
- quantity : int
- attributes : ItemAttributesCollection
- conditions : LaravelCollection with ItemConditions
- model : Illuminate\Database\Eloquent\Model
Set quantity
- return : Item
Add quantity (current quantity + added quantity)
- return : Item
Get quantity
- return : int
Set attributes
- return : Item
Get attributes
- return : ItemAttributesCollection
Empty attributes (delete all attributes)
- return : Item
Add or get ItemCondition
- name : string - condition name
- return : ItemCondition
Add or set ItemConditions as array
This will rewrite the existing conditions.
- return : Item
Get conditions
- return : LaravelCollection with ItemConditions
Remove ItemCondition
return : removed ItemCondition
Has condition
- name : string - condition name
- return : bool
Does item contain any conditions
- return : bool
Empty conditions (remove all conditions)
- return : Item
Get model
- return : Illuminate\Database\Eloquent\Model
Price methods
Get price without applied conditions
-return : double
Get price sum without applied conditions (price * quantity)
-return : double
Get price with applied conditions
-return : double
Get price sum with applied conditions (price * quantity)
-return : double
Set helper
- [] : array - quantity : int (not required), add_quantity : int (not required), attributes : array (not required), conditions : array (not required)
- return : Item
Condition (CartCondition and ItemCondition)
Properties
- name : string - condition name and it's collection key are always the same
- type : string
- value : string - [+-]?[0-9]+(\.[0-9]+)?[%]? examples: +10%, 10%, 10.22% -10%, +10.11, -10.80
- attributes : ConditionAttributesCollection
Set name
This will change the key in collection too.
- name : string
- return : CartCondition | ItemCondition
Get name
- return : string
Set type
- type : string
- return : CartCondition | ItemCondition
Get type
- return : string
Set value
- value : string
- return : CartCondition | ItemCondition
Get value
- return : string
Set attributes
Merge existing attributes.
- attributes : array
- return : CartCondition | ItemCondition
Get attributes
- return : ConditionAttributesCollection
Empty attributes (delete all attributes)
- return : CartCondition | ItemCondition
Set helper
- [] : array - name : string (not required), type : string (not required), value : string (not required), attributes : array (not required)
- return : CartCondition | ItemCondition
Testing
Change log
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CODE_OF_CONDUCT for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-shopping-cart with dependencies
illuminate/support Version ^5.1
illuminate/database Version ^5.1
php Version ^5.6|^7.0