1247 lines
47 KiB
PHP
1247 lines
47 KiB
PHP
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Magento Migration Tool</title>
|
|
<style>
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
min-height: 100vh;
|
|
padding: 20px;
|
|
}
|
|
|
|
.container {
|
|
max-width: 1200px;
|
|
margin: 0 auto;
|
|
background: white;
|
|
border-radius: 12px;
|
|
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
|
|
overflow: hidden;
|
|
}
|
|
|
|
.header {
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
color: white;
|
|
padding: 30px;
|
|
text-align: center;
|
|
}
|
|
|
|
.header h1 {
|
|
font-size: 2.5em;
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
.header p {
|
|
opacity: 0.9;
|
|
font-size: 1.1em;
|
|
}
|
|
|
|
.content {
|
|
padding: 30px;
|
|
}
|
|
|
|
.section {
|
|
margin-bottom: 30px;
|
|
padding: 20px;
|
|
background: #f8f9fa;
|
|
border-radius: 8px;
|
|
border-left: 4px solid #667eea;
|
|
}
|
|
|
|
.section h2 {
|
|
color: #333;
|
|
margin-bottom: 15px;
|
|
font-size: 1.5em;
|
|
}
|
|
|
|
.connection-status {
|
|
display: flex;
|
|
gap: 20px;
|
|
margin-top: 15px;
|
|
}
|
|
|
|
.status-badge {
|
|
padding: 10px 20px;
|
|
border-radius: 6px;
|
|
font-weight: 600;
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
}
|
|
|
|
.status-badge.success {
|
|
background: #d4edda;
|
|
color: #155724;
|
|
}
|
|
|
|
.status-badge.error {
|
|
background: #f8d7da;
|
|
color: #721c24;
|
|
}
|
|
|
|
.store-mapping {
|
|
display: grid;
|
|
grid-template-columns: 1fr auto 1fr;
|
|
gap: 15px;
|
|
align-items: center;
|
|
margin-top: 15px;
|
|
}
|
|
|
|
.store-select {
|
|
padding: 12px;
|
|
border: 2px solid #ddd;
|
|
border-radius: 6px;
|
|
font-size: 1em;
|
|
width: 100%;
|
|
background: white;
|
|
}
|
|
|
|
.store-select:focus {
|
|
outline: none;
|
|
border-color: #667eea;
|
|
}
|
|
|
|
.arrow {
|
|
font-size: 1.5em;
|
|
color: #667eea;
|
|
text-align: center;
|
|
}
|
|
|
|
.btn {
|
|
padding: 12px 30px;
|
|
border: none;
|
|
border-radius: 6px;
|
|
font-size: 1em;
|
|
font-weight: 600;
|
|
cursor: pointer;
|
|
transition: all 0.3s;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.5px;
|
|
}
|
|
|
|
.btn-primary {
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
color: white;
|
|
}
|
|
|
|
.btn-primary:hover {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
|
|
}
|
|
|
|
.btn-primary:disabled {
|
|
opacity: 0.6;
|
|
cursor: not-allowed;
|
|
transform: none;
|
|
}
|
|
|
|
.btn-secondary {
|
|
background: #6c757d;
|
|
color: white;
|
|
}
|
|
|
|
.btn-secondary:hover {
|
|
background: #5a6268;
|
|
}
|
|
|
|
.actions {
|
|
display: flex;
|
|
gap: 15px;
|
|
margin-top: 20px;
|
|
}
|
|
|
|
.log-container {
|
|
background: #1e1e1e;
|
|
color: #d4d4d4;
|
|
padding: 20px;
|
|
border-radius: 6px;
|
|
max-height: 400px;
|
|
overflow-y: auto;
|
|
font-family: 'Courier New', monospace;
|
|
font-size: 0.9em;
|
|
margin-top: 15px;
|
|
display: none;
|
|
}
|
|
|
|
.log-container.active {
|
|
display: block;
|
|
}
|
|
|
|
.log-entry {
|
|
margin-bottom: 5px;
|
|
padding: 5px 0;
|
|
}
|
|
|
|
.log-entry.error {
|
|
color: #f48771;
|
|
}
|
|
|
|
.log-entry.success {
|
|
color: #4ec9b0;
|
|
}
|
|
|
|
.info-box {
|
|
background: #e7f3ff;
|
|
border-left: 4px solid #2196F3;
|
|
padding: 15px;
|
|
border-radius: 4px;
|
|
margin-top: 15px;
|
|
}
|
|
|
|
.info-box p {
|
|
margin: 5px 0;
|
|
color: #1976D2;
|
|
}
|
|
|
|
.loading {
|
|
display: none;
|
|
text-align: center;
|
|
padding: 20px;
|
|
}
|
|
|
|
.loading.active {
|
|
display: block;
|
|
}
|
|
|
|
.spinner {
|
|
border: 4px solid #f3f3f3;
|
|
border-top: 4px solid #667eea;
|
|
border-radius: 50%;
|
|
width: 40px;
|
|
height: 40px;
|
|
animation: spin 1s linear infinite;
|
|
margin: 0 auto;
|
|
}
|
|
|
|
@keyframes spin {
|
|
0% { transform: rotate(0deg); }
|
|
100% { transform: rotate(360deg); }
|
|
}
|
|
|
|
.stats {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
|
gap: 15px;
|
|
margin-top: 15px;
|
|
}
|
|
|
|
.stat-card {
|
|
background: white;
|
|
padding: 20px;
|
|
border-radius: 8px;
|
|
text-align: center;
|
|
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
|
}
|
|
|
|
.stat-card .number {
|
|
font-size: 2em;
|
|
font-weight: bold;
|
|
color: #667eea;
|
|
}
|
|
|
|
.stat-card .label {
|
|
color: #666;
|
|
margin-top: 5px;
|
|
}
|
|
|
|
/* Tabs */
|
|
.tabs {
|
|
display: flex;
|
|
border-bottom: 2px solid #ddd;
|
|
margin-bottom: 20px;
|
|
background: #f8f9fa;
|
|
border-radius: 8px 8px 0 0;
|
|
}
|
|
|
|
.tab {
|
|
padding: 15px 30px;
|
|
cursor: pointer;
|
|
border: none;
|
|
background: transparent;
|
|
font-size: 1em;
|
|
font-weight: 600;
|
|
color: #666;
|
|
transition: all 0.3s;
|
|
border-bottom: 3px solid transparent;
|
|
margin-bottom: -2px;
|
|
}
|
|
|
|
.tab:hover {
|
|
background: #e9ecef;
|
|
color: #333;
|
|
}
|
|
|
|
.tab.active {
|
|
color: #667eea;
|
|
border-bottom-color: #667eea;
|
|
background: white;
|
|
}
|
|
|
|
.tab-content {
|
|
display: none;
|
|
}
|
|
|
|
.tab-content.active {
|
|
display: block;
|
|
}
|
|
|
|
/* Tree View */
|
|
.tree-container {
|
|
background: white;
|
|
border: 1px solid #ddd;
|
|
border-radius: 6px;
|
|
padding: 20px;
|
|
max-height: 600px;
|
|
overflow-y: auto;
|
|
}
|
|
|
|
.tree-node {
|
|
margin: 5px 0;
|
|
}
|
|
|
|
.tree-node-item {
|
|
display: flex;
|
|
align-items: center;
|
|
padding: 8px 12px;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
user-select: none;
|
|
transition: background 0.2s;
|
|
}
|
|
|
|
.tree-node-item:hover {
|
|
background: #f0f0f0;
|
|
}
|
|
|
|
.tree-toggle {
|
|
width: 20px;
|
|
height: 20px;
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
margin-right: 8px;
|
|
font-size: 12px;
|
|
color: #666;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.tree-toggle.expanded::before {
|
|
content: '▼';
|
|
}
|
|
|
|
.tree-toggle.collapsed::before {
|
|
content: '▶';
|
|
}
|
|
|
|
.tree-toggle.leaf {
|
|
width: 20px;
|
|
margin-right: 8px;
|
|
}
|
|
|
|
.tree-label {
|
|
flex: 1;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
}
|
|
|
|
.tree-label-text {
|
|
font-weight: 500;
|
|
color: #333;
|
|
}
|
|
|
|
.tree-badge {
|
|
padding: 2px 8px;
|
|
border-radius: 12px;
|
|
font-size: 0.75em;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.tree-badge.active {
|
|
background: #d4edda;
|
|
color: #155724;
|
|
}
|
|
|
|
.tree-badge.inactive {
|
|
background: #f8d7da;
|
|
color: #721c24;
|
|
}
|
|
|
|
.tree-children {
|
|
margin-left: 28px;
|
|
border-left: 2px solid #e0e0e0;
|
|
padding-left: 12px;
|
|
display: none;
|
|
}
|
|
|
|
.tree-children.expanded {
|
|
display: block;
|
|
}
|
|
|
|
.tree-loading {
|
|
text-align: center;
|
|
padding: 40px;
|
|
color: #666;
|
|
}
|
|
|
|
.tree-error {
|
|
background: #f8d7da;
|
|
color: #721c24;
|
|
padding: 15px;
|
|
border-radius: 6px;
|
|
margin: 10px 0;
|
|
}
|
|
|
|
.tree-delete-btn {
|
|
background: #dc3545;
|
|
color: white;
|
|
border: none;
|
|
border-radius: 4px;
|
|
padding: 4px 8px;
|
|
font-size: 0.75em;
|
|
cursor: pointer;
|
|
margin-left: 8px;
|
|
transition: background 0.2s;
|
|
}
|
|
|
|
.tree-delete-btn:hover {
|
|
background: #c82333;
|
|
}
|
|
|
|
.tree-delete-btn:disabled {
|
|
background: #ccc;
|
|
cursor: not-allowed;
|
|
}
|
|
|
|
.tree-rename-btn {
|
|
background: #28a745;
|
|
color: white;
|
|
border: none;
|
|
border-radius: 4px;
|
|
padding: 4px 8px;
|
|
font-size: 0.75em;
|
|
cursor: pointer;
|
|
margin-left: 8px;
|
|
transition: background 0.2s;
|
|
}
|
|
|
|
.tree-rename-btn:hover {
|
|
background: #218838;
|
|
}
|
|
|
|
.tree-rename-input {
|
|
padding: 4px 8px;
|
|
border: 2px solid #28a745;
|
|
border-radius: 4px;
|
|
font-size: 0.9em;
|
|
width: 200px;
|
|
margin-left: 8px;
|
|
}
|
|
|
|
.tree-rename-input:focus {
|
|
outline: none;
|
|
border-color: #218838;
|
|
}
|
|
|
|
.tree-rename-actions {
|
|
display: inline-flex;
|
|
gap: 5px;
|
|
margin-left: 8px;
|
|
}
|
|
|
|
.tree-rename-save-btn, .tree-rename-cancel-btn {
|
|
padding: 4px 8px;
|
|
border: none;
|
|
border-radius: 4px;
|
|
font-size: 0.75em;
|
|
cursor: pointer;
|
|
transition: background 0.2s;
|
|
}
|
|
|
|
.tree-rename-save-btn {
|
|
background: #28a745;
|
|
color: white;
|
|
}
|
|
|
|
.tree-rename-save-btn:hover {
|
|
background: #218838;
|
|
}
|
|
|
|
.tree-rename-cancel-btn {
|
|
background: #6c757d;
|
|
color: white;
|
|
}
|
|
|
|
.tree-rename-cancel-btn:hover {
|
|
background: #5a6268;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<div class="header">
|
|
<h1>🛒 Magento Migration</h1>
|
|
<p>Migrate categories from Magento 1 to Magento 2 with multi-store support</p>
|
|
</div>
|
|
|
|
<div class="content">
|
|
<!-- Tabs -->
|
|
<div class="tabs">
|
|
<button class="tab active" onclick="switchTab('connections', this)">Database Connections</button>
|
|
<button class="tab" onclick="switchTab('categories', this)">Category Trees</button>
|
|
<button class="tab" onclick="switchTab('migration', this)">Category Migration</button>
|
|
</div>
|
|
|
|
<!-- Database Connections Tab -->
|
|
<div id="tab-connections" class="tab-content active">
|
|
<div class="section">
|
|
<h2>📡 Database Connections</h2>
|
|
<div class="connection-status">
|
|
<div>
|
|
<strong>Magento 1:</strong>
|
|
<span class="status-badge {{ $connectionTest['magento1'] ? 'success' : 'error' }}">
|
|
{{ $connectionTest['magento1'] ? '✓ Connected' : '✗ Failed' }}
|
|
</span>
|
|
@if(!$connectionTest['magento1'] && isset($connectionTest['magento1_error']))
|
|
<div style="color: #721c24; margin-top: 5px; font-size: 0.9em;">
|
|
{{ $connectionTest['magento1_error'] }}
|
|
</div>
|
|
@endif
|
|
</div>
|
|
<div>
|
|
<strong>Magento 2:</strong>
|
|
<span class="status-badge {{ $connectionTest['magento2'] ? 'success' : 'error' }}">
|
|
{{ $connectionTest['magento2'] ? '✓ Connected' : '✗ Failed' }}
|
|
</span>
|
|
@if(!$connectionTest['magento2'] && isset($connectionTest['magento2_error']))
|
|
<div style="color: #721c24; margin-top: 5px; font-size: 0.9em;">
|
|
{{ $connectionTest['magento2_error'] }}
|
|
</div>
|
|
@endif
|
|
</div>
|
|
</div>
|
|
<button class="btn btn-secondary" onclick="testConnections()">Test Connections</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Migration Tab -->
|
|
<div id="tab-migration" class="tab-content">
|
|
<!-- Statistics -->
|
|
<div class="section">
|
|
<h2>📊 Statistics</h2>
|
|
<div class="stats">
|
|
<div class="stat-card">
|
|
<div class="number">{{ $m1Stores->count() }}</div>
|
|
<div class="label">Magento 1 Stores</div>
|
|
</div>
|
|
<div class="stat-card">
|
|
<div class="number">{{ $m2Stores->count() }}</div>
|
|
<div class="label">Magento 2 Stores</div>
|
|
</div>
|
|
<div class="stat-card">
|
|
<div class="number">{{ $m1CategoriesCount }}</div>
|
|
<div class="label">Magento 1 Categories</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Store Mapping -->
|
|
<div class="section">
|
|
<h2>🔄 Store Mapping</h2>
|
|
<p>Map each Magento 1 store to its corresponding Magento 2 store:</p>
|
|
|
|
<div id="store-mappings">
|
|
@foreach($m1Stores as $m1Store)
|
|
<div class="store-mapping" style="margin-top: 15px;">
|
|
<div>
|
|
<strong>M1 Store:</strong> {{ $m1Store->name }} ({{ $m1Store->code }})
|
|
</div>
|
|
<div class="arrow">→</div>
|
|
<div>
|
|
<select class="store-select" name="store_mapping[{{ $m1Store->store_id }}]" id="store_{{ $m1Store->store_id }}">
|
|
<option value="">Select Magento 2 Store</option>
|
|
@foreach($m2Stores as $m2Store)
|
|
<option value="{{ $m2Store->store_id }}">{{ $m2Store->name }} ({{ $m2Store->code }})</option>
|
|
@endforeach
|
|
</select>
|
|
</div>
|
|
</div>
|
|
@endforeach
|
|
</div>
|
|
|
|
@if($m1Stores->isEmpty())
|
|
<div class="info-box">
|
|
<p>No Magento 1 stores found. Please check your database connection.</p>
|
|
</div>
|
|
@endif
|
|
</div>
|
|
|
|
<!-- Actions -->
|
|
<div class="section">
|
|
<h2>⚡ Actions</h2>
|
|
|
|
<div class="info-box" style="margin-bottom: 20px;">
|
|
<h3 style="margin-bottom: 10px; color: #1976D2; font-size: 1.1em;">What happens when you click "Start Migration"?</h3>
|
|
<p style="margin: 5px 0; color: #1976D2;">The migration process will:</p>
|
|
<ul style="margin: 10px 0 0 20px; color: #1976D2; line-height: 1.8;">
|
|
<li><strong>Migrate category structure:</strong> Create categories in Magento 2 based on the hierarchy from Magento 1, preserving parent-child relationships and positions</li>
|
|
<li><strong>Migrate category attributes:</strong> For each mapped store, migrate category names, URL keys, and active status from Magento 1 to Magento 2</li>
|
|
<li><strong>Preserve hierarchy:</strong> Maintain the exact category tree structure with proper levels and paths</li>
|
|
<li><strong>Handle existing categories:</strong> If a category with the same name and parent already exists in Magento 2, it will be reused instead of creating a duplicate</li>
|
|
<li><strong>Generate logs:</strong> Provide detailed migration logs showing which categories were added, updated, or encountered errors</li>
|
|
</ul>
|
|
<p style="margin: 10px 0 0 0; color: #d32f2f; font-weight: 600;">⚠️ <strong>Warning:</strong> This will modify your Magento 2 database. Make sure you have a backup before proceeding.</p>
|
|
</div>
|
|
|
|
<div class="actions">
|
|
<button class="btn btn-primary" onclick="startMigration()" id="migrateBtn" {{ !$connectionTest['magento1'] || !$connectionTest['magento2'] ? 'disabled' : '' }}>
|
|
Start Migration
|
|
</button>
|
|
<button class="btn btn-secondary" onclick="previewCategories()">
|
|
Preview Categories
|
|
</button>
|
|
</div>
|
|
|
|
<div class="loading" id="loading">
|
|
<div class="spinner"></div>
|
|
<p style="margin-top: 15px;">Migration in progress...</p>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Migration Logs Section -->
|
|
<div class="section">
|
|
<h2>📋 Migration Logs</h2>
|
|
<p style="margin-bottom: 15px; color: #666;">Detailed logs showing which categories were added, updated, or encountered errors during migration:</p>
|
|
|
|
<div class="log-container" id="migrationLogContainer" style="display: block;">
|
|
<div id="migrationLogContent">
|
|
<div class="log-entry" style="color: #999; font-style: italic;">
|
|
No migration logs yet. Click "Start Migration" to begin.
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Category Trees Tab -->
|
|
<div id="tab-categories" class="tab-content">
|
|
<!-- Statistics -->
|
|
<div class="section">
|
|
<h2>📊 Category Statistics</h2>
|
|
<div class="stats">
|
|
<div class="stat-card">
|
|
<div class="number">{{ $m1CategoriesCount }}</div>
|
|
<div class="label">Magento 1 Categories</div>
|
|
</div>
|
|
<div class="stat-card">
|
|
<div class="number">{{ $m2CategoriesCount }}</div>
|
|
<div class="label">Magento 2 Categories</div>
|
|
</div>
|
|
<div class="stat-card">
|
|
<div class="number">{{ $m1CategoriesCount - $m2CategoriesCount }}</div>
|
|
<div class="label">Difference</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Missing Categories Section -->
|
|
<div class="section">
|
|
<h2>⚠️ Magento 2 Categories Not Found in Magento 1</h2>
|
|
<p>These categories exist in Magento 2 but do not have a matching name in Magento 1:</p>
|
|
|
|
@if($m2CategoriesNotInM1->count() > 0)
|
|
<div style="margin-top: 15px; max-height: 400px; overflow-y: auto;">
|
|
<table style="width: 100%; border-collapse: collapse; background: white; border-radius: 6px;">
|
|
<thead>
|
|
<tr style="background: #f8f9fa; border-bottom: 2px solid #dee2e6;">
|
|
<th style="padding: 12px; text-align: left; font-weight: 600; color: #333;">ID</th>
|
|
<th style="padding: 12px; text-align: left; font-weight: 600; color: #333;">Category Name</th>
|
|
<th style="padding: 12px; text-align: left; font-weight: 600; color: #333;">Level</th>
|
|
<th style="padding: 12px; text-align: left; font-weight: 600; color: #333;">Status</th>
|
|
<th style="padding: 12px; text-align: left; font-weight: 600; color: #333;">Root Category</th>
|
|
<th style="padding: 12px; text-align: left; font-weight: 600; color: #333;">Path</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@foreach($m2CategoriesNotInM1 as $category)
|
|
<tr style="border-bottom: 1px solid #dee2e6;">
|
|
<td style="padding: 10px 12px;">{{ $category->entity_id }}</td>
|
|
<td style="padding: 10px 12px; font-weight: 500;">{{ $category->name ?? 'Unnamed Category' }}</td>
|
|
<td style="padding: 10px 12px;">{{ $category->level ?? 'N/A' }}</td>
|
|
<td style="padding: 10px 12px;">
|
|
<span class="tree-badge {{ ($category->is_active ?? 0) ? 'active' : 'inactive' }}">
|
|
{{ ($category->is_active ?? 0) ? 'Active' : 'Inactive' }}
|
|
</span>
|
|
</td>
|
|
<td style="padding: 10px 12px;">
|
|
@if(isset($category->root_category_name) && $category->root_category_name !== 'N/A')
|
|
<span style="font-weight: 500;">{{ $category->root_category_name }}</span>
|
|
@if(isset($category->root_category_id))
|
|
<span style="font-size: 0.85em; color: #666;">(ID: {{ $category->root_category_id }})</span>
|
|
@endif
|
|
@else
|
|
<span style="color: #999;">N/A</span>
|
|
@endif
|
|
</td>
|
|
<td style="padding: 10px 12px; font-size: 0.9em; color: #666;">{{ $category->path ?? 'N/A' }}</td>
|
|
</tr>
|
|
@endforeach
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div style="margin-top: 15px; padding: 12px; background: #fff3cd; border-left: 4px solid #ffc107; border-radius: 4px;">
|
|
<strong>Total:</strong> {{ $m2CategoriesNotInM1->count() }} {{ Str::plural('category', $m2CategoriesNotInM1->count()) }} found in Magento 2 but not in Magento 1.
|
|
</div>
|
|
@else
|
|
<div style="margin-top: 15px; padding: 15px; background: #d4edda; border-left: 4px solid #28a745; border-radius: 4px; color: #155724;">
|
|
✓ All Magento 2 categories have matching names in Magento 1.
|
|
</div>
|
|
@endif
|
|
</div>
|
|
|
|
<div class="section">
|
|
<h2>🌳 Category Trees</h2>
|
|
<p>View category hierarchies from Magento 1 and Magento 2</p>
|
|
|
|
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 20px;">
|
|
<!-- Magento 1 Tree -->
|
|
<div>
|
|
<h3 style="margin-bottom: 15px; color: #667eea;">Magento 1 Categories</h3>
|
|
<div class="tree-container" id="m1-tree-container">
|
|
<div class="tree-loading">Loading categories...</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Magento 2 Tree -->
|
|
<div>
|
|
<h3 style="margin-bottom: 15px; color: #764ba2;">Magento 2 Categories</h3>
|
|
<div class="tree-container" id="m2-tree-container">
|
|
<div class="tree-loading">Loading categories...</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
function testConnections() {
|
|
fetch('{{ route("migration.test-connections") }}')
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
alert('✓ Both database connections are working!');
|
|
location.reload();
|
|
} else {
|
|
alert('✗ Connection test failed. Check the error messages above.');
|
|
}
|
|
})
|
|
.catch(error => {
|
|
alert('Error testing connections: ' + error.message);
|
|
});
|
|
}
|
|
|
|
function previewCategories() {
|
|
// Find the Category Trees tab button and switch to it
|
|
const tabs = document.querySelectorAll('.tab');
|
|
let categoriesTab = null;
|
|
tabs.forEach(tab => {
|
|
if (tab.textContent.trim() === 'Category Trees') {
|
|
categoriesTab = tab;
|
|
}
|
|
});
|
|
|
|
if (categoriesTab) {
|
|
switchTab('categories', categoriesTab);
|
|
}
|
|
}
|
|
|
|
function startMigration() {
|
|
const storeMapping = {};
|
|
const selects = document.querySelectorAll('select[name^="store_mapping"]');
|
|
|
|
let hasMapping = false;
|
|
selects.forEach(select => {
|
|
if (select.value) {
|
|
storeMapping[select.name.match(/\[(\d+)\]/)[1]] = select.value;
|
|
hasMapping = true;
|
|
}
|
|
});
|
|
|
|
if (!hasMapping) {
|
|
alert('Please map at least one store before starting migration.');
|
|
return;
|
|
}
|
|
|
|
if (!confirm('Are you sure you want to start the migration? This will modify your Magento 2 database.')) {
|
|
return;
|
|
}
|
|
|
|
document.getElementById('migrateBtn').disabled = true;
|
|
document.getElementById('loading').classList.add('active');
|
|
|
|
// Clear and initialize migration logs
|
|
const migrationLogContent = document.getElementById('migrationLogContent');
|
|
migrationLogContent.innerHTML = '<div class="log-entry">Starting migration...</div>';
|
|
|
|
// Scroll to logs section
|
|
document.getElementById('migrationLogContainer').scrollIntoView({ behavior: 'smooth', block: 'nearest' });
|
|
|
|
fetch('{{ route("migration.migrate") }}', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
|
},
|
|
body: JSON.stringify({ store_mapping: storeMapping })
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
document.getElementById('loading').classList.remove('active');
|
|
document.getElementById('migrateBtn').disabled = false;
|
|
|
|
if (data.success) {
|
|
addLogEntry(`✓ Migration completed successfully!`, 'success');
|
|
addLogEntry(`Total categories processed: ${data.migrated_count}`, 'success');
|
|
if (data.added_count !== undefined) {
|
|
addLogEntry(` - Added new categories: ${data.added_count}`, 'success');
|
|
}
|
|
if (data.existing_count !== undefined) {
|
|
addLogEntry(` - Found existing categories: ${data.existing_count}`, 'success');
|
|
}
|
|
|
|
if (data.log && data.log.length > 0) {
|
|
data.log.forEach(log => {
|
|
const type = log.includes('ERROR') ? 'error' : 'success';
|
|
addLogEntry(log, type);
|
|
});
|
|
}
|
|
} else {
|
|
addLogEntry(`✗ Migration failed: ${data.message}`, 'error');
|
|
if (data.log && data.log.length > 0) {
|
|
data.log.forEach(log => {
|
|
addLogEntry(log, log.includes('ERROR') ? 'error' : 'success');
|
|
});
|
|
}
|
|
}
|
|
})
|
|
.catch(error => {
|
|
document.getElementById('loading').classList.remove('active');
|
|
document.getElementById('migrateBtn').disabled = false;
|
|
addLogEntry(`✗ Error: ${error.message}`, 'error');
|
|
});
|
|
}
|
|
|
|
function addLogEntry(message, type = '') {
|
|
// Add to migration logs section (primary)
|
|
const migrationLogContent = document.getElementById('migrationLogContent');
|
|
const entry = document.createElement('div');
|
|
entry.className = `log-entry ${type}`;
|
|
entry.textContent = message;
|
|
migrationLogContent.appendChild(entry);
|
|
|
|
// Auto-scroll to bottom
|
|
const migrationLogContainer = document.getElementById('migrationLogContainer');
|
|
migrationLogContainer.scrollTop = migrationLogContainer.scrollHeight;
|
|
|
|
// Also add to old log container if it exists (for backward compatibility)
|
|
const oldLogContent = document.getElementById('logContent');
|
|
if (oldLogContent) {
|
|
const oldEntry = document.createElement('div');
|
|
oldEntry.className = `log-entry ${type}`;
|
|
oldEntry.textContent = message;
|
|
oldLogContent.appendChild(oldEntry);
|
|
}
|
|
}
|
|
|
|
// Tab switching
|
|
function switchTab(tabName, tabElement) {
|
|
// Hide all tabs
|
|
document.querySelectorAll('.tab-content').forEach(content => {
|
|
content.classList.remove('active');
|
|
});
|
|
document.querySelectorAll('.tab').forEach(tab => {
|
|
tab.classList.remove('active');
|
|
});
|
|
|
|
// Show selected tab
|
|
document.getElementById('tab-' + tabName).classList.add('active');
|
|
tabElement.classList.add('active');
|
|
|
|
// Load category trees if switching to categories tab
|
|
if (tabName === 'categories') {
|
|
loadCategoryTrees();
|
|
}
|
|
}
|
|
|
|
// Load category trees
|
|
function loadCategoryTrees() {
|
|
loadM1Tree();
|
|
loadM2Tree();
|
|
}
|
|
|
|
// Load Magento 1 tree
|
|
function loadM1Tree() {
|
|
const container = document.getElementById('m1-tree-container');
|
|
container.innerHTML = '<div class="tree-loading">Loading categories...</div>';
|
|
|
|
fetch('{{ route("migration.magento1-category-tree") }}')
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
container.innerHTML = '';
|
|
if (data.tree && data.tree.length > 0) {
|
|
renderTree(container, data.tree, 'm1');
|
|
} else {
|
|
container.innerHTML = '<div class="tree-loading">No categories found</div>';
|
|
}
|
|
} else {
|
|
container.innerHTML = `<div class="tree-error">Error: ${data.message || 'Failed to load categories'}</div>`;
|
|
}
|
|
})
|
|
.catch(error => {
|
|
container.innerHTML = `<div class="tree-error">Error: ${error.message}</div>`;
|
|
});
|
|
}
|
|
|
|
// Load Magento 2 tree
|
|
function loadM2Tree() {
|
|
const container = document.getElementById('m2-tree-container');
|
|
container.innerHTML = '<div class="tree-loading">Loading categories...</div>';
|
|
|
|
fetch('{{ route("migration.magento2-category-tree") }}')
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
container.innerHTML = '';
|
|
if (data.tree && data.tree.length > 0) {
|
|
renderTree(container, data.tree, 'm2');
|
|
} else {
|
|
container.innerHTML = '<div class="tree-loading">No categories found</div>';
|
|
}
|
|
} else {
|
|
container.innerHTML = `<div class="tree-error">Error: ${data.message || 'Failed to load categories'}</div>`;
|
|
}
|
|
})
|
|
.catch(error => {
|
|
container.innerHTML = `<div class="tree-error">Error: ${error.message}</div>`;
|
|
});
|
|
}
|
|
|
|
// Delete category
|
|
function deleteCategory(categoryId, categoryName, source) {
|
|
const container = source === 'm1' ? document.getElementById('m1-tree-container') : document.getElementById('m2-tree-container');
|
|
const originalContent = container.innerHTML;
|
|
container.innerHTML = '<div class="tree-loading">Deleting category...</div>';
|
|
|
|
const url = `{{ route("migration.delete-category", ["categoryId" => ":id"]) }}`.replace(':id', categoryId);
|
|
|
|
fetch(url, {
|
|
method: 'DELETE',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
|
},
|
|
body: JSON.stringify({ source: source })
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
// Reload the tree
|
|
if (source === 'm1') {
|
|
loadM1Tree();
|
|
} else {
|
|
loadM2Tree();
|
|
}
|
|
alert('Category deleted successfully!');
|
|
} else {
|
|
container.innerHTML = originalContent;
|
|
alert('Error: ' + (data.message || 'Failed to delete category'));
|
|
}
|
|
})
|
|
.catch(error => {
|
|
container.innerHTML = originalContent;
|
|
alert('Error: ' + error.message);
|
|
});
|
|
}
|
|
|
|
// Render tree structure
|
|
function renderTree(container, nodes, source = 'm2') {
|
|
nodes.forEach(node => {
|
|
const nodeElement = createTreeNode(node, source);
|
|
container.appendChild(nodeElement);
|
|
});
|
|
}
|
|
|
|
// Create a tree node element
|
|
function createTreeNode(node, source = 'm2') {
|
|
const nodeDiv = document.createElement('div');
|
|
nodeDiv.className = 'tree-node';
|
|
nodeDiv.setAttribute('data-category-id', node.id);
|
|
|
|
const hasChildren = node.children && node.children.length > 0;
|
|
// Prevent deletion of system root (ID 0 or 1)
|
|
const canDelete = node.id != 0 && node.id != 1;
|
|
|
|
const itemDiv = document.createElement('div');
|
|
itemDiv.className = 'tree-node-item';
|
|
|
|
const toggle = document.createElement('span');
|
|
toggle.className = hasChildren ? 'tree-toggle collapsed' : 'tree-toggle leaf';
|
|
if (hasChildren) {
|
|
toggle.onclick = function(e) {
|
|
e.stopPropagation();
|
|
toggleNode(this);
|
|
};
|
|
}
|
|
|
|
const label = document.createElement('div');
|
|
label.className = 'tree-label';
|
|
|
|
const labelText = document.createElement('span');
|
|
labelText.className = 'tree-label-text';
|
|
const productCount = node.product_count !== undefined ? node.product_count : 0;
|
|
labelText.textContent = `${node.name || 'Unnamed Category'} (${productCount})`;
|
|
|
|
const badge = document.createElement('span');
|
|
badge.className = `tree-badge ${node.is_active ? 'active' : 'inactive'}`;
|
|
badge.textContent = node.is_active ? 'Active' : 'Inactive';
|
|
|
|
label.appendChild(labelText);
|
|
label.appendChild(badge);
|
|
|
|
// Add rename button for Magento 2 categories only (except system root)
|
|
if (canDelete && source === 'm2') {
|
|
const renameBtn = document.createElement('button');
|
|
renameBtn.className = 'tree-rename-btn';
|
|
renameBtn.textContent = 'Rename';
|
|
renameBtn.title = 'Rename this category';
|
|
renameBtn.onclick = function(e) {
|
|
e.stopPropagation();
|
|
startRenameCategory(nodeDiv, node, source);
|
|
};
|
|
label.appendChild(renameBtn);
|
|
}
|
|
|
|
// Add delete button for all categories (except system root)
|
|
if (canDelete) {
|
|
const deleteBtn = document.createElement('button');
|
|
deleteBtn.className = 'tree-delete-btn';
|
|
deleteBtn.textContent = 'Delete';
|
|
const warningText = hasChildren
|
|
? `Delete this category and all ${node.children.length} subcategory(ies)?\n\nThis action cannot be undone.`
|
|
: `Are you sure you want to delete the category "${node.name}"?\n\nThis action cannot be undone.`;
|
|
deleteBtn.title = hasChildren ? 'Delete this category and all subcategories' : 'Delete this category';
|
|
deleteBtn.onclick = function(e) {
|
|
e.stopPropagation();
|
|
if (confirm(warningText)) {
|
|
deleteCategory(node.id, node.name, source);
|
|
}
|
|
};
|
|
label.appendChild(deleteBtn);
|
|
}
|
|
|
|
itemDiv.appendChild(toggle);
|
|
itemDiv.appendChild(label);
|
|
|
|
nodeDiv.appendChild(itemDiv);
|
|
|
|
if (hasChildren) {
|
|
const childrenDiv = document.createElement('div');
|
|
childrenDiv.className = 'tree-children';
|
|
node.children.forEach(child => {
|
|
childrenDiv.appendChild(createTreeNode(child, source));
|
|
});
|
|
nodeDiv.appendChild(childrenDiv);
|
|
}
|
|
|
|
return nodeDiv;
|
|
}
|
|
|
|
// Toggle node expansion
|
|
function toggleNode(toggleElement) {
|
|
const nodeItem = toggleElement.parentElement;
|
|
const nodeDiv = nodeItem.parentElement;
|
|
const childrenDiv = nodeDiv.querySelector('.tree-children');
|
|
|
|
if (childrenDiv) {
|
|
const isExpanded = childrenDiv.classList.contains('expanded');
|
|
if (isExpanded) {
|
|
childrenDiv.classList.remove('expanded');
|
|
toggleElement.classList.remove('expanded');
|
|
toggleElement.classList.add('collapsed');
|
|
} else {
|
|
childrenDiv.classList.add('expanded');
|
|
toggleElement.classList.remove('collapsed');
|
|
toggleElement.classList.add('expanded');
|
|
}
|
|
}
|
|
}
|
|
|
|
// Start renaming a category
|
|
function startRenameCategory(nodeDiv, node, source) {
|
|
const label = nodeDiv.querySelector('.tree-label');
|
|
const labelText = label.querySelector('.tree-label-text');
|
|
const originalName = node.name || 'Unnamed Category';
|
|
|
|
// Hide the label text and badge
|
|
labelText.style.display = 'none';
|
|
const badge = label.querySelector('.tree-badge');
|
|
if (badge) badge.style.display = 'none';
|
|
|
|
// Hide rename and delete buttons
|
|
const renameBtn = label.querySelector('.tree-rename-btn');
|
|
const deleteBtn = label.querySelector('.tree-delete-btn');
|
|
if (renameBtn) renameBtn.style.display = 'none';
|
|
if (deleteBtn) deleteBtn.style.display = 'none';
|
|
|
|
// Create input field
|
|
const input = document.createElement('input');
|
|
input.type = 'text';
|
|
input.className = 'tree-rename-input';
|
|
input.value = originalName;
|
|
input.onclick = function(e) {
|
|
e.stopPropagation();
|
|
};
|
|
|
|
// Create action buttons
|
|
const actionsDiv = document.createElement('div');
|
|
actionsDiv.className = 'tree-rename-actions';
|
|
|
|
const saveBtn = document.createElement('button');
|
|
saveBtn.className = 'tree-rename-save-btn';
|
|
saveBtn.textContent = 'Save';
|
|
saveBtn.onclick = function(e) {
|
|
e.stopPropagation();
|
|
saveRenameCategory(nodeDiv, node, input.value, source);
|
|
};
|
|
|
|
const cancelBtn = document.createElement('button');
|
|
cancelBtn.className = 'tree-rename-cancel-btn';
|
|
cancelBtn.textContent = 'Cancel';
|
|
cancelBtn.onclick = function(e) {
|
|
e.stopPropagation();
|
|
cancelRenameCategory(nodeDiv, labelText, badge, renameBtn, deleteBtn);
|
|
};
|
|
|
|
actionsDiv.appendChild(saveBtn);
|
|
actionsDiv.appendChild(cancelBtn);
|
|
|
|
label.appendChild(input);
|
|
label.appendChild(actionsDiv);
|
|
|
|
// Focus and select input
|
|
input.focus();
|
|
input.select();
|
|
|
|
// Handle Enter and Escape keys
|
|
input.onkeydown = function(e) {
|
|
if (e.key === 'Enter') {
|
|
e.preventDefault();
|
|
saveRenameCategory(nodeDiv, node, input.value, source);
|
|
} else if (e.key === 'Escape') {
|
|
e.preventDefault();
|
|
cancelRenameCategory(nodeDiv, labelText, badge, renameBtn, deleteBtn);
|
|
}
|
|
};
|
|
}
|
|
|
|
// Save category rename
|
|
function saveRenameCategory(nodeDiv, node, newName, source) {
|
|
const categoryId = node.id;
|
|
const label = nodeDiv.querySelector('.tree-label');
|
|
const input = label.querySelector('.tree-rename-input');
|
|
const actionsDiv = label.querySelector('.tree-rename-actions');
|
|
|
|
if (!newName || newName.trim() === '') {
|
|
alert('Category name cannot be empty');
|
|
return;
|
|
}
|
|
|
|
// Disable input and buttons
|
|
input.disabled = true;
|
|
const saveBtn = actionsDiv.querySelector('.tree-rename-save-btn');
|
|
const cancelBtn = actionsDiv.querySelector('.tree-rename-cancel-btn');
|
|
if (saveBtn) saveBtn.disabled = true;
|
|
if (cancelBtn) cancelBtn.disabled = true;
|
|
|
|
const url = `{{ route("migration.rename-category", ["categoryId" => ":id"]) }}`.replace(':id', categoryId);
|
|
|
|
fetch(url, {
|
|
method: 'PUT',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
|
},
|
|
body: JSON.stringify({ name: newName.trim() })
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
// Update the node name
|
|
node.name = data.new_name;
|
|
|
|
// Update the label text
|
|
const labelText = label.querySelector('.tree-label-text');
|
|
const productCount = node.product_count !== undefined ? node.product_count : 0;
|
|
labelText.textContent = `${data.new_name} (${productCount})`;
|
|
|
|
// Restore display
|
|
labelText.style.display = '';
|
|
const badge = label.querySelector('.tree-badge');
|
|
if (badge) badge.style.display = '';
|
|
const renameBtn = label.querySelector('.tree-rename-btn');
|
|
const deleteBtn = label.querySelector('.tree-delete-btn');
|
|
if (renameBtn) renameBtn.style.display = '';
|
|
if (deleteBtn) deleteBtn.style.display = '';
|
|
|
|
// Remove input and actions
|
|
label.removeChild(input);
|
|
label.removeChild(actionsDiv);
|
|
} else {
|
|
alert('Error: ' + (data.message || 'Failed to rename category'));
|
|
// Re-enable input and buttons
|
|
input.disabled = false;
|
|
if (saveBtn) saveBtn.disabled = false;
|
|
if (cancelBtn) cancelBtn.disabled = false;
|
|
}
|
|
})
|
|
.catch(error => {
|
|
alert('Error: ' + error.message);
|
|
// Re-enable input and buttons
|
|
input.disabled = false;
|
|
if (saveBtn) saveBtn.disabled = false;
|
|
if (cancelBtn) cancelBtn.disabled = false;
|
|
});
|
|
}
|
|
|
|
// Cancel category rename
|
|
function cancelRenameCategory(nodeDiv, labelText, badge, renameBtn, deleteBtn) {
|
|
const label = nodeDiv.querySelector('.tree-label');
|
|
const input = label.querySelector('.tree-rename-input');
|
|
const actionsDiv = label.querySelector('.tree-rename-actions');
|
|
|
|
// Restore display
|
|
labelText.style.display = '';
|
|
if (badge) badge.style.display = '';
|
|
if (renameBtn) renameBtn.style.display = '';
|
|
if (deleteBtn) deleteBtn.style.display = '';
|
|
|
|
// Remove input and actions
|
|
if (input) label.removeChild(input);
|
|
if (actionsDiv) label.removeChild(actionsDiv);
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|
|
|