AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

StoreDesignController.php 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Http\Controllers\Concerns\RendersStorefront;
  4. use App\Models\Product;
  5. use App\Storefront\RelatedProducts;
  6. use App\StorePlan\PlanSchema;
  7. use Illuminate\Http\RedirectResponse;
  8. use Illuminate\Http\Request;
  9. use Inertia\Response;
  10. /**
  11. * The store pages that come from the design: home, extra pages, shop and product.
  12. * Used for both the live store and the owner's preview (see App\Storefront\Storefront).
  13. */
  14. class StoreDesignController extends Controller
  15. {
  16. use RendersStorefront;
  17. /**
  18. * The home page.
  19. */
  20. public function preview(Request $request): Response
  21. {
  22. return $this->renderStorefront($request, $this->storefront($request), [
  23. 'type' => 'page',
  24. 'pageId' => PlanSchema::HOME_PAGE,
  25. ]);
  26. }
  27. /**
  28. * Any other page of the design, such as "about". Its id is its address.
  29. */
  30. public function page(Request $request): Response|RedirectResponse
  31. {
  32. $storefront = $this->storefront($request);
  33. $pageId = (string) $request->route('pageId');
  34. if ($pageId === PlanSchema::HOME_PAGE) {
  35. return redirect($storefront->path());
  36. }
  37. abort_unless(in_array($pageId, array_column($storefront->plan['pages'] ?? [], 'id'), true), 404);
  38. return $this->renderStorefront($request, $storefront, ['type' => 'page', 'pageId' => $pageId]);
  39. }
  40. /**
  41. * One collection's page: its name, description and active products.
  42. */
  43. public function collection(Request $request): Response
  44. {
  45. $storefront = $this->storefront($request);
  46. $collection = $storefront->store->collections()
  47. ->with(['products' => fn ($query) => $query->active()->with(Product::STOREFRONT_RELATIONS)])
  48. ->where('slug', (string) $request->route('collectionSlug'))
  49. ->firstOrFail();
  50. return $this->renderStorefront($request, $storefront, [
  51. 'type' => 'collection',
  52. 'collection' => $collection->toStorefront(),
  53. 'collectionProducts' => $collection->products->map(fn (Product $product) => $product->toStorefront())->values()->all(),
  54. ]);
  55. }
  56. /**
  57. * The shop page: every product shoppers may see.
  58. */
  59. public function shop(Request $request): Response
  60. {
  61. return $this->renderStorefront($request, $this->storefront($request), ['type' => 'shop']);
  62. }
  63. /**
  64. * One product's own page.
  65. */
  66. public function product(Request $request): Response
  67. {
  68. $storefront = $this->storefront($request);
  69. $product = $storefront->store->products()
  70. ->active()
  71. ->with(Product::STOREFRONT_RELATIONS)
  72. ->where('slug', (string) $request->route('productSlug'))
  73. ->firstOrFail();
  74. return $this->renderStorefront($request, $storefront, [
  75. 'type' => 'product',
  76. 'product' => $product->toStorefront(),
  77. 'related' => RelatedProducts::for($product)->map(fn (Product $item) => $item->toStorefront())->values()->all(),
  78. ]);
  79. }
  80. }