承接 johannesschobel/laravel-shoppingcart 相关项目开发

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

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

johannesschobel/laravel-shoppingcart

Composer 安装命令:

composer require johannesschobel/laravel-shoppingcart

包简介

A Shopping Cart Implementation for Laravel

README 文档

README

Provides an invitation mechanism for Laravel applications. Note that this package does not handle, how the invitation is sent to the user (e.g., via email).

Installation

First, add the respective line to your composer file

"require" : {
   ... ,
   "johannesschobel/laravel-shoppingcart": "0.*" ,
}

and run composer install to install the new component.

Then add respective ServiceProvider from the package to your config/app.php configuration file, like this:

'providers' => [
   ... ,
   JohannesSchobel\ShoppingCart\ShoppingCartServiceProvider::class,
],

and register the Facade

'aliases' => [
   ... ,
   'ShoppingCart' => JohannesSchobel\ShoppingCart\Facades\ShoppingCart::class,
],

Then, you simply add the provided migration file using the following command:

php artisan vendor:publish --provider="JohannesSchobel\ShoppingCart\ShoppingCartServiceProvider" --tag="migrations"

and then you migrate your database using

php artisan db:migrate

If you want, you can overwrite the basic configuration of this package using the following command:

php artisan vendor:publish --provider="JohannesSchobel\ShoppingCart\ShoppingCartServiceProvider" --tag="config"

This will copy the shoppingcart configuration file to your config folder. Using this file, you can customize the various parameters of the package. Currently, not many are available, however, I will be adding more and more ;)

Usage

The ShoppingCart Facade provides some neat methods to deal with the shopping cart in general. These methods are:

LOAD a ShoppingCart from the database

ShoppingCart::load($identifier, $name = null);

Load the cart with the identifier and name from the database. If no name is provided, the default name default will be used. If no cart exists, an empty cart will be returned. This cart remains temporary as long as no items are stored.

CLEAR a ShoppingCart

ShoppingCart::clear();

Removes the current instance of the cart from the database.

ADD Items to the Cart

ShoppingCart::addItem(
   $id, 
   $name = null, 
   $type = null, 
   $qty = 1, 
   Money $price = null, 
   $uri = null, 
   array $options = []
);

This method allows for adding items to the cart. The basic usage allows you to directly specify the item you want to set. For example

ShoppingCart::addItem(
   '1234', 
   'Basic T-Shirt', 
   'products', 
   10, 
   new Money(999, new Currency('EUR')), // note the value is added in cents! 
   '/products/1234', 
   ['size' => 'large', 'color' => 'black']
);

would add 10 "Basic T-Shirts", each costs 9.99 EUR to the cart. The customer has specified a color and size.

You may, however, add the Buyable interface to your products in order to simplify this process. This will require you to implement additional methods on the model (you can add the CanBePurchased Trait in order to make a "best guess").

This would allow you to just add a specific product:

$product = Product::find(1234); // remember, Product must implement the Buyable interface!
ShoppingCart::addBuyable(
   $product, 
   10, 
   ['size' => 'large', 'color' => 'black']
);

would result in the same cart as above. However, the id, name, price and uri are directly taken from the model!

REMOVE Items from the Cart

ShoppingCart::removeItem($row)

To remove an item from the shopping cart you need to have its rowId. This rowId can be obtained, for example, via the ShoppingCart::load() or ShoppingCart::getContent() method.

$rowId = "30168b5f5a78bc48d08b4d5a125a9d90";
ShoppingCart::removeItem($rowId);

UPDATE Items in the Cart

ShoppingCart::updateItem($row, $qty = 1, array $options = [])

allows you to update a given row in the cart. This rowId can be obtained, for example, via the ShoppingCart::load() or ShoppingCart::getContent() method.

$rowId = "30168b5f5a78bc48d08b4d5a125a9d90";
ShoppingCart::updateItem($rowId, 1, ['color' => 'red']);

would update the quantity and options of the item (e.g., the product to be purchased shall be 'red' instead of 'black').

Items / Price / Taxes

The Cart also provides methods to

  • get the amount of items in the cart => getItemCount()
  • get the content of the cart. This returns all items in the cart => getContent()
  • get the value of the current cart
    • get the taxes of the cart => getTaxes()
    • get total (value including taxes) => getTotal()
    • get subtotal (value without taxes) => getSubTotal()
  • get the "associated" Buyable model => resolveModel()

johannesschobel/laravel-shoppingcart 适用场景与选型建议

johannesschobel/laravel-shoppingcart 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 64.39k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2017 年 09 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 johannesschobel/laravel-shoppingcart 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 64.39k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 24
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-09-03