102 lines
3.8 KiB
PHP
102 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Shop;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Product;
|
|
|
|
class ProductController extends Controller
|
|
{
|
|
public function show(Product $product)
|
|
{
|
|
$product->load('category');
|
|
$related = Product::query()
|
|
->where('is_active', true)
|
|
->where('stock', '>', 0)
|
|
->where('category_id', $product->category_id)
|
|
->whereKeyNot($product->id)
|
|
->with('category')
|
|
->latest('id')
|
|
->take(4)
|
|
->get();
|
|
|
|
return view('shop.product', [
|
|
'product' => $product,
|
|
'specLabels' => $this->specLabelsForProduct($product),
|
|
'related' => $related,
|
|
]);
|
|
}
|
|
|
|
private function specLabelsForCategory(?string $slug): array
|
|
{
|
|
if (!$slug) {
|
|
return [];
|
|
}
|
|
|
|
return collect(config('product_specs.categories.' . $slug, []))
|
|
->mapWithKeys(fn (array $definition) => [$definition['key'] => $definition['label']])
|
|
->all();
|
|
}
|
|
|
|
private function specLabelsForProduct(Product $product): array
|
|
{
|
|
$labels = $this->specLabelsForCategory($product->category?->slug);
|
|
$fallback = $this->defaultSpecLabels();
|
|
|
|
foreach (array_keys((array) ($product->specs ?? [])) as $key) {
|
|
if (!isset($labels[$key])) {
|
|
$labels[$key] = $fallback[$key] ?? str_replace('_', ' ', $key);
|
|
}
|
|
}
|
|
|
|
return $labels;
|
|
}
|
|
|
|
private function defaultSpecLabels(): array
|
|
{
|
|
return [
|
|
'manufacturer' => 'Производитель',
|
|
'socket_type' => 'Тип сокета',
|
|
'cpu_type' => 'Тип процессора',
|
|
'form_factor' => 'Форм-фактор',
|
|
'cpu_socket' => 'Сокет для процессора',
|
|
'condition' => 'Состояние',
|
|
'chipset' => 'Чипсет',
|
|
'memory_type' => 'Тип памяти',
|
|
'pcie_version' => 'Версия PCI Express',
|
|
'wifi_standard' => 'Стандарт Wi-Fi',
|
|
'max_memory' => 'Максимальный объем памяти',
|
|
'cache' => 'Объем кэша',
|
|
'capacity' => 'Объем',
|
|
'gpu' => 'GPU',
|
|
'vram' => 'Объем видеопамяти',
|
|
'vram_type' => 'Тип видеопамяти',
|
|
'kit' => 'Количество модулей',
|
|
'frequency' => 'Частота',
|
|
'power' => 'Мощность',
|
|
'efficiency' => 'Сертификат 80 Plus',
|
|
'size' => 'Типоразмер',
|
|
'gpu_length' => 'Макс. длина видеокарты',
|
|
'intel_socket' => 'Сокет Intel',
|
|
'amd_socket' => 'Сокет AMD',
|
|
'fan_speed' => 'Скорость вращения',
|
|
'fans' => 'Количество вентиляторов',
|
|
'type' => 'Тип',
|
|
'model' => 'Модель',
|
|
'color' => 'Цвет',
|
|
'screen_size' => 'Диагональ экрана',
|
|
'cpu_brand' => 'Производитель процессора',
|
|
'cpu_model' => 'Модель процессора',
|
|
'ram' => 'Оперативная память',
|
|
'storage' => 'Накопитель',
|
|
'panel' => 'Тип матрицы',
|
|
'resolution' => 'Разрешение экрана',
|
|
'refresh_rate' => 'Частота обновления',
|
|
'smart_tv' => 'Smart TV',
|
|
'cores' => 'Количество ядер',
|
|
'gpu_brand' => 'Производитель видеокарты',
|
|
'gpu_model' => 'Модель видеокарты',
|
|
];
|
|
}
|
|
}
|