2026-07-31 17:41:55 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use Lunar\Models\Product;
|
|
|
|
|
|
|
|
|
|
class ProductController extends Controller
|
|
|
|
|
{
|
2026-08-08 14:50:10 +03:00
|
|
|
public function show(string $locale, Product $product)
|
2026-07-31 17:41:55 +03:00
|
|
|
{
|
|
|
|
|
$product->load([
|
|
|
|
|
"variants.prices.currency",
|
|
|
|
|
"variants.values.option",
|
|
|
|
|
"media",
|
|
|
|
|
"collections",
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$option = $product->variants->first()?->values->first()?->option;
|
|
|
|
|
|
|
|
|
|
$variantsData = $product->variants
|
|
|
|
|
->map(
|
|
|
|
|
fn($v) => [
|
|
|
|
|
"id" => $v->id,
|
|
|
|
|
"price" => $v->prices->first()?->price->decimal,
|
|
|
|
|
"image" => null, // variant-level media not differentiated yet
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
->values()
|
|
|
|
|
->toArray();
|
|
|
|
|
|
|
|
|
|
$firstImage = $product->media->first()?->getUrl();
|
|
|
|
|
|
|
|
|
|
// temp categories here
|
|
|
|
|
$categories = \Lunar\Models\Collection::orderBy("_lft")->get();
|
|
|
|
|
|
|
|
|
|
// dd($product);
|
|
|
|
|
|
|
|
|
|
return view("product.show", [
|
|
|
|
|
"categories" => $categories,
|
|
|
|
|
"product" => $product,
|
|
|
|
|
"option" => $option,
|
|
|
|
|
"variantsData" => $variantsData,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|