razorisuru/shopping-cart 问题修复 & 功能扩展

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

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

razorisuru/shopping-cart

最新稳定版本:1.0.3

Composer 安装命令:

composer require razorisuru/shopping-cart

包简介

The ShoppingCart package provides a simple and flexible solution for managing a shopping cart in Laravel applications. It uses sessions to store cart items, allowing you to easily add, update, remove, and clear items. With support for custom attributes, price calculations, and total cost computation

README 文档

README

ShoppingCart is a simple and lightweight package for managing a shopping cart in Laravel applications using sessions. This package is ideal for e-commerce platforms or any project requiring shopping cart functionality.

Features

  • Add items to the cart with quantity, price, and custom attributes.
  • Update or remove items from the cart.
  • Calculate the total cost of items in the cart.
  • Clear all items in the cart.
  • Session-based for seamless integration.

Installation

  1. Clone the repository:

    composer require razorisuru/shopping-cart
  2. Configure Composer to use the token (Optional):

    composer config --global github-oauth.github.com your-personal-access-token

Usage

Declare the cart:

use razorisuru\ShoppingCart\Cart;

class ProductController extends Controller
{
   protected $cart;

   public function __construct()
   {
      $this->cart = new Cart(); // Initialize an instance of the Cart class
   }
}
  1. Adding Items to the Cart:

    $this->cart->add($userId = 1, $itemId = 101, $quantity = 2, $price = 10.50, $attributes = ['color' => 'red']);
  2. Getting All Cart Items:

    $this->items = $cart->getAll($userId = 1);
  3. Updating an Item's Quantity:

    $this->cart->update(1, 1, 5); // Update item with USERID 1, PRODUCTID 1 to have a quantity of 5
  4. Removing an Item:

    $this->cart->remove($userId = 1, $itemId = 101);
  5. Clearing the Cart:

    $this->cart->clear($userId = 1);
  6. Calculating Total Cost:

    $this->cart->total($userId = 1);
  7. Counting the user cart items:

    $this->cart->countQuantity($userId = 1);
  8. Counting the user cart Product Count:

    $this->cart->countProducts($userId = 1);

Requirements PHP 8.0 or newer Laravel 8 or newer illuminate/support

Contributing

Contributions are welcome! To contribute:

  1. Fork the repository.
  2. Create a feature branch: git checkout -b feature-name.
  3. Commit your changes: git commit -m 'Add some feature'.
  4. Push to the branch: git push origin feature-name.
  5. Open a pull request.

License

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-01-09