cart
This commit is contained in:
parent
7c734754b5
commit
6c8ec6d645
|
|
@ -23,32 +23,30 @@ class CartController extends Controller
|
|||
*
|
||||
* POST /carts/select {sku_ids:[product_sku_id, product_sku_id]}
|
||||
* @param Request $request
|
||||
* @return View
|
||||
* @return array
|
||||
*/
|
||||
public function select(Request $request): View
|
||||
public function select(Request $request): array
|
||||
{
|
||||
$productSkuIds = $request->get('sku_ids');
|
||||
$customer = current_customer();
|
||||
CartService::select($customer, $productSkuIds);
|
||||
|
||||
$data = CartService::reloadData();
|
||||
return view("cart", $data);
|
||||
return CartService::reloadData();
|
||||
}
|
||||
|
||||
/**
|
||||
* PUT /carts/{cart_id} {quantity: 123}
|
||||
* @param Request $request
|
||||
* @param $cartId
|
||||
* @return View
|
||||
* @return array
|
||||
*/
|
||||
public function update(Request $request, $cartId): View
|
||||
public function update(Request $request, $cartId): array
|
||||
{
|
||||
$customer = current_customer();
|
||||
$quantity = $request->get('quantity');
|
||||
CartService::updateQuantity($customer, $cartId, $quantity);
|
||||
|
||||
$data = CartService::reloadData();
|
||||
return view("cart", $data);
|
||||
return CartService::reloadData();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ class CartList extends JsonResource
|
|||
$description = $sku->product->description;
|
||||
$subTotal = $price * $this->quantity;
|
||||
return [
|
||||
'cart_id' => $this->id,
|
||||
'product_id' => $this->product_id,
|
||||
'sku_id' => $this->product_sku_id,
|
||||
'name' => $description->name,
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ Route::prefix('/')
|
|||
Route::get('carts', [CartController::class, 'index'])->name('carts.index');
|
||||
Route::post('carts', [CartController::class, 'store'])->name('carts.store');
|
||||
Route::get('carts/mini', [CartController::class, 'miniCart'])->name('carts.mini');
|
||||
Route::put('carts/{cart}', [CartController::class, 'update'])->name('carts.update');
|
||||
Route::post('carts/select', [CartController::class, 'select'])->name('carts.select');
|
||||
|
||||
Route::get('checkout', [CheckoutController::class, 'index'])->name('checkout.index');
|
||||
|
||||
|
|
|
|||
|
|
@ -80,9 +80,12 @@ class CartService
|
|||
*/
|
||||
public static function select($customer, $productSkuIds)
|
||||
{
|
||||
if (empty($productSkuIds)) {
|
||||
return;
|
||||
}
|
||||
Cart::query()->where('customer_id', $customer->id)
|
||||
->whereIn('product_sku_id', $productSkuIds)
|
||||
->update(['selected', 1]);
|
||||
->update(['selected' => 1]);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -91,9 +94,12 @@ class CartService
|
|||
*/
|
||||
public static function updateQuantity($customer, $cartId, $quantity)
|
||||
{
|
||||
if (empty($cartId)) {
|
||||
return;
|
||||
}
|
||||
Cart::query()->where('customer_id', $customer->id)
|
||||
->where('id', $cartId)
|
||||
->update(['quantity', $quantity]);
|
||||
->update(['quantity' => $quantity]);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue