the browser-facing portion of osu!
at master 1.6 kB view raw
1<?php 2 3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0. 4// See the LICENCE file in the repository root for full licence text. 5 6namespace App\Http\Controllers\Store; 7 8use App\Libraries\OrderCheckout; 9 10class CartController extends Controller 11{ 12 protected $layout = 'master'; 13 14 public function __construct() 15 { 16 $this->middleware('auth', ['only' => [ 17 'store', 18 ]]); 19 20 if (!$this->isAllowRestrictedUsers()) { 21 $this->middleware('check-user-restricted', ['only' => [ 22 'store', 23 ]]); 24 } 25 26 parent::__construct(); 27 } 28 29 public function empty() 30 { 31 $this->userCart()?->items->each->delete(); 32 33 return ext_view('layout.ujs-reload', [], 'js'); 34 } 35 36 public function show() 37 { 38 $order = $this->userCart(); 39 $validationErrors = $order !== null ? (new OrderCheckout($order))->validate() : []; 40 41 return ext_view('store.cart.show', compact('order', 'validationErrors')); 42 } 43 44 public function store() 45 { 46 $params = get_params(request()->all(), null, [ 47 'add:bool', 48 'item:array', 49 ]); 50 51 $add = $params['add'] ?? false; 52 $error = $this->userCart()->updateItem($params['item'] ?? [], $add); 53 54 if ($error === null) { 55 return $add ? ujs_redirect(route('store.cart.show')) : ext_view('layout.ujs-reload', [], 'js'); 56 } else { 57 return error_popup($error); 58 } 59 } 60}