AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

RendersStorefront.php 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace App\Http\Controllers\Concerns;
  3. use App\Commerce\Cart;
  4. use App\Models\Product;
  5. use App\Models\Store;
  6. use App\StorePlan\PlanSchema;
  7. use Illuminate\Http\Request;
  8. use Inertia\Inertia;
  9. use Inertia\Response;
  10. /**
  11. * Shared by the controllers that show storefront pages.
  12. * For now the storefront is a preview that only the store's owner can open. Step 5 makes it public.
  13. */
  14. trait RendersStorefront
  15. {
  16. private function ownedStore(Request $request, string $slug): Store
  17. {
  18. return $request->user()->stores()->where('slug', $slug)->firstOrFail();
  19. }
  20. private function cart(Request $request, Store $store): Cart
  21. {
  22. return new Cart($request->session(), $store);
  23. }
  24. /**
  25. * Every storefront page gets the same basics: the plan, the fonts, the product list and the cart.
  26. *
  27. * @param array<string, mixed> $view Which page to show.
  28. */
  29. private function renderStorefront(Request $request, Store $store, array $view): Response
  30. {
  31. abort_if($store->plan === null, 404);
  32. return Inertia::render('stores/preview', [
  33. 'storeName' => $store->name,
  34. 'language' => $store->language->value,
  35. 'plan' => $store->plan,
  36. 'fonts' => PlanSchema::FONTS,
  37. // Links inside the storefront are built on top of this address.
  38. 'baseUrl' => route('stores.preview', $store->slug, false),
  39. 'view' => $view,
  40. 'products' => $store->products()
  41. ->active()
  42. ->with('images')
  43. ->latest('id')
  44. ->limit(60)
  45. ->get()
  46. ->map(fn (Product $product) => $product->toStorefront()),
  47. 'cart' => $this->cart($request, $store)->toStorefront(),
  48. ]);
  49. }
  50. }