migrationService = $migrationService; } /** * Show the category migration page */ public function index() { $m1Stores = $this->migrationService->getMagento1Stores(); $m2Stores = $this->migrationService->getMagento2Stores(); $connectionTest = $this->migrationService->testConnections(); $m1Categories = $this->migrationService->getMagento1Categories(); $m2Categories = $this->migrationService->getMagento2Categories(); return view('migration.index', [ 'm1Stores' => $m1Stores, 'm2Stores' => $m2Stores, 'connectionTest' => $connectionTest, 'm1CategoriesCount' => $m1Categories->count(), 'm2CategoriesCount' => $m2Categories->count(), ]); } /** * Execute the migration */ public function migrate(Request $request) { $request->validate([ 'store_mapping' => 'required|array', 'store_mapping.*' => 'required|integer', ]); try { $storeMapping = $request->input('store_mapping'); // Convert array format: ['m1_store_id' => 'm2_store_id'] $mapping = []; foreach ($storeMapping as $m1StoreId => $m2StoreId) { $mapping[(int)$m1StoreId] = (int)$m2StoreId; } $result = $this->migrationService->migrateCategories($mapping); return response()->json($result); } catch (\Exception $e) { Log::error('Migration error: ' . $e->getMessage()); return response()->json([ 'success' => false, 'message' => 'Migration failed: ' . $e->getMessage(), ], 500); } } }