承接 nhanchaukp/laracart 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

nhanchaukp/laracart

最新稳定版本:1.0.2

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.

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固