From 64ddd5bb014cd3edd226181e0beae112c0a02f9e Mon Sep 17 00:00:00 2001 From: Chris Rosenau Date: Sat, 8 Nov 2025 15:35:10 -0700 Subject: [PATCH] adding attributes --- .../MagentoMigrationController.php | 8 + .../MagentoCategoryMigrationService.php | 174 +++++++++++++++++ resources/views/migration/index.blade.php | 180 ++++++++++++++++++ 3 files changed, 362 insertions(+) diff --git a/app/Http/Controllers/MagentoMigrationController.php b/app/Http/Controllers/MagentoMigrationController.php index 75310f9..e764bdf 100644 --- a/app/Http/Controllers/MagentoMigrationController.php +++ b/app/Http/Controllers/MagentoMigrationController.php @@ -26,6 +26,10 @@ public function index() $m1Categories = $this->migrationService->getMagento1Categories(); $m2Categories = $this->migrationService->getMagento2Categories(); $m2CategoriesNotInM1 = $this->migrationService->getM2CategoriesNotInM1(); + $m1Attributes = $this->migrationService->getMagento1Attributes(); + $m2Attributes = $this->migrationService->getMagento2Attributes(); + $m1AttributeGroups = $this->migrationService->getMagento1AttributeGroups(); + $m2AttributeGroups = $this->migrationService->getMagento2AttributeGroups(); return view('migration.index', [ 'm1Stores' => $m1Stores, @@ -34,6 +38,10 @@ public function index() 'm1CategoriesCount' => $m1Categories->count(), 'm2CategoriesCount' => $m2Categories->count(), 'm2CategoriesNotInM1' => $m2CategoriesNotInM1, + 'm1Attributes' => $m1Attributes, + 'm2Attributes' => $m2Attributes, + 'm1AttributeGroups' => $m1AttributeGroups, + 'm2AttributeGroups' => $m2AttributeGroups, ]); } diff --git a/app/Services/MagentoCategoryMigrationService.php b/app/Services/MagentoCategoryMigrationService.php index f87222a..023e096 100644 --- a/app/Services/MagentoCategoryMigrationService.php +++ b/app/Services/MagentoCategoryMigrationService.php @@ -968,6 +968,180 @@ public function testConnections() return $results; } + /** + * Get all category attributes from Magento 1 + */ + public function getMagento1Attributes() + { + try { + // Get entity type ID for catalog_category + $entityTypeId = DB::connection($this->magento1Connection) + ->table($this->magento1Prefix . 'eav_entity_type') + ->where('entity_type_code', 'catalog_category') + ->value('entity_type_id'); + + if (!$entityTypeId) { + return collect([]); + } + + // Get all attributes for catalog_category + $attributes = DB::connection($this->magento1Connection) + ->table($this->magento1Prefix . 'eav_attribute') + ->where('entity_type_id', $entityTypeId) + ->select('attribute_id', 'attribute_code', 'backend_type', 'frontend_input', 'frontend_label', 'is_required', 'is_user_defined', 'default_value') + ->orderBy('attribute_code') + ->get(); + + return $attributes; + } catch (Exception $e) { + Log::error('Error fetching Magento 1 attributes: ' . $e->getMessage()); + return collect([]); + } + } + + /** + * Get all category attributes from Magento 2 + */ + public function getMagento2Attributes() + { + try { + // Get entity type ID for catalog_category + $entityTypeId = DB::connection($this->magento2Connection) + ->table($this->magento2Prefix . 'eav_entity_type') + ->where('entity_type_code', 'catalog_category') + ->value('entity_type_id'); + + if (!$entityTypeId) { + return collect([]); + } + + // Get all attributes for catalog_category + $attributes = DB::connection($this->magento2Connection) + ->table($this->magento2Prefix . 'eav_attribute') + ->where('entity_type_id', $entityTypeId) + ->select('attribute_id', 'attribute_code', 'backend_type', 'frontend_input', 'frontend_label', 'is_required', 'is_user_defined', 'default_value') + ->orderBy('attribute_code') + ->get(); + + return $attributes; + } catch (Exception $e) { + Log::error('Error fetching Magento 2 attributes: ' . $e->getMessage()); + return collect([]); + } + } + + /** + * Get attribute groups from Magento 1 + */ + public function getMagento1AttributeGroups() + { + try { + // Get entity type ID for catalog_category + $entityTypeId = DB::connection($this->magento1Connection) + ->table($this->magento1Prefix . 'eav_entity_type') + ->where('entity_type_code', 'catalog_category') + ->value('entity_type_id'); + + if (!$entityTypeId) { + return collect([]); + } + + // Get attribute sets for catalog_category + $attributeSets = DB::connection($this->magento1Connection) + ->table($this->magento1Prefix . 'eav_attribute_set') + ->where('entity_type_id', $entityTypeId) + ->get(); + + $groups = collect([]); + + foreach ($attributeSets as $set) { + // Get attribute groups for this set + $setGroups = DB::connection($this->magento1Connection) + ->table($this->magento1Prefix . 'eav_attribute_group') + ->where('attribute_set_id', $set->attribute_set_id) + ->select('attribute_group_id', 'attribute_set_id', 'attribute_group_name', 'sort_order') + ->orderBy('sort_order') + ->get(); + + foreach ($setGroups as $group) { + // Get attributes in this group + $attributeIds = DB::connection($this->magento1Connection) + ->table($this->magento1Prefix . 'eav_entity_attribute') + ->where('attribute_set_id', $set->attribute_set_id) + ->where('attribute_group_id', $group->attribute_group_id) + ->pluck('attribute_id') + ->toArray(); + + $group->attribute_set_name = $set->attribute_set_name ?? 'Default'; + $group->attribute_count = count($attributeIds); + $group->attribute_ids = $attributeIds; + $groups->push($group); + } + } + + return $groups; + } catch (Exception $e) { + Log::error('Error fetching Magento 1 attribute groups: ' . $e->getMessage()); + return collect([]); + } + } + + /** + * Get attribute groups from Magento 2 + */ + public function getMagento2AttributeGroups() + { + try { + // Get entity type ID for catalog_category + $entityTypeId = DB::connection($this->magento2Connection) + ->table($this->magento2Prefix . 'eav_entity_type') + ->where('entity_type_code', 'catalog_category') + ->value('entity_type_id'); + + if (!$entityTypeId) { + return collect([]); + } + + // Get attribute sets for catalog_category + $attributeSets = DB::connection($this->magento2Connection) + ->table($this->magento2Prefix . 'eav_attribute_set') + ->where('entity_type_id', $entityTypeId) + ->get(); + + $groups = collect([]); + + foreach ($attributeSets as $set) { + // Get attribute groups for this set + $setGroups = DB::connection($this->magento2Connection) + ->table($this->magento2Prefix . 'eav_attribute_group') + ->where('attribute_set_id', $set->attribute_set_id) + ->select('attribute_group_id', 'attribute_set_id', 'attribute_group_name', 'sort_order') + ->orderBy('sort_order') + ->get(); + + foreach ($setGroups as $group) { + // Get attributes in this group + $attributeIds = DB::connection($this->magento2Connection) + ->table($this->magento2Prefix . 'eav_entity_attribute') + ->where('attribute_set_id', $set->attribute_set_id) + ->where('attribute_group_id', $group->attribute_group_id) + ->pluck('attribute_id') + ->toArray(); + + $group->attribute_set_name = $set->attribute_set_name ?? 'Default'; + $group->attribute_count = count($attributeIds); + $group->attribute_ids = $attributeIds; + $groups->push($group); + } + } + + return $groups; + } catch (Exception $e) { + Log::error('Error fetching Magento 2 attribute groups: ' . $e->getMessage()); + return collect([]); + } + } + /** * Recursively delete all children of a category */ diff --git a/resources/views/migration/index.blade.php b/resources/views/migration/index.blade.php index 378b9ae..efd9e50 100644 --- a/resources/views/migration/index.blade.php +++ b/resources/views/migration/index.blade.php @@ -499,6 +499,7 @@ + @@ -735,6 +736,185 @@ + + +
+ +
+

📦 Attribute Groups

+

View attribute groups that organize attributes within attribute sets:

+ +
+ +
+

Magento 1 Attribute Groups ({{ $m1AttributeGroups->count() }})

+
+ @if($m1AttributeGroups->count() > 0) + + + + + + + + + + + + @foreach($m1AttributeGroups as $group) + + + + + + + + @endforeach + +
Group IDGroup NameAttribute SetAttributesSort Order
{{ $group->attribute_group_id }}{{ $group->attribute_group_name ?? 'N/A' }}{{ $group->attribute_set_name ?? 'N/A' }} + {{ $group->attribute_count ?? 0 }} + {{ $group->sort_order ?? 'N/A' }}
+ @else +
+ No attribute groups found. Please check your database connection. +
+ @endif +
+
+ + +
+

Magento 2 Attribute Groups ({{ $m2AttributeGroups->count() }})

+
+ @if($m2AttributeGroups->count() > 0) + + + + + + + + + + + + @foreach($m2AttributeGroups as $group) + + + + + + + + @endforeach + +
Group IDGroup NameAttribute SetAttributesSort Order
{{ $group->attribute_group_id }}{{ $group->attribute_group_name ?? 'N/A' }}{{ $group->attribute_set_name ?? 'N/A' }} + {{ $group->attribute_count ?? 0 }} + {{ $group->sort_order ?? 'N/A' }}
+ @else +
+ No attribute groups found. Please check your database connection. +
+ @endif +
+
+
+
+ + +
+

📋 Category Attributes

+

View all category attributes from Magento 1 and Magento 2

+ +
+ +
+

Magento 1 Attributes ({{ $m1Attributes->count() }})

+
+ @if($m1Attributes->count() > 0) + + + + + + + + + + + + + @foreach($m1Attributes as $attr) + + + + + + + + + @endforeach + +
IDCodeLabelTypeInputRequired
{{ $attr->attribute_id }}{{ $attr->attribute_code }}{{ $attr->frontend_label ?? 'N/A' }}{{ $attr->backend_type ?? 'N/A' }}{{ $attr->frontend_input ?? 'N/A' }} + @if($attr->is_required ?? 0) + Yes + @else + No + @endif +
+ @else +
+ No attributes found. Please check your database connection. +
+ @endif +
+
+ + +
+

Magento 2 Attributes ({{ $m2Attributes->count() }})

+
+ @if($m2Attributes->count() > 0) + + + + + + + + + + + + + @foreach($m2Attributes as $attr) + + + + + + + + + @endforeach + +
IDCodeLabelTypeInputRequired
{{ $attr->attribute_id }}{{ $attr->attribute_code }}{{ $attr->frontend_label ?? 'N/A' }}{{ $attr->backend_type ?? 'N/A' }}{{ $attr->frontend_input ?? 'N/A' }} + @if($attr->is_required ?? 0) + Yes + @else + No + @endif +
+ @else +
+ No attributes found. Please check your database connection. +
+ @endif +
+
+
+
+