6
0
Fork 0

购物车优化

release
李静 2021-12-13 14:32:02 +08:00
parent 385cf0d936
commit 4c863302fa
1 changed files with 4 additions and 2 deletions

View File

@ -56,6 +56,8 @@ class ShoppingCartItemController extends Controller
'quantity' => $input['quantity'], 'quantity' => $input['quantity'],
]); ]);
$shoppingCartItem->setRelation('sku', $sku);
if (! $shoppingCartItem->wasRecentlyCreated) { if (! $shoppingCartItem->wasRecentlyCreated) {
if ($shoppingCartItem->quantity + $input['quantity'] > $sku->saleable_stock) { if ($shoppingCartItem->quantity + $input['quantity'] > $sku->saleable_stock) {
throw new ProductNotEnoughException(); throw new ProductNotEnoughException();
@ -64,7 +66,7 @@ class ShoppingCartItemController extends Controller
$shoppingCartItem->increment('quantity', $input['quantity']); $shoppingCartItem->increment('quantity', $input['quantity']);
} }
return response()->noContent(); return ShoppingCartItemResource::make($shoppingCartItem);
} }
/** /**
@ -98,7 +100,7 @@ class ShoppingCartItemController extends Controller
'specs' => $sku->specs, 'specs' => $sku->specs,
])); ]));
return response()->noContent(); return ShoppingCartItemResource::make($shoppingCartItem);
} }
/** /**