82 lines
2.4 KiB
PHP
82 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Services\MagentoCategoryMigrationService;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class CustomersController extends Controller
|
|
{
|
|
protected $migrationService;
|
|
|
|
public function __construct(MagentoCategoryMigrationService $migrationService)
|
|
{
|
|
$this->migrationService = $migrationService;
|
|
}
|
|
|
|
/**
|
|
* Show the customers page
|
|
*/
|
|
public function index()
|
|
{
|
|
$m1Customers = $this->migrationService->getMagento1Customers();
|
|
$m2Customers = $this->migrationService->getMagento2Customers();
|
|
$m1CustomersNotInM2 = $this->migrationService->getM1CustomersNotInM2();
|
|
$m2CustomersNotInM1 = $this->migrationService->getM2CustomersNotInM1();
|
|
|
|
return view('customers.index', [
|
|
'm1Customers' => $m1Customers,
|
|
'm2Customers' => $m2Customers,
|
|
'm1CustomersNotInM2' => $m1CustomersNotInM2,
|
|
'm2CustomersNotInM1' => $m2CustomersNotInM1,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Migrate all customers from Magento 1 to Magento 2
|
|
*/
|
|
public function migrateCustomers(Request $request)
|
|
{
|
|
try {
|
|
$dryRun = $request->input('dry_run', false);
|
|
$result = $this->migrationService->migrateCustomers($dryRun);
|
|
|
|
return response()->json($result, $result['success'] ? 200 : 400);
|
|
|
|
} catch (\Exception $e) {
|
|
Log::error('Customer migration error: ' . $e->getMessage());
|
|
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => 'Migration failed: ' . $e->getMessage(),
|
|
'added' => 0,
|
|
'updated' => 0,
|
|
'errors' => 0,
|
|
'log' => []
|
|
], 500);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Delete a single customer from Magento 2
|
|
*/
|
|
public function deleteM2Customer(Request $request, $customerId)
|
|
{
|
|
try {
|
|
$result = $this->migrationService->deleteM2Customer($customerId);
|
|
|
|
return response()->json($result, $result['success'] ? 200 : 400);
|
|
|
|
} catch (\Exception $e) {
|
|
Log::error('Delete M2 customer error: ' . $e->getMessage());
|
|
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => 'Deletion failed: ' . $e->getMessage()
|
|
], 500);
|
|
}
|
|
}
|
|
}
|
|
|