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

RendersStorefront.php 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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\Storefront\Storefront;
  7. use App\StorePlan\PlanSchema;
  8. use Illuminate\Http\Request;
  9. use Inertia\Inertia;
  10. use Inertia\Response;
  11. /**
  12. * Shared by the controllers that show store pages, both live and in the owner's preview.
  13. */
  14. trait RendersStorefront
  15. {
  16. private function storefront(Request $request): Storefront
  17. {
  18. return Storefront::fromRequest($request);
  19. }
  20. private function cart(Request $request, Store $store): Cart
  21. {
  22. return new Cart($request->session(), $store);
  23. }
  24. /**
  25. * Every store page gets the same basics: the design, 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, Storefront $storefront, array $view): Response
  30. {
  31. $store = $storefront->store;
  32. return Inertia::render('stores/preview', [
  33. 'storeName' => $store->name,
  34. 'language' => $store->language->value,
  35. 'plan' => $storefront->plan,
  36. 'fonts' => PlanSchema::FONTS,
  37. // Links inside the store are built on top of this address. It is empty for a live store.
  38. 'baseUrl' => $storefront->baseUrl,
  39. 'preview' => $storefront->preview,
  40. 'view' => $view,
  41. 'products' => $store->products()
  42. ->active()
  43. ->with('images')
  44. ->latest('id')
  45. ->limit(60)
  46. ->get()
  47. ->map(fn (Product $product) => $product->toStorefront()),
  48. 'cart' => $this->cart($request, $store)->toStorefront(),
  49. ]);
  50. }
  51. }