添加购物车时的单价在哪儿获取

问题咨询 · lingdu · 于 5年前 发布 · 1878 次阅读

我商品添加进来单价是双倍,我想查找下是哪儿出现问题了

共收到 2 条回复
Fecmall#15年前 0 个赞

1.产品加入购物车,数据库不记录产品价格,价格是动态计算的

2.得到购物车信息的cart services 方法:

https://github.com/fecshop/yii2_fecshop/blob/master/services/Cart.php#L111

return Yii::$service->cart->quote->getCartInfo($activeProduct, $shipping_method, $country, $region);

就是文件

https://github.com/fecshop/yii2_fecshop/blob/master/services/cart/Quote.php#L353

找到369行

$cart_product_info = Yii::$service->cart->quoteItem->getCartProductInfo($activeProduct);

就是文件:https://github.com/fecshop/yii2_fecshop/blob/master/services/cart/QuoteItem.php#L207

价格计算就是 234行

$product_price_arr  = Yii::$service->product->price->getCartPriceByProductId($product_id, $qty, $custom_option_sku, 2);

也就是: https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Price.php#L108

protected function actionGetCartPriceByProductId($productId, $qty, $custom_option_sku, $format = 1)

这个方法获取的,通过这个逻辑就可以顺出来,先了解一下services的原理和结构,找底层代码就容易很多

Fecmall#25年前 0 个赞

价格是计算出来的

$price   // 产品原价
$special_price,  // 产品特价
$special_from,  // 产品特价开始时间
$special_to,    // 产品特价结束时间
$qty = '',      // 产品个数
$custom_option_price,  // 产品自定义选项中的浮动价格
$tier_price = [],    // 产品的批发价格,譬如一个10美元,2个9美元,5个8美元

产品的价格是通过上面的这几个产品属性,经过一系列的逻辑计算出来的

添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册
Your Site Analytics