我使用的是从here
获得的Laravel购物车包我已按照说明安装软件包。
这是"C:\Program Files\Java\jdk1.8.0_92\bin\java" -cp folder1.classfile folder2\parameter.txt > Logs\log.out 2>&1 & echo $! > Files/pid.txt
模型类:
Cart.php
namespace App;
use Amsgames\LaravelShop\Models\ShopCartModel;
class Cart extends ShopCartModel
{
}
ShopCartModel
最后是use Amsgames\LaravelShop\Contracts\ShopCartInterface;
use Amsgames\LaravelShop\Traits\ShopCartTrait;
use Amsgames\LaravelShop\Traits\ShopCalculationsTrait;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Config;
class ShopCartModel extends Model implements ShopCartInterface
{
use ShopCartTrait, ShopCalculationsTrait;
/**
* The database table used by the model.
*
* @var string
*/
protected $table;
/**
* Fillable attributes for mass assignment.
*
* @var array
*/
protected $fillable = ['user_id','user_count', 'user_price'];
/**
* Creates a new instance of the model.
*
* @param array $attributes
*/
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
$this->table = Config::get('shop.cart_table');
}
}
ShopCartInterface
我尝试做的是在以下代码中将商品添加到购物车
namespace Amsgames\LaravelShop\Contracts;
/**
* This file is part of LaravelShop,
* A shop solution for Laravel.
*
* @author Alejandro Mostajo
* @copyright Amsgames, LLC
* @license MIT
* @package Amsgames\LaravelShop
*/
interface ShopCartInterface
{
/**
* One-to-One relations with the user model.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function user();
/**
* One-to-Many relations with Item.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function items();
/**
* Adds item to cart.
*
* @param mixed $item Item to add, can be an Store Item, a Model with ShopItemTrait or an array.
* @param int $quantity Item quantity in cart.
*/
public function add($item, $quantity = 1, $quantityReset = self::QUANTITY_ADDITION);
/**
* Removes an item from the cart or decreases its quantity.
* Returns flag indicating if removal was successful.
*
* @param mixed $item Item to remove, can be an Store Item, a Model with ShopItemTrait or an array.
* @param int $quantity Item quantity to decrease. 0 if wanted item to be removed completly.
*
* @return bool
*/
public function remove($item, $quantity = 0);
/**
* Checks if the user has a role by its name.
*
* @param string|array $name Role name or array of role names.
* @param bool $requireAll All roles in the array are required.
*
* @return bool
*/
public function hasItem($sku, $requireAll = false);
/**
* Scope to current user cart and returns class model.
*
* @param \Illuminate\Database\Eloquent\Builder $query Query.
*
* @return this
*/
public function scopeCurrent($query);
/**
* Returns total amount of items in cart.
*
* @return int
*/
public function getCountAttribute();
/**
* Returns total price of all the items in cart.
*
* @return float
*/
public function getTotalPriceAttribute();
/**
* Returns total tax of all the items in cart.
*
* @return float
*/
public function getTotalTaxAttribute();
/**
* Returns total tax of all the items in cart.
*
* @return float
*/
public function getTotalShippingAttribute();
/**
* Returns total discount amount based on all coupons applied.
*
* @return float
*/
public function getTotalDiscountAttribute();
/**
* Returns total amount to be charged base on total price, tax and discount.
*
* @return float
*/
public function getTotalAttribute();
/**
* Returns formatted total price of all the items in cart.
*
* @return string
*/
public function getDisplayTotalPriceAttribute();
/**
* Returns formatted total tax of all the items in cart.
*
* @return string
*/
public function getDisplayTotalTaxAttribute();
/**
* Returns formatted total tax of all the items in cart.
*
* @return string
*/
public function getDisplayTotalShippingAttribute();
/**
* Returns formatted total discount amount based on all coupons applied.
*
* @return string
*/
public function getDisplayTotalDiscountAttribute();
/**
* Returns formatted total amount to be charged base on total price, tax and discount.
*
* @return string
*/
public function getDisplayTotalAttribute();
/**
* Transforms cart into an order.
* Returns created order.
*
* @param mixed $status Order status to create order with.
*
* @return Order
*/
public function placeOrder($statusCode = null);
/**
* Whipes put cart
*/
public function clear();
}
我收到了这个错误
$items = DB::table('apps as a')
->leftJoin('odoo_modules as b', 'a.i_odoo', '=', 'b.id')
->whereIn('a.id', Input::get('items'))
->select('a.id as i_apps', 'b.name as sku', 'a.price')
->get();
$cart = \App\Cart::current();
foreach($items as $item){
$cart->add(['sku' => $item->sku, 'i_apps' => $item->i_apps, 'price' => $item->price]);
}
我是否必须在模型BadMethodCallException in Builder.php line 2345:
Call to undefined method Illuminate\Database\Query\Builder::add()
中实施add
方法?如果没有导致错误的原因是什么?