laravelir/cart 问题修复 & 功能扩展

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

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

laravelir/cart

最新稳定版本:0.1.0

Composer 安装命令:

composer require laravelir/cart

包简介

shop cart package

README 文档

README

  • Starts
  • Forks
  • Total Downloads

cart package (In Develop)

a multi driver shopping cart package

Installation

  1. Run the command below to add this package:
composer require laravelir/cart
  1. Open your config/app.php and add the following to the providers/aliases array:
Laravelir\Cart\Providers\CartServiceProvider::class,
'Cart' => Laravelir\Cart\Facade\Cart::class,
  1. Run the command below to install package:
php artisan cart:install

Drivers

Session - Cookie - Eloquent - Cache

you can set your favorite driver in config file

eloquent driver need to authenticated user for save user's id

How to use

add HasCart trait to User model

this trait has one method:

$this->cart(); // return cart 

Methods

$cart = resolve(Cart());

$cart->all();

$cart->add();

$cart->has();

$cart->update();

$cart->count();

$cart->delete();

$cart->truncate();

Helpers

cart();

cartItems();

Cart::user($user_id)->add(); Cart::driver('session')->add(); Cart::add(['id' => '293ad', 'name' => 'Product 1', 'qty' => 1, 'price' => 9.99, 'options' => ['size' => 'large']]);

Usage

$user = auth()->user();

$product = Product::first();

$cart = resolve(Cart());

$data = [ 'item' => $product, 'title' => $product->title, 'quantity' => 1, 'price' => $product->price, ];

$options = [ 'color' => 'red', 'size' => 'XL' ]; $user->cart->add($data, $options);

$data = [

]; Cart::update($itemId, $data); Cart::update($itemId)->increaseQuantity(); Cart::update($itemId)->decreaseQuantity(); Cart::all(); Cart::count(); Cart::get($itemId); Cart::delete($itemId); Cart::truncate();

Cartable Contract

For the convenience of faster adding items to cart and their automatic association, your model can implement Buyable interface. To do so, it must implement such functions:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Product exends Model implements Cartable {

    public function getCartableId() {
        return $this->id;
    }

    public function getCartableTitle() {
        return $this->title;
    }

    public function getCartablePrice() {
        return $this->price;
    }
}

Events

The cart has following events:

cart.added - when an item added cart.updated - when an item cart updated cart.deleted - when an item deleted

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固