juliobitencourt/laravel-cart 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

juliobitencourt/laravel-cart

最新稳定版本:v1.0.1

Composer 安装命令:

composer require juliobitencourt/laravel-cart

包简介

A lightweight PHP Shopping Cart for Laravel 5.

README 文档

README

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

Code Climate

A lightweight PHP Shopping Cart for Laravel 5.

Installation

With Composer

$ composer require juliobitencourt/laravel-cart
{
    "require": {
        "juliobitencourt/laravel-cart": "1.0.*"
    }
}

Add the service provider to your app/config/app.php in the service providers array

'JulioBitencourt\Cart\CartServiceProvider',

Publish the resources

php artisan vendor:publish

Check the config/laravel-cart.php file. The storage-driver config can have the values Session (default) or Database.

In case you use Database as the storage driver you have to run the migrations

php artisan migrate

Usage

Inject the class into the constructor.

use JulioBitencourt\Cart\Cart;

class CartController extends Controller {

	protected $cart;

	public function __construct(Cart $cart)
	{
		$this->cart = $cart;
	}

Insert a new Item to the cart.

If you insert an item with the same SKU twice, the item quantity will be updated.

$item = [
	'sku' => '123456',
	'description' => 'PlayStation 4',
	'price' => 300,
	'quantity' => 1
];

$result = $this->cart->insert($item);

Insert a Child Item.

$item = [
	'sku' => '111111',
	'description' => '2 Year Protection',
	'price' => 30.50,
	'quantity' => 1
];

$result = $this->cart->insertChild($parentId, $item);

Update an item

If you update an item with 0 quantity, it will be removed from the cart's list of items

$result = $this->cart->update($id, $quantity);

Remove an item

$this->cart->delete($id);

Destroy the cart

$this->cart->destroy();

Checking if the cart is empty

$this->cart->isEmpty(); // Returns true or false

Returning an array with the list of items

$this->cart->all();

Count the total of items

$this->cart->totalItems();

Sum the cart total price

$this->cart->total();

Identify the cart with the e-mail.

This is useful if you want to implement abandoned cart recovery.

$this->cart->setEmail($email)

统计信息

  • 总下载量: 1.31k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 38
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 38
  • Watchers: 3
  • Forks: 15
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-04-13