From 1f1eb7714e55a6eb11756cdae21568b6795f56d4 Mon Sep 17 00:00:00 2001 From: sky121113 Date: Mon, 15 Jun 2026 09:07:41 +0800 Subject: [PATCH] =?UTF-8?q?[FIX]=20=E4=BF=AE=E6=AD=A3=E5=A4=9A=E8=AA=9E?= =?UTF-8?q?=E7=B3=BB=E5=8D=87=E7=B4=9A=E5=B0=8E=E8=87=B4=E6=97=A2=E6=9C=89?= =?UTF-8?q?=E7=92=B0=E5=A2=83=E5=95=86=E5=93=81=E7=B7=A8=E8=BC=AF=E5=99=A8?= =?UTF-8?q?=E5=8F=AA=E5=89=A9=E7=B9=81=E4=B8=AD=20Tab?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 新增回填 migration:將既有機台 settings.languages 補為 ["zh_TW","en","ja"](僅補缺鍵/空值者,已設定者不動,以 DB 更新避免觸發機台事件),使 demo/prod 升級後公司語系聯集維持中英日、商品編輯器照常顯示三 Tab。 2. 商品編輯頁加保險:語系 Tab = 公司機台語系聯集 ∪「此商品已有翻譯的語系」,並依白名單排序,避免日後公司聯集縮減時藏掉既有翻譯而無法編輯。 Co-Authored-By: Claude Opus 4.8 --- ...000_backfill_machine_display_languages.php | 47 +++++++++++++++++++ resources/views/admin/products/edit.blade.php | 9 ++++ 2 files changed, 56 insertions(+) create mode 100644 database/migrations/2026_06_12_093000_backfill_machine_display_languages.php diff --git a/database/migrations/2026_06_12_093000_backfill_machine_display_languages.php b/database/migrations/2026_06_12_093000_backfill_machine_display_languages.php new file mode 100644 index 0000000..5fcb8fa --- /dev/null +++ b/database/migrations/2026_06_12_093000_backfill_machine_display_languages.php @@ -0,0 +1,47 @@ +select('id', 'settings')->orderBy('id') + ->chunkById(200, function ($machines) use ($default) { + foreach ($machines as $m) { + $settings = $m->settings ? json_decode($m->settings, true) : []; + if (!is_array($settings)) { + $settings = []; + } + // 已有非空 languages 者跳過 + if (!empty($settings['languages']) && is_array($settings['languages'])) { + continue; + } + $settings['languages'] = $default; + DB::table('machines')->where('id', $m->id)->update([ + 'settings' => json_encode($settings, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), + ]); + } + }); + } + + /** + * 不反向移除 languages:無法區分回填值與使用者後續手動設定值, + * 貿然移除恐誤刪設定,故 down 不動資料。 + */ + public function down(): void + { + // no-op + } +}; diff --git a/resources/views/admin/products/edit.blade.php b/resources/views/admin/products/edit.blade.php index a4f3651..1f56708 100644 --- a/resources/views/admin/products/edit.blade.php +++ b/resources/views/admin/products/edit.blade.php @@ -6,6 +6,15 @@ $localeLabels = config('locales.supported', ['zh_TW' => '繁體中文']); $locales = \App\Models\System\Company::activeLocalesFor($product->company_id); + // 保險:併入「此商品已有翻譯」的語系,避免公司聯集縮減時藏掉既有翻譯而無法編輯。 + $existingLocales = $product->translations->pluck('locale') + ->merge($product->specTranslations->pluck('locale')) + ->unique()->all(); + $order = array_keys($localeLabels); // 依白名單順序穩定排序 + $locales = collect($locales)->merge($existingLocales)->unique() + ->sortBy(fn ($l) => ($i = array_search($l, $order)) === false ? 999 : $i) + ->values()->all(); + $names = []; $specs = []; foreach ($locales as $locale) {