定制 nhanchaukp/laracart 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

nhanchaukp/laracart

Composer 安装命令:

composer require nhanchaukp/laracart

包简介

Enhanced Laravel shopping cart package with multiple storage drivers

README 文档

README

LaraCart

LaraCart

Build Status License Downloads Contributors PHP Version Require Packagist Version

LaraCart is a Laravel package that provides a flexible and extensible shopping cart system. It supports multiple storage drivers (e.g., database, session) and offers a wide range of features for managing shopping carts in your Laravel application.

Features

  • Multiple storage drivers (Database, Session)
  • Add, update, and remove items from the cart
  • Support for polymorphic itemable models
  • Discount management
  • Assign carts to users
  • Clear and count items in the cart
  • Retrieve cart totals and quantities

Installation

  1. Install the package via Composer:

    composer require nhanchaukp/laracart
  2. Publish the configuration and migration files:

    # config
    php artisan vendor:publish --provider="NhanChauKP\LaraCart\Providers\LaraCartServiceProvider" --tag=laracart-config
    
    #migrations
    php artisan vendor:publish --provider="NhanChauKP\LaraCart\Providers\LaraCartServiceProvider" --tag=laracart-migrations
  3. Run the migrations:

    php artisan migrate
  4. Configure the driver in config/laracart.php (default: database).

Usage

Basic Usage

Add an Item to the Cart

use NhanChauKP\LaraCart\Facades\LaraCart;

$item = Product::find(1); // Example item
LaraCart::addItem($item, 2, 100.00, ['color' => 'red']);

Retrieve the Cart

$cart = LaraCart::getCart();

Get All Items

$items = LaraCart::getItems();

Remove an Item

LaraCart::removeItem($item);

Clear the Cart

LaraCart::clear();

Advanced Features

Set a Discount

LaraCart::setDiscount(10); // 10% discount

Assign Cart to a User

LaraCart::assignToUser($userId);

Switch Drivers

LaraCart::driver('session');

Configuration

The configuration file config/laracart.php allows you to customize the following:

  • driver: The storage driver (database or session).
  • session_key: The session key for the session driver.
  • currency: The default currency.
  • models: Custom models for Cart and CartItem.
  • cookie: Cookie settings for guest users.

Models

Cart

The Cart model represents a shopping cart and includes the following attributes:

  • user_id: The ID of the user associated with the cart.
  • session_id: The session ID for guest users.
  • discount_percent: The discount percentage applied to the cart.
  • total: The total price of the cart.

CartItem

The CartItem model represents an item in the cart and includes the following attributes:

  • cart_id: The ID of the cart.
  • itemable: Polymorphic relation to the itemable model.
  • quantity: The quantity of the item.
  • price: The price of the item.
  • options: Additional options for the item.

License

This package is open-sourced software licensed under the MIT license.

nhanchaukp/laracart 适用场景与选型建议

nhanchaukp/laracart 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 472 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 04 月 17 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「shopping」 「Laravel shopping cart」 「Laravel cart」 「laracart」 「laravel shopping」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 nhanchaukp/laracart 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 nhanchaukp/laracart 我们能提供哪些服务?
定制开发 / 二次开发

基于 nhanchaukp/laracart 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-17