feat(sales): WIP: add SaleController, Current_sales component, and view

- Added a new file `SaleController.php` in the `app/Http/Controllers` directory to handle sales-related logic.
- Created a new file `Current_sales.php` in the `app/View/Components/Sales` directory to define the `Current_sales` component.
- Added a new file `current_sales.blade.php` in the `resources/views/components/sales` directory to display the current sales.
- Modified the `web.php` routes file to include a route for accessing the sales page.

These changes introduce functionality related to displaying and managing sales data on the website.
This commit is contained in:
Rico van Zelst
2023-12-05 13:35:59 +01:00
parent 6eb9b48a84
commit 48c74fb4d6
5 changed files with 126 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Cache;
class SaleController extends Controller
{
public function index()
{
$sales = Cache::remember('sales_data', 60 * 60 * 8, function () {
$shopData = json_decode(file_get_contents('https://api.shop.riotgames.com/v3/collections/'),
true);
$salesData = array_filter($shopData, function ($collection) {
return $collection['path'] === '/event/sales';
});
return reset($salesData)['dynamicCollection']['discountedProductsByProductType'] ?? [];
});
return view('sales.index', compact('sales'));
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace App\View\Components\Sales;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;
class Current_sales extends Component
{
public function __construct(public array $sales)
{
}
public function render(): View
{
return view('components.sales.current_sales');
}
}

View File

@@ -0,0 +1,32 @@
@php
use App\Models\Champion;
use App\Models\ChampionSkin;
@endphp
<section class="max-w-screen-xl mx-auto mt-12">
<h1
class="text-3xl font-bold text-center text-transparent uppercase sm:text-4xl
bg-gradient-to-bl from-orange-300 to-orange-500 bg-clip-text">
Sale Rotation</h1>
<h2 class="text-lg font-bold text-center text-transparent uppercase sm:text-xl
bg-gradient-to-bl from-orange-300 to-orange-500 bg-clip-text">All champions & skins on sale</h2>
<div class="container mx-auto p-4 flex items-center justify-center mt-3 flex-col text-white">
<h3 class="text-2xl font-bold text-center text-transparent uppercase sm:text-3xl
bg-gradient-to-bl from-orange-300 to-orange-500 bg-clip-text">Champions on Sale</h3>
@foreach($sales['CHAMPION'] as $sale)
{{json_encode($sale)}}<br>
@php
$champion = Champion::where('champion_id', $sale['id'])->first();
@endphp
<br>{{ $champion->name }}<br>
@endforeach
</div>
<div class="container mx-auto p-4 flex items-center justify-center mt-3 flex-col text-white">
<h3 class="text-2xl font-bold text-center text-transparent uppercase sm:text-3xl
bg-gradient-to-bl from-orange-300 to-orange-500 bg-clip-text">Skins on Sale</h3>
@foreach($sales['CHAMPION_SKIN'] as $sale)
{{json_encode($sale)}}<br>
@endforeach
</div>
</section>

View File

@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Favicon -->
<link rel="apple-touch-icon" sizes="180x180" href="/img/icons/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/img/icons/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/img/icons/favicon-16x16.png">
<link rel="manifest" href="/img/icons/site.webmanifest">
<link rel="mask-icon" href="/img/icons/safari-pinned-tab.svg" color="#e6855e">
<link rel="shortcut icon" href="/img/icons/favicon.ico">
<meta name="msapplication-TileColor" content="#ff7c47">
<meta name="msapplication-config" content="/img/icons/browserconfig.xml">
<meta name="theme-color" content="#ff7c47">
<title>Heimerdinger.LoL Sale Rotation</title>
<meta name="description"
content="Explore the current LoL Sale on Heimerdinger.LoL. Find detailed information on what champions and skins are currently on sale and grab a good deal!">
<!-- OpenGraph -->
<meta property="og:site_name" content="Heimerdinger.LoL">
<meta property="og:title" content="Heimerdinger.LoL • Sale Rotation">
<meta property="og:description"
content="Explore the current LoL Sale on Heimerdinger.LoL. Find detailed information on what champions and skins are currently on sale and grab a good deal!">
<meta property="og:locale" content="en">
<meta property="og:type" content="website">
<meta property="og:image" content="{{asset('img/og_image.png')}}">
<!-- Twitter -->
<meta name="twitter:card" content="summary_large_image">
<meta property="twitter:domain" content="heimerdinger.lol">
<meta property="twitter:title" content="Heimerdinger.LoL • Sale Rotation">
<meta property="twitter:description"
content="Explore the current LoL Sale on Heimerdinger.LoL. Find detailed information on what champions and skins are currently on sale and grab a good deal!">
<meta property="twitter:image" content="{{asset('img/og_image.png')}}">
<link rel="preconnect" href="https://rsms.me/">
<link rel="preload" href="https://rsms.me/inter/inter.css" as="style">
<link rel="stylesheet" href="https://rsms.me/inter/inter.css" media="print" onload="this.media='all'">
@vite(['resources/css/app.css', 'resources/js/app.js'])
</head>
<body class="antialiased bg-stone-900 dark scroll-smooth">
<x-navbar/>
<x-sales.current_sales :sales="$sales"/>
<x-footer/>
</body>
</html>

View File

@@ -2,6 +2,7 @@
use App\Http\Controllers\AssetsController; use App\Http\Controllers\AssetsController;
use App\Http\Controllers\ChampionController; use App\Http\Controllers\ChampionController;
use App\Http\Controllers\SaleController;
use App\Http\Controllers\SummonerEmoteController; use App\Http\Controllers\SummonerEmoteController;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
use App\Http\Controllers\HomeController; use App\Http\Controllers\HomeController;
@@ -57,3 +58,5 @@ Route::get('/assets', [
Route::get(config('app.login_route'), function () { Route::get(config('app.login_route'), function () {
return redirect('/pulse'); return redirect('/pulse');
})->name('login')->middleware('auth.basic'); })->name('login')->middleware('auth.basic');
Route::get('/sale-rotation', [SaleController::class, 'index'])->name('sales.index');