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;
7
8use App\Http\Controllers\Store\Controller as Controller;
9use App\Models\Store;
10use Auth;
11
12class StoreController extends Controller
13{
14 // bootstrap setup in BaseController
15 protected $layout = 'master';
16
17 public function __construct()
18 {
19 $this->middleware('auth', ['only' => [
20 'getInvoice',
21 ]]);
22
23 if (!$this->isAllowRestrictedUsers()) {
24 $this->middleware('check-user-restricted', ['only' => [
25 'getInvoice',
26 ]]);
27 }
28
29 $this->middleware('verify-user', ['only' => [
30 'getInvoice',
31 ]]);
32
33 parent::__construct();
34 }
35
36 public function getListing()
37 {
38 return ext_view('store.index', [
39 'cart' => $this->userCart(),
40 'products' => Store\Product::listing()->get(),
41 ]);
42 }
43
44 public function getInvoice($id = null)
45 {
46 $order = Store\Order::whereHasInvoice()
47 ->with('items.product')
48 ->findOrFail($id);
49
50 if (Auth::user()->user_id !== $order->user_id && !Auth::user()->isAdmin()) {
51 abort(403);
52 }
53
54 return ext_view('store.invoice', compact('order'));
55 }
56}