| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
-
- namespace App\Http\Controllers;
-
- use App\Http\Controllers\Concerns\RendersStorefront;
- use App\Models\Product;
- use App\Storefront\RelatedProducts;
- use App\StorePlan\PlanSchema;
- use Illuminate\Http\RedirectResponse;
- use Illuminate\Http\Request;
- use Inertia\Response;
-
- /**
- * The store pages that come from the design: home, extra pages, shop and product.
- * Used for both the live store and the owner's preview (see App\Storefront\Storefront).
- */
- class StoreDesignController extends Controller
- {
- use RendersStorefront;
-
- /**
- * The home page.
- */
- public function preview(Request $request): Response
- {
- return $this->renderStorefront($request, $this->storefront($request), [
- 'type' => 'page',
- 'pageId' => PlanSchema::HOME_PAGE,
- ]);
- }
-
- /**
- * Any other page of the design, such as "about". Its id is its address.
- */
- public function page(Request $request): Response|RedirectResponse
- {
- $storefront = $this->storefront($request);
- $pageId = (string) $request->route('pageId');
-
- if ($pageId === PlanSchema::HOME_PAGE) {
- return redirect($storefront->path());
- }
-
- abort_unless(in_array($pageId, array_column($storefront->plan['pages'] ?? [], 'id'), true), 404);
-
- return $this->renderStorefront($request, $storefront, ['type' => 'page', 'pageId' => $pageId]);
- }
-
- /**
- * The shop page: every product shoppers may see.
- */
- public function shop(Request $request): Response
- {
- return $this->renderStorefront($request, $this->storefront($request), ['type' => 'shop']);
- }
-
- /**
- * One product's own page.
- */
- public function product(Request $request): Response
- {
- $storefront = $this->storefront($request);
-
- $product = $storefront->store->products()
- ->active()
- ->with(Product::STOREFRONT_RELATIONS)
- ->where('slug', (string) $request->route('productSlug'))
- ->firstOrFail();
-
- return $this->renderStorefront($request, $storefront, [
- 'type' => 'product',
- 'product' => $product->toStorefront(),
- 'related' => RelatedProducts::for($product)->map(fn (Product $item) => $item->toStorefront())->values()->all(),
- ]);
- }
- }
|