定制 andreilungeanu/simple-cart 二次开发

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

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

andreilungeanu/simple-cart

Composer 安装命令:

composer require andreilungeanu/simple-cart

包简介

A simple cart package for Laravel applications

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Modern Laravel shopping cart package with clean architecture

📖 For detailed documentation, examples, and advanced usage, see DOCUMENTATION.md

🎯 Features

  • Event-Driven Design - Comprehensive listeners for cart lifecycle events
  • Advanced Calculations - Dynamic tax system, flexible shipping, flexible discount system (fixed, percentage, free shipping with conditional logic)
  • Multiple Cart Instances - Proper user/session isolation and state management
  • Service-Based API - Clean service layer for cart operations
  • Database Persistence - Reliable storage with automatic expiration handling

📦 Installation

Install via Composer:

composer require andreilungeanu/simple-cart

Publish and run migrations:

php artisan vendor:publish --tag="simple-cart-migrations"
php artisan migrate

Optionally publish the configuration:

php artisan vendor:publish --tag="simple-cart-config"

🚀 Quick Start

Basic Usage

use AndreiLungeanu\SimpleCart\Facades\Cart;

// Create cart for user
$cart = Cart::create(userId: 123);

// Add items to cart
Cart::addItem($cart, [
    'product_id' => 'prod_1',
    'name' => 'Gaming Laptop', 
    'price' => 1299.99,
    'quantity' => 1,
    'category' => 'electronics'
]);

Cart::addItem($cart, [
    'product_id' => 'prod_2',
    'name' => 'Wireless Mouse',
    'price' => 25.50,
    'quantity' => 2
]);

// Apply tax
Cart::applyTax($cart, [
    'code' => 'VAT_UK',
    'rate' => 0.20,
    'apply_to_shipping' => true
]);

// Apply discount
Cart::applyDiscount($cart, [
    'code' => 'SAVE50',
    'type' => 'fixed',
    'value' => 50,
    'conditions' => ['minimum_amount' => 100]
]);

// Apply shipping
Cart::applyShipping($cart, [
    'method_name' => 'Express Shipping',
    'cost' => 15.99,
    'carrier' => 'UPS'
]);

// Get calculations
$subtotal = Cart::calculateSubtotal($cart);    // 1350.99
$shipping = Cart::calculateShipping($cart);    // 15.99 (or 0 if free shipping)
$tax = Cart::calculateTax($cart);              // Based on applied tax config
$total = Cart::calculateTotal($cart);          // Final total with all calculations

echo "Final Total: $" . $total;

Cart Summary

// Get complete cart overview
$summary = Cart::getCartSummary($cart);
/*
[
    'id' => 'cart-uuid',
    'item_count' => 3,
    'subtotal' => 1350.99,
    'shipping' => 15.99,
    'tax' => 270.20,
    'discounts' => 50.00,
    'total' => 1586.18,
    'status' => 'active',
    'expires_at' => '2025-10-07T12:00:00.000000Z'
]
*/

Cart merge stratery on login

When a user logs in and both a guest session cart and a user cart exist, you can control behavior via login_cart_strategy (env: CART_ON_LOGIN_CART_STRATEGY). Options: merge (default), guest, user.

For details, see the documentation section “Cart Merge Strategy on Login”.

🔧 Key Features Overview

Dynamic Tax System

  • Priority-based rates: Item-specific > Category > Type > Default
  • Flexible conditions: Support for any tax scenario
  • API integration ready: Perfect for external tax services

Advanced Discounts

  • Multiple types: Percentage, fixed amount, free shipping
  • Conditional logic: Minimum amounts, item requirements, categories
  • Stacking support: Configure multiple discount behavior

Flexible Shipping

  • Dynamic rates: Your app provides shipping data
  • Free shipping: Threshold-based or discount-based
  • Carrier integration: Store any shipping method data

Event-Driven Architecture

All cart operations dispatch events for:

  • Analytics tracking
  • Inventory management
  • Cache invalidation
  • Custom business logic

📖 Complete Documentation

For comprehensive documentation including:

  • Detailed API reference with all methods and parameters
  • Advanced tax scenarios (EU VAT, US State tax, API integration)
  • Conditional discount patterns (percentage, fixed amount, free shipping; quantity/amount conditions)
  • Event handling examples (analytics, inventory, notifications)
  • Performance optimization tips and caching strategies
  • Security best practices and error handling
  • Complete usage examples for real-world scenarios

👉 See DOCUMENTATION.md

⚡ Configuration

Basic configuration in config/simple-cart.php:

return [
    'storage' => [
        'ttl_days' => 30,              // Cart expiration
    ],
    'shipping' => [
        'free_shipping_threshold' => 100.00,  // Free shipping over $100
    ],
    'discounts' => [
        'allow_stacking' => false,     // Allow multiple discount codes
        'max_discount_codes' => 3,     // Maximum discount codes per cart
    ],
];

🧹 Maintenance

Clean up expired carts:

# Manual cleanup
php artisan simple-cart:cleanup

# Scheduled cleanup (add to Kernel.php)
$schedule->command('simple-cart:cleanup --force')->daily();

📄 License

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

Need help? Check the complete documentation or create an issue on GitHub.

andreilungeanu/simple-cart 适用场景与选型建议

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

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

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

围绕 andreilungeanu/simple-cart 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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