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\Models\Store\Product;
9use Auth;
10
11class ProductsController extends Controller
12{
13 protected $layout = 'master';
14
15 public function show($id)
16 {
17 $product = $this->getProduct($id);
18 if ($product->isRedirectPlaceholder()) {
19 return redirect($product->description);
20 }
21
22 $cart = $this->userCart();
23
24 $requestedNotification = Auth::check()
25 ? $product->notificationRequests()->where('user_id', Auth::user()->user_id)->exists()
26 : false;
27
28 return ext_view('store.products.show', compact('cart', 'product', 'requestedNotification'));
29 }
30
31 private function getProduct($id)
32 {
33 $product = Product::with('masterProduct')->available();
34
35 return is_numeric($id)
36 ? $product->findOrFail($id)
37 : $product
38 ->customClass($id)
39 ->where('master_product_id', null)
40 ->orderBy('product_id', 'desc')
41 ->firstOrFail();
42 }
43}