neyromanser / laravel-shop
适用于Laravel应用程序的订单。
v1.3.8
2016-08-26 14:01 UTC
Requires
- illuminate/config: 5.0.*|5.1.*|5.2.*
- illuminate/console: 5.0.*|5.1.*|5.2.*
- illuminate/database: 5.0.*|5.1.*|5.2.*
- illuminate/support: 5.0.*|5.1.*|5.2.*
Requires (Dev)
- phpunit/phpunit: ~4.0
README
Laravel 5的商店模块,包括购物车和订单
安装
composer require "neyromanser/laravel-shop:1.*"
安装后,转到 config/app.php
下的 providers
部分,添加以下内容
Neyromanser\LaravelShop\LaravelShopServiceProvider::class
并在 "aliases" 下添加
'Shop' => Neyromanser\LaravelShop\Facades\ShopFacade::class
使用以下命令发布迁移和配置文件
php artisan vendor:publish
在 config/shop.php
中编辑其他设置
return [ 'currency' => "грн." ];
使用方法
购物车
# Add to cart Shop::Cart()->add([ 'id' => $id, 'name' => $name, 'qty' => $request->input('qty', 1), 'price' => $item->price, 'options' => $options ]); # Remove from cart Shop::Cart()->remove($id); # Update cart Shop::Cart()->update($id, $quantity); # Cart total sum Shop::Cart()->total() # Cart positions amount Shop::Cart()->count() # Cart total products units Shop::Cart()->count(false) # Search in cart Shop::Cart()->search(['id' => 123]); # Associate cart with App\Model\Product Shop::Cart()->associate('Product', 'App\\Model') # New cart instance Shop::Cart()->instance('wishlist')
订单
# Create order Shop::Order()->order(Auth::user()->id, [ 'shipping_method_id' => $request->input('shipping_method',0), 'payment_method_id' => $request->input('payment_method',0), 'shipping_address' => $request->input('address',''), 'shipping_city' => $request->input('city',''), 'shipping_name' => $request->input('name',''), 'shipping_email' => $request->input('email',''), 'shipping_phone' => $request->input('phone',''), 'note' => $request->input('note','') ]); # Add items to order Shop::Order()->addItems($order, [ [ "description" => $name, "currency" => $currency, "line_item_id" => $item->id, "line_item_type" => "App\\ProductVariant", "price" => $item->price, "quantity" => $item->qty, "vat" => 0 ],[ "description" => $name, "currency" => $currency, "line_item_id" => $item->id, "line_item_type" => "App\\ProductVariant", "price" => $item->price, "quantity" => $item->qty, "vat" => 0 ], ]);
演示
Shop::Cart()->instance('wishlist')->associate('Product', 'App')->add($addItem);
基于
https://github.com/Trexology/laravel-order
https://github.com/Crinsane/LaravelShoppingcart
查看
https://github.com/amsgames/laravel-shop
更新