Download the PHP package foridom/laravel-shopping-cart without Composer
On this page you can find all versions of the php package foridom/laravel-shopping-cart. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download foridom/laravel-shopping-cart
More information about foridom/laravel-shopping-cart
Files in foridom/laravel-shopping-cart
Package laravel-shopping-cart
Short Description Shopping cart for Laravel Application.
License MIT
Informations about the package laravel-shopping-cart
购物车在电商场景中基本是必须的一个模块,本包是基于 overtrue/laravel-shopping-cart 进行扩展开发,主要实现了以下扩展:
- 购物车数据支持 Database 存储
- Item 增加 Model 属性返回。因为购物车可能是SPU或者SKU,因此直接通过 model 属性直接返回相关对象。
- 支持多 Guard. 因为在果酱小店中有商城购物车和导购购物车。
已经完成了 Session 和 Database 模式下的单元测试,而且正在果酱小店产品线上使用中. 可放心使用.
Installation
低于 Laravel5.5 版本
config/app.php
文件中 'providers' 添加
config/app.php
文件中 'aliases' 添加
Usage
Select Storage
You can change data Storage in config/ibrand/cart.php
file.
If you use Database Storage, you need to execute php artisan migrate
Add item to cart
Add a new item.
example:
Update item
Update the specified item.
example:
Get all items
Get all the items.
example:
Get item
Get the specified item.
example:
Remove item
Remove the specified item by raw ID.
example:
Destroy cart
Clean Shopping Cart.
example:
Total price
Returns the total of all items.
example:
Count rows
Return the number of rows.
example:
Count quantity
Returns the quantity of all items
$totalItems
: When false
,will return the number of rows.
example:
Search items
Search items by property.
example:
Check empty
Specifies the associated model
Specifies the associated model of item.
example:
The Collection And Item
Collection
and Overtrue\LaravelShoppingCart\Item
are instanceof Illuminate\Support\Collection
, Usage Refer to:Collections - Laravel doc.
properties of Overtrue\LaravelShoppingCart\Item
:
id
- your goods item ID.name
- Name of item.qty
- Quantity of item.price
- Unit price of item.total
- Total price of item.__raw_id
- Unique ID of row.__model
- Name of item associated Model.- ... custom attributes.
And methods:
rawId()
- Return the raw ID of item.
Events
Event Name | Parameters |
---|---|
cart.adding |
($attributes, $cart); |
cart.added |
($attributes, $cart); |
cart.updating |
($row, $cart); |
cart.updated |
($row, $cart); |
cart.removing |
($row, $cart); |
cart.removed |
($row, $cart); |
cart.destroying |
($cart); |
cart.destroyed |
($cart); |
You can easily handle these events, for example: