优化:购物车页面订单金额统计优化 和支付页面一致
This commit is contained in:
parent
be017fdb7e
commit
b7a2839ee4
|
|
@ -5,6 +5,7 @@ namespace Beike\Shop\Http\Controllers;
|
|||
use Beike\Models\ProductSku;
|
||||
use Beike\Shop\Http\Requests\CartRequest;
|
||||
use Beike\Shop\Services\CartService;
|
||||
use Beike\Shop\Services\CheckoutService;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
|
|
@ -18,7 +19,7 @@ class CartController extends Controller
|
|||
$data = [
|
||||
'data' => CartService::reloadData(),
|
||||
];
|
||||
|
||||
$data['totals'] = $this->getOrderMoney($data['data']['carts']);
|
||||
$data = hook_filter('cart.index.data', $data);
|
||||
|
||||
return view('cart/cart', $data);
|
||||
|
|
@ -38,6 +39,7 @@ class CartController extends Controller
|
|||
CartService::select($customer, $cartIds);
|
||||
|
||||
$data = CartService::reloadData();
|
||||
$data['totals'] = $this->getOrderMoney($data['carts']);
|
||||
|
||||
$data = hook_filter('cart.select.data', $data);
|
||||
|
||||
|
|
@ -100,6 +102,7 @@ class CartController extends Controller
|
|||
CartService::updateQuantity($customer, $cartId, $quantity);
|
||||
|
||||
$data = CartService::reloadData();
|
||||
$data['totals'] = $this->getOrderMoney($data['carts']);
|
||||
|
||||
$data = hook_filter('cart.update.data', $data);
|
||||
|
||||
|
|
@ -145,4 +148,22 @@ class CartController extends Controller
|
|||
|
||||
return json_success(trans('common.success'), $data);
|
||||
}
|
||||
/**
|
||||
* Common: 实时计算购物车订单金额
|
||||
* Author: wu-hui
|
||||
* Time: 2023/08/18 13:56
|
||||
* @param $carts
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getOrderMoney($carts){
|
||||
$carts = collect($carts)->where('selected', 1)->toArray();
|
||||
$checkoutService = new CheckoutService();
|
||||
$totalClass = hook_filter('service.checkout.total_service','Beike\Shop\Services\TotalService');
|
||||
$checkoutService->totalService = (new $totalClass($checkoutService->cart,$carts));
|
||||
$checkoutData = $checkoutService->checkoutData();
|
||||
|
||||
return $checkoutData['totals'];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,9 +85,14 @@
|
|||
<div class="p-lg-0"><h4 class="mb-3">{{ __('shop/carts.product_total') }}</h4></div>
|
||||
<div class="card-body p-lg-0">
|
||||
<ul class="list-group list-group-flush">
|
||||
<li class="list-group-item"><span>{{ __('shop/carts.all') }}</span><span>@{{ allProduct }}</span></li>
|
||||
<li class="list-group-item"><span>{{ __('shop/carts.selected') }}</span><span>@{{ total_quantity }}</span></li>
|
||||
<li class="list-group-item border-bottom-0"><span>{{ __('shop/carts.product_total') }}</span><span class="total-price">@{{ amount_format }}</span></li>
|
||||
{{--<li class="list-group-item"><span>{{ __('shop/carts.all') }}</span><span>@{{ allProduct }}</span></li>--}}
|
||||
{{--<li class="list-group-item"><span>{{ __('shop/carts.selected') }}</span><span>@{{ total_quantity }}</span></li>--}}
|
||||
{{--<li class="list-group-item border-bottom-0"><span>{{ __('shop/carts.product_total') }}</span><span class="total-price">@{{ amount_format }}</span></li>--}}
|
||||
<li v-for="(item,index) in totals">
|
||||
<span>@{{ item.title }}</span>
|
||||
<span>@{{ item.amount_format }}</span>
|
||||
</li>
|
||||
|
||||
<li class="list-group-item d-grid gap-2 mt-3 border-bottom-0">
|
||||
@hookwrapper('cart.confirm')
|
||||
<button type="button" class="btn btn-primary fs-5 fw-bold" @click="checkedBtnToCheckout">{{ __('shop/carts.to_checkout') }}</button>
|
||||
|
|
@ -128,8 +133,8 @@
|
|||
total_quantity: @json($data['quantity']),
|
||||
amount: @json($data['amount']),
|
||||
amount_format: @json($data['amount_format']),
|
||||
totals: @json($totals),
|
||||
},
|
||||
|
||||
computed: {
|
||||
allSelected: {
|
||||
get() {
|
||||
|
|
@ -145,7 +150,12 @@
|
|||
return this.products.map(e => e.quantity).reduce((n,m) => n + m);
|
||||
},
|
||||
},
|
||||
mounted(){
|
||||
|
||||
console.log(this.totals);
|
||||
|
||||
|
||||
},
|
||||
methods: {
|
||||
checkedBtnToCheckout() {
|
||||
if (!this.products.some(e => e.selected)) {
|
||||
|
|
@ -185,9 +195,11 @@
|
|||
},
|
||||
|
||||
setUpdateData(res) {
|
||||
this.products = res.data.carts
|
||||
this.amount_format = res.data.amount_format
|
||||
this.total_quantity = res.data.quantity
|
||||
this.products = res.data.carts;
|
||||
this.amount_format = res.data.amount_format;
|
||||
this.total_quantity = res.data.quantity;
|
||||
|
||||
this.totals = Object.assign({}, res.data.totals);
|
||||
bk.getCarts()
|
||||
}
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue