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) {