AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

PlanUpgrader.php 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace App\StorePlan;
  3. /**
  4. * Brings a plan saved in an older format up to the current one.
  5. *
  6. * Version 1: one flat list of sections, with the header and footer inside it.
  7. * Version 2: header and footer at the top of the plan, and a list of pages.
  8. */
  9. final class PlanUpgrader
  10. {
  11. /**
  12. * @param array<string, mixed> $plan
  13. * @return array<string, mixed>
  14. */
  15. public static function upgrade(array $plan): array
  16. {
  17. if (($plan['version'] ?? null) !== 1) {
  18. return $plan;
  19. }
  20. $header = null;
  21. $footer = null;
  22. $body = [];
  23. foreach ($plan['sections'] ?? [] as $section) {
  24. $type = $section['type'] ?? null;
  25. $shared = ['variant' => $section['variant'] ?? null, 'content' => $section['content'] ?? []];
  26. if ($type === 'header' && $header === null) {
  27. $header = $shared;
  28. } elseif ($type === 'footer') {
  29. $footer = $shared;
  30. } elseif ($type !== 'header') {
  31. $body[] = $section;
  32. }
  33. }
  34. return [
  35. 'version' => 2,
  36. 'theme' => $plan['theme'] ?? [],
  37. 'header' => $header ?? ['variant' => 'simple', 'content' => ['logoText' => 'Store', 'links' => []]],
  38. 'footer' => $footer ?? ['variant' => 'simple', 'content' => ['text' => '', 'links' => []]],
  39. 'pages' => [
  40. ['id' => PlanSchema::HOME_PAGE, 'title' => 'Home', 'sections' => $body],
  41. ],
  42. ];
  43. }
  44. }