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

StoreStyleController.php 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\StorePlan\PlanSchema;
  4. use App\StorePlan\PlanValidator;
  5. use Illuminate\Http\RedirectResponse;
  6. use Illuminate\Http\Request;
  7. use Illuminate\Validation\Rule;
  8. use Inertia\Inertia;
  9. /**
  10. * The Design tab's Style box: a ready-made look (style, corner roundness and fonts), or single style options.
  11. * Colours are never touched. This changes the working design, so a live store shows it after "Publish changes".
  12. */
  13. class StoreStyleController extends Controller
  14. {
  15. public function update(Request $request, PlanValidator $validator, string $slug): RedirectResponse
  16. {
  17. $store = $request->user()->stores()->where('slug', $slug)->firstOrFail();
  18. abort_if($store->plan === null, 404);
  19. $rules = ['preset' => ['nullable', Rule::in(array_keys(PlanSchema::STYLE_PRESETS))], 'style' => ['nullable', 'array']];
  20. foreach (PlanSchema::STYLE_OPTIONS as $option => $values) {
  21. $rules["style.$option"] = ['nullable', Rule::in($values)];
  22. }
  23. $validated = $request->validate($rules);
  24. $plan = $store->plan;
  25. $preset = PlanSchema::STYLE_PRESETS[$validated['preset'] ?? ''] ?? null;
  26. if ($preset !== null) {
  27. $plan['theme']['radius'] = $preset['radius'];
  28. $plan['theme']['fonts'] = $preset['fonts'];
  29. $plan['theme']['style'] = $preset['style'];
  30. }
  31. if (is_array($validated['style'] ?? null)) {
  32. $plan['theme']['style'] = [...PlanSchema::STYLE_DEFAULTS, ...($plan['theme']['style'] ?? []), ...array_filter($validated['style'])];
  33. }
  34. $store->plan = $validator->validate($plan);
  35. $store->save();
  36. Inertia::flash('toast', ['type' => 'success', 'message' => $store->isPublished()
  37. ? __('Saved. Click "Publish changes" to show it on your live store.')
  38. : __('Style saved.')]);
  39. return to_route('stores.show', $store->slug);
  40. }
  41. }