81 lines
2.6 KiB
PHP
81 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Services\MagentoCategoryMigrationService;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class AttributesController extends Controller
|
|
{
|
|
protected $migrationService;
|
|
|
|
public function __construct(MagentoCategoryMigrationService $migrationService)
|
|
{
|
|
$this->migrationService = $migrationService;
|
|
}
|
|
|
|
/**
|
|
* Show the attributes page
|
|
*/
|
|
public function index()
|
|
{
|
|
$m1Attributes = $this->migrationService->getMagento1Attributes();
|
|
$m2Attributes = $this->migrationService->getMagento2Attributes();
|
|
$m1AttributesMissingInM2 = $this->migrationService->getM1AttributesMissingInM2();
|
|
$m1AttributeGroups = $this->migrationService->getMagento1AttributeGroups();
|
|
$m2AttributeGroups = $this->migrationService->getMagento2AttributeGroups();
|
|
$m1AttributeGroupsMissingInM2 = $this->migrationService->getM1AttributeGroupsMissingInM2();
|
|
|
|
return view('attributes.index', [
|
|
'm1Attributes' => $m1Attributes,
|
|
'm2Attributes' => $m2Attributes,
|
|
'm1AttributesMissingInM2' => $m1AttributesMissingInM2,
|
|
'm1AttributeGroups' => $m1AttributeGroups,
|
|
'm2AttributeGroups' => $m2AttributeGroups,
|
|
'm1AttributeGroupsMissingInM2' => $m1AttributeGroupsMissingInM2,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Migrate an attribute from Magento 1 to Magento 2
|
|
*/
|
|
public function migrateAttribute(Request $request, $attributeId)
|
|
{
|
|
try {
|
|
$result = $this->migrationService->migrateAttribute($attributeId);
|
|
|
|
return response()->json($result, $result['success'] ? 200 : 400);
|
|
|
|
} catch (\Exception $e) {
|
|
Log::error('Attribute migration error: ' . $e->getMessage());
|
|
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => 'Migration failed: ' . $e->getMessage(),
|
|
], 500);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Migrate an attribute group from Magento 1 to Magento 2
|
|
*/
|
|
public function migrateAttributeGroup(Request $request, $groupId, $setId)
|
|
{
|
|
try {
|
|
$result = $this->migrationService->migrateAttributeGroup($groupId, $setId);
|
|
|
|
return response()->json($result, $result['success'] ? 200 : 400);
|
|
|
|
} catch (\Exception $e) {
|
|
Log::error('Attribute group migration error: ' . $e->getMessage());
|
|
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => 'Migration failed: ' . $e->getMessage(),
|
|
], 500);
|
|
}
|
|
}
|
|
}
|
|
|