|
@@ -67,11 +67,13 @@ class Cart extends Base
|
|
|
$data = [];
|
|
|
$productExtend = new \addons\unishop\extend\Product;
|
|
|
|
|
|
+ $choose_price_total = 0;//已选中的总价格
|
|
|
foreach ($carts as $item) {
|
|
|
$oldProduct = json_decode($item['snapshot'], true);
|
|
|
$oldData = $productExtend->getBaseData($oldProduct, $item['spec'] ?? '');
|
|
|
|
|
|
- if (empty($item['product'])) {
|
|
|
+ if (empty($item['product'])) { //商品被删了的情况
|
|
|
+ continue;//不要了
|
|
|
$tempData = $oldData;
|
|
|
$tempData['isset'] = false; // 失效
|
|
|
$tempData['title'] = $oldProduct['title'];
|
|
@@ -84,6 +86,7 @@ class Cart extends Base
|
|
|
|
|
|
$tempData['isset'] = true;
|
|
|
if ($productData['switch'] == Product::SWITCH_OFF) {
|
|
|
+ continue;//不要了
|
|
|
$tempData['isset'] = false; // 失效
|
|
|
$tempData['choose'] = 0;
|
|
|
}
|
|
@@ -96,13 +99,23 @@ class Cart extends Base
|
|
|
$tempData['image'] = Config::getImagesFullUrl($oldData['image']);
|
|
|
$tempData['oldPrice'] = round($oldData['sales_price'], 2);
|
|
|
$tempData['nowPrice'] = round($tempData['sales_price'], 2);
|
|
|
+ //新增此商品总价
|
|
|
+ $tempData['Price_total'] = bcmul($tempData['sales_price'],$tempData['number'],2);
|
|
|
+ //已选中商品,总价格
|
|
|
+ if($item['choose'] == 1){
|
|
|
+ $choose_price_total = bcadd($choose_price_total,$tempData['Price_total'],2);
|
|
|
+ }
|
|
|
|
|
|
$tempData['product_id'] = Hashids::encodeHex($item['product_id']);
|
|
|
|
|
|
$data[] = $tempData;
|
|
|
}
|
|
|
|
|
|
- $this->success('', $data);
|
|
|
+ $result = [
|
|
|
+ 'choose_price_total' => $choose_price_total,
|
|
|
+ 'list' => $data,
|
|
|
+ ];
|
|
|
+ $this->success('', $result);
|
|
|
}
|
|
|
|
|
|
|