2765 lines
139 KiB
PHP
2765 lines
139 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 {
|
|
width: 90%;
|
|
max-width: 90%;
|
|
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;
|
|
}
|
|
|
|
/* Delete Confirmation Popup */
|
|
.delete-confirm-popup {
|
|
position: fixed;
|
|
background: white;
|
|
border-radius: 8px;
|
|
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
|
|
padding: 20px;
|
|
min-width: 320px;
|
|
max-width: 400px;
|
|
max-height: calc(100vh - 40px);
|
|
overflow-y: auto;
|
|
z-index: 10000;
|
|
border: 1px solid #e0e0e0;
|
|
animation: popupFadeIn 0.2s ease-out;
|
|
}
|
|
|
|
.delete-confirm-popup.no-arrow::before,
|
|
.delete-confirm-popup.no-arrow::after {
|
|
display: none;
|
|
}
|
|
|
|
@keyframes popupFadeIn {
|
|
from {
|
|
opacity: 0;
|
|
transform: translate(-50%, -50%) scale(0.95);
|
|
}
|
|
to {
|
|
opacity: 1;
|
|
transform: translate(-50%, -50%) scale(1);
|
|
}
|
|
}
|
|
|
|
.delete-confirm-popup::before {
|
|
content: '';
|
|
position: absolute;
|
|
bottom: -8px;
|
|
left: 20px;
|
|
width: 0;
|
|
height: 0;
|
|
border-left: 8px solid transparent;
|
|
border-right: 8px solid transparent;
|
|
border-top: 8px solid white;
|
|
}
|
|
|
|
.delete-confirm-popup::after {
|
|
content: '';
|
|
position: absolute;
|
|
bottom: -9px;
|
|
left: 20px;
|
|
width: 0;
|
|
height: 0;
|
|
border-left: 8px solid transparent;
|
|
border-right: 8px solid transparent;
|
|
border-top: 8px solid #e0e0e0;
|
|
}
|
|
|
|
.delete-confirm-popup h3 {
|
|
margin: 0 0 12px 0;
|
|
color: #d32f2f;
|
|
font-size: 1.1em;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
}
|
|
|
|
.delete-confirm-popup h3::before {
|
|
content: '⚠️';
|
|
font-size: 1.2em;
|
|
}
|
|
|
|
.delete-confirm-popup p {
|
|
margin: 0 0 16px 0;
|
|
color: #666;
|
|
line-height: 1.5;
|
|
font-size: 0.95em;
|
|
}
|
|
|
|
.delete-confirm-popup .popup-buttons {
|
|
display: flex;
|
|
gap: 10px;
|
|
justify-content: flex-end;
|
|
}
|
|
|
|
.delete-confirm-popup .popup-btn {
|
|
padding: 8px 16px;
|
|
border: none;
|
|
border-radius: 4px;
|
|
font-size: 0.9em;
|
|
cursor: pointer;
|
|
transition: all 0.2s;
|
|
font-weight: 500;
|
|
}
|
|
|
|
.delete-confirm-popup .popup-btn-cancel {
|
|
background: #f5f5f5;
|
|
color: #333;
|
|
}
|
|
|
|
.delete-confirm-popup .popup-btn-cancel:hover {
|
|
background: #e0e0e0;
|
|
}
|
|
|
|
.delete-confirm-popup .popup-btn-delete {
|
|
background: #d32f2f;
|
|
color: white;
|
|
}
|
|
|
|
.delete-confirm-popup .popup-btn-delete:hover {
|
|
background: #b71c1c;
|
|
}
|
|
|
|
.popup-overlay {
|
|
position: fixed;
|
|
top: 0;
|
|
left: 0;
|
|
right: 0;
|
|
bottom: 0;
|
|
background: rgba(0, 0, 0, 0.1);
|
|
z-index: 9999;
|
|
}
|
|
</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>
|
|
<button class="tab" onclick="switchTab('attributes', this)">Attribute List</button>
|
|
<button class="tab" onclick="switchTab('products', this)">Products</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 class="stat-card">
|
|
<div class="number">{{ $m2CategoriesCount }}</div>
|
|
<div class="label">Magento 2 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 id="m2-categories-not-in-m1-table-wrapper" 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>
|
|
<th style="padding: 12px; text-align: left; font-weight: 600; color: #333;">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="m2-categories-not-in-m1-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>
|
|
<td style="padding: 10px 12px;">
|
|
<button
|
|
class="tree-delete-btn"
|
|
onclick="showDeleteConfirmPopup(this, {{ $category->entity_id }}, '{{ addslashes($category->name ?? 'Unnamed Category') }}', 'm2', false, 0)"
|
|
title="Delete this category">
|
|
Delete
|
|
</button>
|
|
</td>
|
|
</tr>
|
|
@endforeach
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div id="m2-categories-not-in-m1-total" 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 id="m2-categories-not-in-m1-empty" 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>
|
|
|
|
<!-- Attribute List Tab -->
|
|
<div id="tab-attributes" class="tab-content">
|
|
<!-- Attribute Groups Section -->
|
|
<div class="section">
|
|
<h2>📦 Attribute Groups</h2>
|
|
<p>View attribute groups that organize attributes within attribute sets:</p>
|
|
|
|
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 20px;">
|
|
<!-- Magento 1 Attribute Groups -->
|
|
<div>
|
|
<h3 style="margin-bottom: 15px; color: #667eea;">Magento 1 Attribute Groups ({{ $m1AttributeGroups->count() }})</h3>
|
|
<div style="background: white; border: 1px solid #ddd; border-radius: 6px; padding: 20px; max-height: 600px; overflow-y: auto;">
|
|
@if($m1AttributeGroups->count() > 0)
|
|
<table style="width: 100%; border-collapse: collapse;">
|
|
<thead>
|
|
<tr style="background: #f8f9fa; border-bottom: 2px solid #dee2e6;">
|
|
<th style="padding: 10px; text-align: left; font-weight: 600; color: #333; font-size: 0.9em;">Group ID</th>
|
|
<th style="padding: 10px; text-align: left; font-weight: 600; color: #333; font-size: 0.9em;">Group Name</th>
|
|
<th style="padding: 10px; text-align: left; font-weight: 600; color: #333; font-size: 0.9em;">Attribute Set</th>
|
|
<th style="padding: 10px; text-align: left; font-weight: 600; color: #333; font-size: 0.9em;">Attributes</th>
|
|
<th style="padding: 10px; text-align: left; font-weight: 600; color: #333; font-size: 0.9em;">Sort Order</th>
|
|
<th style="padding: 10px; text-align: left; font-weight: 600; color: #333; font-size: 0.9em;">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="m1AttributeGroupsTableBody">
|
|
@foreach($m1AttributeGroups as $group)
|
|
@php
|
|
$groupKey = ($group->attribute_set_name ?? 'Default') . '|' . ($group->attribute_group_name ?? '');
|
|
$isMissing = $m1AttributeGroupsMissingInM2->contains(function($missingGroup) use ($groupKey) {
|
|
$missingKey = ($missingGroup->attribute_set_name ?? 'Default') . '|' . ($missingGroup->attribute_group_name ?? '');
|
|
return $missingKey === $groupKey;
|
|
});
|
|
@endphp
|
|
<tr id="group-row-{{ $group->attribute_group_id }}-{{ $group->attribute_set_id }}" style="border-bottom: 1px solid #e0e0e0;">
|
|
<td style="padding: 8px 10px; font-size: 0.85em;">{{ $group->attribute_group_id }}</td>
|
|
<td style="padding: 8px 10px; font-size: 0.85em; font-weight: 500; color: #667eea;">{{ $group->attribute_group_name ?? 'N/A' }}</td>
|
|
<td style="padding: 8px 10px; font-size: 0.85em; color: #666;">{{ $group->attribute_set_name ?? 'N/A' }}</td>
|
|
<td style="padding: 8px 10px; font-size: 0.85em;">
|
|
<span style="font-weight: 600; color: #667eea;">{{ $group->attribute_count ?? 0 }}</span>
|
|
</td>
|
|
<td style="padding: 8px 10px; font-size: 0.85em; color: #666;">{{ $group->sort_order ?? 'N/A' }}</td>
|
|
<td style="padding: 8px 10px; font-size: 0.85em;">
|
|
@if($isMissing)
|
|
<button
|
|
class="btn btn-primary"
|
|
onclick="migrateAttributeGroup({{ $group->attribute_group_id }}, {{ $group->attribute_set_id }}, '{{ $group->attribute_group_name ?? 'N/A' }}')"
|
|
id="migrate-group-btn-{{ $group->attribute_group_id }}-{{ $group->attribute_set_id }}"
|
|
style="padding: 6px 12px; font-size: 0.85em; background: #1976D2; color: white; border: none; border-radius: 4px; cursor: pointer;">
|
|
Migrate
|
|
</button>
|
|
@else
|
|
<span style="color: #28a745; font-size: 0.85em;">✓ Exists</span>
|
|
@endif
|
|
</td>
|
|
</tr>
|
|
@endforeach
|
|
</tbody>
|
|
</table>
|
|
@else
|
|
<div style="text-align: center; padding: 40px; color: #999;">
|
|
No attribute groups found. Please check your database connection.
|
|
</div>
|
|
@endif
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Magento 2 Attribute Groups -->
|
|
<div>
|
|
<h3 style="margin-bottom: 15px; color: #764ba2;">Magento 2 Attribute Groups ({{ $m2AttributeGroups->count() }})</h3>
|
|
<div style="background: white; border: 1px solid #ddd; border-radius: 6px; padding: 20px; max-height: 600px; overflow-y: auto;">
|
|
@if($m2AttributeGroups->count() > 0)
|
|
<table style="width: 100%; border-collapse: collapse;">
|
|
<thead>
|
|
<tr style="background: #f8f9fa; border-bottom: 2px solid #dee2e6;">
|
|
<th style="padding: 10px; text-align: left; font-weight: 600; color: #333; font-size: 0.9em;">Group ID</th>
|
|
<th style="padding: 10px; text-align: left; font-weight: 600; color: #333; font-size: 0.9em;">Group Name</th>
|
|
<th style="padding: 10px; text-align: left; font-weight: 600; color: #333; font-size: 0.9em;">Attribute Set</th>
|
|
<th style="padding: 10px; text-align: left; font-weight: 600; color: #333; font-size: 0.9em;">Attributes</th>
|
|
<th style="padding: 10px; text-align: left; font-weight: 600; color: #333; font-size: 0.9em;">Sort Order</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@foreach($m2AttributeGroups as $group)
|
|
<tr style="border-bottom: 1px solid #e0e0e0;">
|
|
<td style="padding: 8px 10px; font-size: 0.85em;">{{ $group->attribute_group_id }}</td>
|
|
<td style="padding: 8px 10px; font-size: 0.85em; font-weight: 500; color: #764ba2;">{{ $group->attribute_group_name ?? 'N/A' }}</td>
|
|
<td style="padding: 8px 10px; font-size: 0.85em; color: #666;">{{ $group->attribute_set_name ?? 'N/A' }}</td>
|
|
<td style="padding: 8px 10px; font-size: 0.85em;">
|
|
<span style="font-weight: 600; color: #764ba2;">{{ $group->attribute_count ?? 0 }}</span>
|
|
</td>
|
|
<td style="padding: 8px 10px; font-size: 0.85em; color: #666;">{{ $group->sort_order ?? 'N/A' }}</td>
|
|
</tr>
|
|
@endforeach
|
|
</tbody>
|
|
</table>
|
|
@else
|
|
<div style="text-align: center; padding: 40px; color: #999;">
|
|
No attribute groups found. Please check your database connection.
|
|
</div>
|
|
@endif
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Missing Attributes Section -->
|
|
<div class="section" style="margin-top: 30px;">
|
|
<h2>⚠️ Magento 1 Attributes Missing in Magento 2</h2>
|
|
<p>These attributes exist in Magento 1 but do not have a matching attribute code in Magento 2:</p>
|
|
@if($m1AttributesMissingInM2->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;">Attribute Code</th>
|
|
<th style="padding: 12px; text-align: left; font-weight: 600; color: #333;">Label</th>
|
|
<th style="padding: 12px; text-align: left; font-weight: 600; color: #333;">Type</th>
|
|
<th style="padding: 12px; text-align: left; font-weight: 600; color: #333;">Input</th>
|
|
<th style="padding: 12px; text-align: left; font-weight: 600; color: #333;">Required</th>
|
|
<th style="padding: 12px; text-align: left; font-weight: 600; color: #333;">User Defined</th>
|
|
<th style="padding: 12px; text-align: left; font-weight: 600; color: #333;">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="missingAttributesTableBody">
|
|
@foreach($m1AttributesMissingInM2 as $attr)
|
|
<tr id="attr-row-{{ $attr->attribute_id }}" style="border-bottom: 1px solid #dee2e6;">
|
|
<td style="padding: 10px 12px;">{{ $attr->attribute_id }}</td>
|
|
<td style="padding: 10px 12px; font-weight: 500; color: #667eea;">{{ $attr->attribute_code }}</td>
|
|
<td style="padding: 10px 12px;">{{ $attr->frontend_label ?? 'N/A' }}</td>
|
|
<td style="padding: 10px 12px; color: #666;">{{ $attr->backend_type ?? 'N/A' }}</td>
|
|
<td style="padding: 10px 12px; color: #666;">{{ $attr->frontend_input ?? 'N/A' }}</td>
|
|
<td style="padding: 10px 12px;">
|
|
@if($attr->is_required ?? 0)
|
|
<span style="color: #d32f2f; font-weight: 600;">Yes</span>
|
|
@else
|
|
<span style="color: #666;">No</span>
|
|
@endif
|
|
</td>
|
|
<td style="padding: 10px 12px;">
|
|
@if($attr->is_user_defined ?? 0)
|
|
<span style="color: #1976D2; font-weight: 600;">Yes</span>
|
|
@else
|
|
<span style="color: #666;">No</span>
|
|
@endif
|
|
</td>
|
|
<td style="padding: 10px 12px;">
|
|
<button
|
|
class="btn btn-primary"
|
|
onclick="migrateAttribute({{ $attr->attribute_id }}, '{{ $attr->attribute_code }}')"
|
|
id="migrate-btn-{{ $attr->attribute_id }}"
|
|
style="padding: 6px 12px; font-size: 0.85em; background: #1976D2; color: white; border: none; border-radius: 4px; cursor: pointer;">
|
|
Migrate
|
|
</button>
|
|
</td>
|
|
</tr>
|
|
@endforeach
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div id="missingAttributesCount" style="margin-top: 15px; padding: 12px; background: #fff3cd; border-left: 4px solid #ffc107; border-radius: 4px;">
|
|
<strong>Total:</strong> <span id="missingAttributesTotal">{{ $m1AttributesMissingInM2->count() }}</span> {{ Str::plural('attribute', $m1AttributesMissingInM2->count()) }} found in Magento 1 but not in Magento 2.
|
|
</div>
|
|
@else
|
|
<div style="margin-top: 15px; padding: 15px; background: #d4edda; border-left: 4px solid #28a745; border-radius: 4px; color: #155724;">
|
|
✓ All Magento 1 attributes have matching attribute codes in Magento 2.
|
|
</div>
|
|
@endif
|
|
</div>
|
|
|
|
<!-- Category Attributes Section -->
|
|
<div class="section" style="margin-top: 30px;">
|
|
<h2>📋 Category Attributes</h2>
|
|
<p>View all category attributes from Magento 1 and Magento 2</p>
|
|
|
|
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 20px;">
|
|
<!-- Magento 1 Attributes -->
|
|
<div>
|
|
<h3 style="margin-bottom: 15px; color: #667eea;">Magento 1 Attributes ({{ $m1Attributes->count() }})</h3>
|
|
<div style="background: white; border: 1px solid #ddd; border-radius: 6px; padding: 20px; max-height: 600px; overflow-y: auto;">
|
|
@if($m1Attributes->count() > 0)
|
|
<table style="width: 100%; border-collapse: collapse;">
|
|
<thead>
|
|
<tr style="background: #f8f9fa; border-bottom: 2px solid #dee2e6;">
|
|
<th style="padding: 10px; text-align: left; font-weight: 600; color: #333; font-size: 0.9em;">ID</th>
|
|
<th style="padding: 10px; text-align: left; font-weight: 600; color: #333; font-size: 0.9em;">Code</th>
|
|
<th style="padding: 10px; text-align: left; font-weight: 600; color: #333; font-size: 0.9em;">Label</th>
|
|
<th style="padding: 10px; text-align: left; font-weight: 600; color: #333; font-size: 0.9em;">Type</th>
|
|
<th style="padding: 10px; text-align: left; font-weight: 600; color: #333; font-size: 0.9em;">Input</th>
|
|
<th style="padding: 10px; text-align: left; font-weight: 600; color: #333; font-size: 0.9em;">Required</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@foreach($m1Attributes as $attr)
|
|
<tr style="border-bottom: 1px solid #e0e0e0;">
|
|
<td style="padding: 8px 10px; font-size: 0.85em;">{{ $attr->attribute_id }}</td>
|
|
<td style="padding: 8px 10px; font-size: 0.85em; font-weight: 500; color: #667eea;">{{ $attr->attribute_code }}</td>
|
|
<td style="padding: 8px 10px; font-size: 0.85em;">{{ $attr->frontend_label ?? 'N/A' }}</td>
|
|
<td style="padding: 8px 10px; font-size: 0.85em; color: #666;">{{ $attr->backend_type ?? 'N/A' }}</td>
|
|
<td style="padding: 8px 10px; font-size: 0.85em; color: #666;">{{ $attr->frontend_input ?? 'N/A' }}</td>
|
|
<td style="padding: 8px 10px; font-size: 0.85em;">
|
|
@if($attr->is_required ?? 0)
|
|
<span style="color: #d32f2f; font-weight: 600;">Yes</span>
|
|
@else
|
|
<span style="color: #666;">No</span>
|
|
@endif
|
|
</td>
|
|
</tr>
|
|
@endforeach
|
|
</tbody>
|
|
</table>
|
|
@else
|
|
<div style="text-align: center; padding: 40px; color: #999;">
|
|
No attributes found. Please check your database connection.
|
|
</div>
|
|
@endif
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Magento 2 Attributes -->
|
|
<div>
|
|
<h3 style="margin-bottom: 15px; color: #764ba2;">Magento 2 Attributes ({{ $m2Attributes->count() }})</h3>
|
|
<div style="background: white; border: 1px solid #ddd; border-radius: 6px; padding: 20px; max-height: 600px; overflow-y: auto;">
|
|
@if($m2Attributes->count() > 0)
|
|
<table style="width: 100%; border-collapse: collapse;">
|
|
<thead>
|
|
<tr style="background: #f8f9fa; border-bottom: 2px solid #dee2e6;">
|
|
<th style="padding: 10px; text-align: left; font-weight: 600; color: #333; font-size: 0.9em;">ID</th>
|
|
<th style="padding: 10px; text-align: left; font-weight: 600; color: #333; font-size: 0.9em;">Code</th>
|
|
<th style="padding: 10px; text-align: left; font-weight: 600; color: #333; font-size: 0.9em;">Label</th>
|
|
<th style="padding: 10px; text-align: left; font-weight: 600; color: #333; font-size: 0.9em;">Type</th>
|
|
<th style="padding: 10px; text-align: left; font-weight: 600; color: #333; font-size: 0.9em;">Input</th>
|
|
<th style="padding: 10px; text-align: left; font-weight: 600; color: #333; font-size: 0.9em;">Required</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@foreach($m2Attributes as $attr)
|
|
<tr style="border-bottom: 1px solid #e0e0e0;">
|
|
<td style="padding: 8px 10px; font-size: 0.85em;">{{ $attr->attribute_id }}</td>
|
|
<td style="padding: 8px 10px; font-size: 0.85em; font-weight: 500; color: #764ba2;">{{ $attr->attribute_code }}</td>
|
|
<td style="padding: 8px 10px; font-size: 0.85em;">{{ $attr->frontend_label ?? 'N/A' }}</td>
|
|
<td style="padding: 8px 10px; font-size: 0.85em; color: #666;">{{ $attr->backend_type ?? 'N/A' }}</td>
|
|
<td style="padding: 8px 10px; font-size: 0.85em; color: #666;">{{ $attr->frontend_input ?? 'N/A' }}</td>
|
|
<td style="padding: 8px 10px; font-size: 0.85em;">
|
|
@if($attr->is_required ?? 0)
|
|
<span style="color: #d32f2f; font-weight: 600;">Yes</span>
|
|
@else
|
|
<span style="color: #666;">No</span>
|
|
@endif
|
|
</td>
|
|
</tr>
|
|
@endforeach
|
|
</tbody>
|
|
</table>
|
|
@else
|
|
<div style="text-align: center; padding: 40px; color: #999;">
|
|
No attributes found. Please check your database connection.
|
|
</div>
|
|
@endif
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Products Tab -->
|
|
<div id="tab-products" class="tab-content">
|
|
<!-- Product Migration Section -->
|
|
<div class="section">
|
|
<h2>🚀 Product Migration</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 Product Migration"?</h3>
|
|
<p style="margin: 5px 0; color: #1976D2;">The product migration process will:</p>
|
|
<ul style="margin: 10px 0 0 20px; color: #1976D2; line-height: 1.8;">
|
|
<li><strong>Create new products:</strong> If a product with the same SKU doesn't exist in Magento 2, it will be created with all its attributes (name, description, price, weight, status, etc.)</li>
|
|
<li><strong>Update existing products:</strong> If a product with the same SKU already exists in Magento 2, it will be updated with the latest data from Magento 1</li>
|
|
<li><strong>Migrate product attributes:</strong> All product attributes including SKU, name, description, price, weight, status, visibility, and tax class will be migrated</li>
|
|
<li><strong>Assign to categories:</strong> Products will be assigned to the corresponding categories in Magento 2 based on the category mapping from previous migrations</li>
|
|
<li><strong>Preserve product types:</strong> Product types (simple, configurable, etc.) will be maintained</li>
|
|
<li><strong>Generate logs:</strong> Detailed migration logs showing which products 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 style="margin-top: 20px; display: flex; gap: 15px; flex-wrap: wrap;">
|
|
<button id="dryRunProductMigrationBtn" class="btn btn-secondary" onclick="startProductMigration(true)" style="padding: 12px 24px; font-size: 1em; background: #6c757d; color: white; border: none; border-radius: 4px; cursor: pointer; font-weight: 600;">
|
|
Run Dry Run (Check for Errors)
|
|
</button>
|
|
<button id="startProductMigrationBtn" class="btn btn-primary" onclick="startProductMigration(false)" style="padding: 12px 24px; font-size: 1em; background: #1976D2; color: white; border: none; border-radius: 4px; cursor: pointer; font-weight: 600;">
|
|
Start Product Migration
|
|
</button>
|
|
<button id="deleteProductsAboveM1MaxBtn" class="btn btn-danger" onclick="deleteProductsAboveM1Max()" style="padding: 12px 24px; font-size: 1em; background: #d32f2f; color: white; border: none; border-radius: 4px; cursor: pointer; font-weight: 600;">
|
|
Delete M2 Products Above M1 Max ID
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Missing Attributes Section -->
|
|
<div class="section" id="missingAttributesSection" style="margin-top: 30px; display: none;">
|
|
<h2>⚠️ Missing Attributes</h2>
|
|
<p style="margin-bottom: 15px; color: #666;">The following attributes exist in Magento 1 but are missing in Magento 2. These need to be created before migration:</p>
|
|
<div style="background: white; border: 1px solid #ddd; border-radius: 6px; padding: 20px; max-height: 400px; overflow-y: auto;">
|
|
<table style="width: 100%; border-collapse: collapse;" id="missingAttributesTable">
|
|
<thead>
|
|
<tr style="background: #f8f9fa; border-bottom: 2px solid #dee2e6;">
|
|
<th style="padding: 10px; text-align: left; font-weight: 600; color: #333; font-size: 0.9em;">Attribute Code</th>
|
|
<th style="padding: 10px; text-align: left; font-weight: 600; color: #333; font-size: 0.9em;">Label</th>
|
|
<th style="padding: 10px; text-align: left; font-weight: 600; color: #333; font-size: 0.9em;">Backend Type</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="missingAttributesTableBody">
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Migration Logs Section -->
|
|
<div class="section" style="margin-top: 30px;">
|
|
<h2>📋 Product Migration Logs</h2>
|
|
<p style="margin-bottom: 15px; color: #666;">Detailed logs showing which products were added, updated, or encountered errors during migration:</p>
|
|
<div class="log-container" id="productMigrationLogContainer" style="display: block;">
|
|
<div id="productMigrationLogContent">
|
|
<div class="log-entry" style="color: #999; font-style: italic;">
|
|
No product migration logs yet. Click "Run Dry Run" or "Start Product Migration" to begin.
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Category Tree with Products Section -->
|
|
<div class="section" style="margin-top: 30px;">
|
|
<h2>🌳 Category Tree with Products</h2>
|
|
<p>View all categories with their associated products in a tree structure.</p>
|
|
|
|
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 20px;">
|
|
<!-- Magento 1 Category Tree with Products -->
|
|
<div>
|
|
<h3 style="margin-bottom: 15px; color: #667eea;">Magento 1 Categories</h3>
|
|
<div id="m1-category-products-tree-container" style="background: white; border: 1px solid #ddd; border-radius: 6px; padding: 20px; max-height: 600px; overflow-y: auto; margin-top: 15px;">
|
|
<div class="tree-loading">Click "Load M1 Category Tree" to view categories and their products.</div>
|
|
</div>
|
|
<div style="margin-top: 15px;">
|
|
<button onclick="loadM1CategoryTreeWithProducts()" style="padding: 10px 20px; font-size: 1em; background: #667eea; color: white; border: none; border-radius: 4px; cursor: pointer; font-weight: 600;">
|
|
Load M1 Category Tree with Products
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Magento 2 Category Tree with Products -->
|
|
<div>
|
|
<h3 style="margin-bottom: 15px; color: #1976D2;">Magento 2 Categories</h3>
|
|
<div id="m2-category-products-tree-container" style="background: white; border: 1px solid #ddd; border-radius: 6px; padding: 20px; max-height: 600px; overflow-y: auto; margin-top: 15px;">
|
|
<div class="tree-loading">Click "Load M2 Category Tree" to view categories and their products.</div>
|
|
</div>
|
|
<div style="margin-top: 15px;">
|
|
<button onclick="loadM2CategoryTreeWithProducts()" style="padding: 10px 20px; font-size: 1em; background: #1976D2; color: white; border: none; border-radius: 4px; cursor: pointer; font-weight: 600;">
|
|
Load M2 Category Tree with Products
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Sync Product Categories Section -->
|
|
<div class="section" style="margin-top: 30px;">
|
|
<h2>🔄 Sync Product Categories</h2>
|
|
<div style="background: #f8f9fa; border-left: 4px solid #1976D2; padding: 15px; border-radius: 4px; margin-bottom: 15px;">
|
|
<p style="margin: 0 0 10px 0; color: #333; font-weight: 500;">This tool will update Magento 2 products to be in the same categories as their Magento 1 counterparts.</p>
|
|
<ul style="margin: 10px 0 0 0; padding-left: 20px; color: #666;">
|
|
<li>Matches products between M1 and M2 by SKU or Product ID</li>
|
|
<li>Uses the category mapping from previous migrations</li>
|
|
<li>Adds missing category associations</li>
|
|
<li>Removes category associations that don't exist in M1</li>
|
|
<li>Preserves product positions in categories</li>
|
|
</ul>
|
|
<p style="margin: 10px 0 0 0; color: #d32f2f; font-weight: 600;">⚠️ <strong>Warning:</strong> This will modify product-category associations in your Magento 2 database. Make sure you have a backup before proceeding.</p>
|
|
</div>
|
|
|
|
<div style="margin-top: 20px;">
|
|
<button id="syncProductCategoriesBtn" class="btn btn-primary" onclick="syncProductCategories()" style="padding: 12px 24px; font-size: 1em; background: #1976D2; color: white; border: none; border-radius: 4px; cursor: pointer; font-weight: 600;">
|
|
Sync Product Categories
|
|
</button>
|
|
</div>
|
|
|
|
<!-- Sync Logs Section -->
|
|
<div class="section" style="margin-top: 30px;">
|
|
<h3>Sync Logs</h3>
|
|
<div id="syncProductCategoriesLogs" style="background: #f5f5f5; border: 1px solid #ddd; border-radius: 6px; padding: 15px; max-height: 400px; overflow-y: auto; font-family: 'Courier New', monospace; font-size: 0.85em; display: none;">
|
|
<div style="color: #666; font-style: italic;">No sync operations performed yet...</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Missing Products Section -->
|
|
<div class="section" style="margin-top: 30px;">
|
|
<h2>⚠️ Magento 1 Products Not Found in Magento 2</h2>
|
|
<p>These products exist in Magento 1 but do not have a matching SKU or ID in Magento 2:</p>
|
|
@if($m1ProductsNotInM2->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;">SKU</th>
|
|
<th style="padding: 12px; text-align: left; font-weight: 600; color: #333;">Name</th>
|
|
<th style="padding: 12px; text-align: left; font-weight: 600; color: #333;">Type</th>
|
|
<th style="padding: 12px; text-align: left; font-weight: 600; color: #333;">Created</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@foreach($m1ProductsNotInM2 as $product)
|
|
<tr style="border-bottom: 1px solid #dee2e6;">
|
|
<td style="padding: 10px 12px;">{{ $product->entity_id }}</td>
|
|
<td style="padding: 10px 12px; font-weight: 500; color: #667eea;">{{ $product->sku ?? 'N/A' }}</td>
|
|
<td style="padding: 10px 12px; font-weight: 500;">{{ $product->name ?? 'Unnamed Product' }}</td>
|
|
<td style="padding: 10px 12px; color: #666;">{{ $product->type_id ?? 'N/A' }}</td>
|
|
<td style="padding: 10px 12px; font-size: 0.9em; color: #666;">
|
|
@if($product->created_at)
|
|
{{ \Carbon\Carbon::parse($product->created_at)->format('Y-m-d') }}
|
|
@else
|
|
N/A
|
|
@endif
|
|
</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> {{ $m1ProductsNotInM2->count() }} {{ Str::plural('product', $m1ProductsNotInM2->count()) }} found in Magento 1 but not in Magento 2.
|
|
</div>
|
|
@else
|
|
<div style="margin-top: 15px; padding: 15px; background: #d4edda; border-left: 4px solid #28a745; border-radius: 4px; color: #155724;">
|
|
✓ All Magento 1 products have matching SKUs or IDs in Magento 2.
|
|
</div>
|
|
@endif
|
|
</div>
|
|
|
|
<!-- Magento 2 Products Not in Magento 1 Section -->
|
|
<div class="section" style="margin-top: 30px;">
|
|
<h2>⚠️ Magento 2 Products Not Found in Magento 1</h2>
|
|
<p>These products exist in Magento 2 but do not have a matching SKU or ID in Magento 1:</p>
|
|
@if($m2ProductsNotInM1->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;">SKU</th>
|
|
<th style="padding: 12px; text-align: left; font-weight: 600; color: #333;">Name</th>
|
|
<th style="padding: 12px; text-align: left; font-weight: 600; color: #333;">Type</th>
|
|
<th style="padding: 12px; text-align: left; font-weight: 600; color: #333;">Created</th>
|
|
<th style="padding: 12px; text-align: left; font-weight: 600; color: #333;">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@foreach($m2ProductsNotInM1 as $product)
|
|
<tr style="border-bottom: 1px solid #dee2e6;" id="product-row-{{ $product->entity_id }}">
|
|
<td style="padding: 10px 12px;">{{ $product->entity_id }}</td>
|
|
<td style="padding: 10px 12px; font-weight: 500; color: #667eea;">{{ $product->sku ?? 'N/A' }}</td>
|
|
<td style="padding: 10px 12px; font-weight: 500;">{{ $product->name ?? 'Unnamed Product' }}</td>
|
|
<td style="padding: 10px 12px; color: #666;">{{ $product->type_id ?? 'N/A' }}</td>
|
|
<td style="padding: 10px 12px; font-size: 0.9em; color: #666;">
|
|
@if($product->created_at)
|
|
{{ \Carbon\Carbon::parse($product->created_at)->format('Y-m-d') }}
|
|
@else
|
|
N/A
|
|
@endif
|
|
</td>
|
|
<td style="padding: 10px 12px;">
|
|
<button onclick="deleteM2Product({{ $product->entity_id }}, '{{ addslashes($product->name ?? 'Unnamed Product') }}', '{{ addslashes($product->sku ?? 'N/A') }}')"
|
|
style="padding: 6px 12px; background: #d32f2f; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 0.85em; font-weight: 500;">
|
|
Delete
|
|
</button>
|
|
</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> {{ $m2ProductsNotInM1->count() }} {{ Str::plural('product', $m2ProductsNotInM1->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 products have matching SKUs or IDs in Magento 1.
|
|
</div>
|
|
@endif
|
|
</div>
|
|
|
|
<!-- Products List Section -->
|
|
<div class="section" style="margin-top: 30px;">
|
|
<h2>📦 Products</h2>
|
|
<p>View all products from Magento 1 and Magento 2</p>
|
|
|
|
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 20px;">
|
|
<!-- Magento 1 Products -->
|
|
<div>
|
|
<h3 style="margin-bottom: 15px; color: #667eea;">Magento 1 Products ({{ $m1Products->count() }})</h3>
|
|
<div style="background: white; border: 1px solid #ddd; border-radius: 6px; padding: 20px; max-height: 600px; overflow-y: auto;">
|
|
@if($m1Products->count() > 0)
|
|
<table style="width: 100%; border-collapse: collapse;">
|
|
<thead>
|
|
<tr style="background: #f8f9fa; border-bottom: 2px solid #dee2e6;">
|
|
<th style="padding: 10px; text-align: left; font-weight: 600; color: #333; font-size: 0.9em;">ID</th>
|
|
<th style="padding: 10px; text-align: left; font-weight: 600; color: #333; font-size: 0.9em;">SKU</th>
|
|
<th style="padding: 10px; text-align: left; font-weight: 600; color: #333; font-size: 0.9em;">Name</th>
|
|
<th style="padding: 10px; text-align: left; font-weight: 600; color: #333; font-size: 0.9em;">Type</th>
|
|
<th style="padding: 10px; text-align: left; font-weight: 600; color: #333; font-size: 0.9em;">Created</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@foreach($m1Products as $product)
|
|
<tr style="border-bottom: 1px solid #e0e0e0;">
|
|
<td style="padding: 8px 10px; font-size: 0.85em;">{{ $product->entity_id }}</td>
|
|
<td style="padding: 8px 10px; font-size: 0.85em; font-weight: 500; color: #667eea;">{{ $product->sku ?? 'N/A' }}</td>
|
|
<td style="padding: 8px 10px; font-size: 0.85em;">{{ $product->name ?? 'Unnamed Product' }}</td>
|
|
<td style="padding: 8px 10px; font-size: 0.85em; color: #666;">{{ $product->type_id ?? 'N/A' }}</td>
|
|
<td style="padding: 8px 10px; font-size: 0.85em; color: #666;">
|
|
@if($product->created_at)
|
|
{{ \Carbon\Carbon::parse($product->created_at)->format('Y-m-d') }}
|
|
@else
|
|
N/A
|
|
@endif
|
|
</td>
|
|
</tr>
|
|
@endforeach
|
|
</tbody>
|
|
</table>
|
|
@else
|
|
<div style="text-align: center; padding: 40px; color: #999;">
|
|
No products found. Please check your database connection.
|
|
</div>
|
|
@endif
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Magento 2 Products -->
|
|
<div>
|
|
<h3 style="margin-bottom: 15px; color: #764ba2;">Magento 2 Products ({{ $m2Products->count() }})</h3>
|
|
<div style="background: white; border: 1px solid #ddd; border-radius: 6px; padding: 20px; max-height: 600px; overflow-y: auto;">
|
|
@if($m2Products->count() > 0)
|
|
<table style="width: 100%; border-collapse: collapse;">
|
|
<thead>
|
|
<tr style="background: #f8f9fa; border-bottom: 2px solid #dee2e6;">
|
|
<th style="padding: 10px; text-align: left; font-weight: 600; color: #333; font-size: 0.9em;">ID</th>
|
|
<th style="padding: 10px; text-align: left; font-weight: 600; color: #333; font-size: 0.9em;">SKU</th>
|
|
<th style="padding: 10px; text-align: left; font-weight: 600; color: #333; font-size: 0.9em;">Name</th>
|
|
<th style="padding: 10px; text-align: left; font-weight: 600; color: #333; font-size: 0.9em;">Type</th>
|
|
<th style="padding: 10px; text-align: left; font-weight: 600; color: #333; font-size: 0.9em;">Created</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@foreach($m2Products as $product)
|
|
<tr style="border-bottom: 1px solid #e0e0e0;">
|
|
<td style="padding: 8px 10px; font-size: 0.85em;">{{ $product->entity_id }}</td>
|
|
<td style="padding: 8px 10px; font-size: 0.85em; font-weight: 500; color: #764ba2;">{{ $product->sku ?? 'N/A' }}</td>
|
|
<td style="padding: 8px 10px; font-size: 0.85em;">{{ $product->name ?? 'Unnamed Product' }}</td>
|
|
<td style="padding: 8px 10px; font-size: 0.85em; color: #666;">{{ $product->type_id ?? 'N/A' }}</td>
|
|
<td style="padding: 8px 10px; font-size: 0.85em; color: #666;">
|
|
@if($product->created_at)
|
|
{{ \Carbon\Carbon::parse($product->created_at)->format('Y-m-d') }}
|
|
@else
|
|
N/A
|
|
@endif
|
|
</td>
|
|
</tr>
|
|
@endforeach
|
|
</tbody>
|
|
</table>
|
|
@else
|
|
<div style="text-align: center; padding: 40px; color: #999;">
|
|
No products found. Please check your database connection.
|
|
</div>
|
|
@endif
|
|
</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 loadM1CategoryTreeWithProducts() {
|
|
const container = document.getElementById('m1-category-products-tree-container');
|
|
container.innerHTML = '<div class="tree-loading">Loading categories and products...</div>';
|
|
|
|
fetch('{{ route("migration.magento1-category-tree-with-products") }}')
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
container.innerHTML = '';
|
|
if (data.tree && data.tree.length > 0) {
|
|
renderCategoryTreeWithProducts(container, data.tree);
|
|
} 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>`;
|
|
});
|
|
}
|
|
|
|
function loadM2CategoryTreeWithProducts() {
|
|
const container = document.getElementById('m2-category-products-tree-container');
|
|
container.innerHTML = '<div class="tree-loading">Loading categories and products...</div>';
|
|
|
|
fetch('{{ route("migration.magento2-category-tree-with-products") }}')
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
container.innerHTML = '';
|
|
if (data.tree && data.tree.length > 0) {
|
|
renderCategoryTreeWithProducts(container, data.tree);
|
|
} 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>`;
|
|
});
|
|
}
|
|
|
|
function renderCategoryTreeWithProducts(container, tree) {
|
|
tree.forEach(node => {
|
|
const nodeElement = createCategoryWithProductsNode(node);
|
|
container.appendChild(nodeElement);
|
|
});
|
|
}
|
|
|
|
function createCategoryWithProductsNode(node) {
|
|
const nodeDiv = document.createElement('div');
|
|
nodeDiv.className = 'tree-node';
|
|
nodeDiv.setAttribute('data-category-id', node.id);
|
|
|
|
const hasChildren = node.children && node.children.length > 0;
|
|
const hasProducts = node.products && node.products.length > 0;
|
|
|
|
const itemDiv = document.createElement('div');
|
|
itemDiv.className = 'tree-node-item';
|
|
|
|
const toggle = document.createElement('span');
|
|
toggle.className = (hasChildren || hasProducts) ? 'tree-toggle collapsed' : 'tree-toggle leaf';
|
|
if (hasChildren || hasProducts) {
|
|
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.products ? node.products.length : 0;
|
|
labelText.textContent = `[${node.id}] ${node.name || 'Unnamed Category'} (${productCount} product${productCount !== 1 ? 's' : ''})`;
|
|
|
|
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);
|
|
itemDiv.appendChild(toggle);
|
|
itemDiv.appendChild(label);
|
|
nodeDiv.appendChild(itemDiv);
|
|
|
|
// Products section
|
|
if (hasProducts) {
|
|
const productsDiv = document.createElement('div');
|
|
productsDiv.className = 'tree-children tree-products';
|
|
productsDiv.style.display = 'none';
|
|
|
|
const productsHeader = document.createElement('div');
|
|
productsHeader.style.cssText = 'padding: 8px 12px; background: #f8f9fa; border-bottom: 1px solid #dee2e6; font-weight: 600; color: #333; font-size: 0.9em;';
|
|
productsHeader.textContent = `Products (${node.products.length}):`;
|
|
productsDiv.appendChild(productsHeader);
|
|
|
|
const productsList = document.createElement('div');
|
|
productsList.style.cssText = 'padding: 8px;';
|
|
|
|
// Sort products by position
|
|
const sortedProducts = [...node.products].sort((a, b) => (a.position || 0) - (b.position || 0));
|
|
|
|
sortedProducts.forEach(product => {
|
|
const productDiv = document.createElement('div');
|
|
productDiv.style.cssText = 'padding: 6px 12px; margin: 4px 0; background: white; border: 1px solid #e0e0e0; border-radius: 4px; font-size: 0.85em;';
|
|
productDiv.innerHTML = `
|
|
<strong style="color: #667eea;">ID: ${product.id}</strong> |
|
|
<strong>SKU:</strong> ${product.sku || 'N/A'} |
|
|
<strong>Name:</strong> ${product.name || 'Unnamed Product'}
|
|
`;
|
|
productsList.appendChild(productDiv);
|
|
});
|
|
|
|
productsDiv.appendChild(productsList);
|
|
nodeDiv.appendChild(productsDiv);
|
|
}
|
|
|
|
// Children categories
|
|
if (hasChildren) {
|
|
const childrenDiv = document.createElement('div');
|
|
childrenDiv.className = 'tree-children';
|
|
childrenDiv.style.display = 'none';
|
|
node.children.forEach(child => {
|
|
childrenDiv.appendChild(createCategoryWithProductsNode(child));
|
|
});
|
|
nodeDiv.appendChild(childrenDiv);
|
|
}
|
|
|
|
return nodeDiv;
|
|
}
|
|
|
|
function syncProductCategories() {
|
|
if (!confirm('Are you sure you want to sync product categories from Magento 1 to Magento 2?\n\nThis will update category assignments for all matching products. Make sure you have a backup!')) {
|
|
return;
|
|
}
|
|
|
|
const button = document.getElementById('syncProductCategoriesBtn');
|
|
const logsDiv = document.getElementById('syncProductCategoriesLogs');
|
|
const originalText = button.textContent;
|
|
|
|
button.disabled = true;
|
|
button.textContent = 'Syncing Categories...';
|
|
button.style.background = '#999';
|
|
button.style.cursor = 'not-allowed';
|
|
|
|
logsDiv.style.display = 'block';
|
|
logsDiv.innerHTML = '<div style="color: #666;">Starting category sync...</div>';
|
|
|
|
fetch('/migration/products/sync-categories', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
|
}
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
button.disabled = false;
|
|
button.textContent = originalText;
|
|
button.style.background = '#1976D2';
|
|
button.style.cursor = 'pointer';
|
|
|
|
if (data.success) {
|
|
// Display logs
|
|
let logHtml = '';
|
|
if (data.log && data.log.length > 0) {
|
|
data.log.forEach(logEntry => {
|
|
let logColor = '#333';
|
|
if (logEntry.includes('ERROR')) {
|
|
logColor = '#d32f2f';
|
|
} else if (logEntry.includes('UPDATED')) {
|
|
logColor = '#1976D2';
|
|
} else if (logEntry.includes('SKIPPED')) {
|
|
logColor = '#666';
|
|
}
|
|
logHtml += `<div style="color: ${logColor}; margin-bottom: 5px;">${logEntry}</div>`;
|
|
});
|
|
} else {
|
|
logHtml = '<div style="color: #666;">No log entries available.</div>';
|
|
}
|
|
|
|
logHtml += `<div style="margin-top: 15px; padding-top: 15px; border-top: 1px solid #ddd; color: #28a745; font-weight: 600;">✓ ${data.message}</div>`;
|
|
logsDiv.innerHTML = logHtml;
|
|
|
|
// Scroll to bottom of logs
|
|
logsDiv.scrollTop = logsDiv.scrollHeight;
|
|
} else {
|
|
logsDiv.innerHTML = `<div style="color: #d32f2f;">✗ Error: ${data.message || 'Failed to sync product categories'}</div>`;
|
|
}
|
|
})
|
|
.catch(error => {
|
|
button.disabled = false;
|
|
button.textContent = originalText;
|
|
button.style.background = '#1976D2';
|
|
button.style.cursor = 'pointer';
|
|
|
|
logsDiv.innerHTML = `<div style="color: #d32f2f;">✗ Error: ${error.message}</div>`;
|
|
});
|
|
}
|
|
|
|
function deleteM2Product(productId, productName, productSku) {
|
|
if (!confirm(`Are you sure you want to delete product ID ${productId}?\n\nProduct: ${productName}\nSKU: ${productSku}\n\nThis action cannot be undone. Make sure you have a backup!`)) {
|
|
return;
|
|
}
|
|
|
|
const row = document.getElementById(`product-row-${productId}`);
|
|
if (!row) return;
|
|
|
|
// Disable the button
|
|
const button = row.querySelector('button');
|
|
const originalText = button.textContent;
|
|
button.disabled = true;
|
|
button.textContent = 'Deleting...';
|
|
button.style.background = '#999';
|
|
button.style.cursor = 'not-allowed';
|
|
|
|
fetch(`/migration/products/${productId}`, {
|
|
method: 'DELETE',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
|
}
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
// Remove the row from the table
|
|
row.style.opacity = '0.5';
|
|
row.style.transition = 'opacity 0.3s';
|
|
setTimeout(() => {
|
|
const section = row.closest('.section');
|
|
row.remove();
|
|
|
|
// Update the count
|
|
const table = section.querySelector('table');
|
|
const remainingRows = table ? table.querySelectorAll('tbody tr').length : 0;
|
|
const summaryDiv = section.querySelector('div[style*="background: #fff3cd"]');
|
|
|
|
if (remainingRows > 0) {
|
|
if (summaryDiv) {
|
|
summaryDiv.innerHTML = `<strong>Total:</strong> ${remainingRows} ${remainingRows === 1 ? 'product' : 'products'} found in Magento 2 but not in Magento 1.`;
|
|
}
|
|
} else {
|
|
// Show success message if all products are deleted
|
|
const tableContainer = section.querySelector('div[style*="max-height: 400px"]');
|
|
if (tableContainer) tableContainer.style.display = 'none';
|
|
if (summaryDiv) summaryDiv.style.display = 'none';
|
|
|
|
// Remove existing success message if any
|
|
const existingSuccess = section.querySelector('div[style*="background: #d4edda"]');
|
|
if (existingSuccess) existingSuccess.remove();
|
|
|
|
const successDiv = document.createElement('div');
|
|
successDiv.style.cssText = 'margin-top: 15px; padding: 15px; background: #d4edda; border-left: 4px solid #28a745; border-radius: 4px; color: #155724;';
|
|
successDiv.textContent = '✓ All Magento 2 products have matching SKUs or IDs in Magento 1.';
|
|
section.appendChild(successDiv);
|
|
}
|
|
}, 300);
|
|
} else {
|
|
button.disabled = false;
|
|
button.textContent = originalText;
|
|
button.style.background = '#d32f2f';
|
|
button.style.cursor = 'pointer';
|
|
alert('✗ Error: ' + (data.message || 'Failed to delete product'));
|
|
}
|
|
})
|
|
.catch(error => {
|
|
button.disabled = false;
|
|
button.textContent = originalText;
|
|
button.style.background = '#d32f2f';
|
|
button.style.cursor = 'pointer';
|
|
alert('✗ Error: ' + error.message);
|
|
});
|
|
}
|
|
|
|
function deleteProductsAboveM1Max() {
|
|
if (!confirm('Are you sure you want to delete all products in Magento 2 that have entity_id greater than the maximum product ID in Magento 1?\n\nThis will permanently delete these products and cannot be undone. Make sure you have a backup!')) {
|
|
return;
|
|
}
|
|
|
|
const button = document.getElementById('deleteProductsAboveM1MaxBtn');
|
|
const originalText = button.textContent;
|
|
button.disabled = true;
|
|
button.textContent = 'Deleting Products...';
|
|
button.style.background = '#999';
|
|
button.style.cursor = 'not-allowed';
|
|
|
|
fetch('{{ route("migration.delete-products-above-m1-max") }}', {
|
|
method: 'DELETE',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
|
}
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
button.disabled = false;
|
|
button.textContent = originalText;
|
|
button.style.background = '#d32f2f';
|
|
button.style.cursor = 'pointer';
|
|
|
|
if (data.success) {
|
|
alert(`✓ ${data.message}\n\nDeleted ${data.deleted} product(s). Max M1 Product ID: ${data.max_m1_id}`);
|
|
// Optionally reload the page to refresh product lists
|
|
// window.location.reload();
|
|
} else {
|
|
alert('✗ Error: ' + (data.message || 'Failed to delete products'));
|
|
}
|
|
})
|
|
.catch(error => {
|
|
button.disabled = false;
|
|
button.textContent = originalText;
|
|
button.style.background = '#d32f2f';
|
|
button.style.cursor = 'pointer';
|
|
|
|
alert('✗ Error: ' + error.message);
|
|
});
|
|
}
|
|
|
|
function startProductMigration(dryRun = false) {
|
|
if (!dryRun) {
|
|
if (!confirm('Are you sure you want to migrate all products from Magento 1 to Magento 2?\n\nThis will create new products or update existing ones based on SKU. Make sure you have a backup!')) {
|
|
return;
|
|
}
|
|
}
|
|
|
|
const button = dryRun ? document.getElementById('dryRunProductMigrationBtn') : document.getElementById('startProductMigrationBtn');
|
|
const otherButton = dryRun ? document.getElementById('startProductMigrationBtn') : document.getElementById('dryRunProductMigrationBtn');
|
|
const originalText = button.textContent;
|
|
button.disabled = true;
|
|
otherButton.disabled = true;
|
|
button.textContent = dryRun ? 'Running Dry Run...' : 'Migrating Products...';
|
|
button.style.background = '#999';
|
|
button.style.cursor = 'not-allowed';
|
|
|
|
// Clear previous logs and hide missing attributes section
|
|
const logContent = document.getElementById('productMigrationLogContent');
|
|
logContent.innerHTML = '<div class="log-entry" style="color: #1976D2;">' + (dryRun ? 'Starting dry run...' : 'Starting product migration...') + '</div>';
|
|
const missingSection = document.getElementById('missingAttributesSection');
|
|
missingSection.style.display = 'none';
|
|
const missingTableBody = document.getElementById('missingAttributesTableBody');
|
|
missingTableBody.innerHTML = '';
|
|
|
|
fetch('{{ route("migration.migrate-products") }}', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
|
},
|
|
body: JSON.stringify({ dry_run: dryRun })
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
button.disabled = false;
|
|
otherButton.disabled = false;
|
|
button.textContent = originalText;
|
|
button.style.background = dryRun ? '#6c757d' : '#1976D2';
|
|
button.style.cursor = 'pointer';
|
|
|
|
if (data.success) {
|
|
// Clear and add new logs
|
|
logContent.innerHTML = '';
|
|
|
|
// Add summary
|
|
const summary = document.createElement('div');
|
|
summary.className = 'log-entry';
|
|
const summaryColor = dryRun ? '#ffc107' : '#28a745';
|
|
const summaryBg = dryRun ? '#fff3cd' : '#d4edda';
|
|
summary.style.cssText = `color: ${summaryColor}; font-weight: 600; margin-bottom: 10px; padding: 10px; background: ${summaryBg}; border-left: 4px solid ${summaryColor}; border-radius: 4px;`;
|
|
summary.textContent = `${dryRun ? '✓ Dry run completed!' : '✓ Migration completed!'} Added: ${data.added}, Updated: ${data.updated}, Errors: ${data.errors}`;
|
|
logContent.appendChild(summary);
|
|
|
|
// Show missing attributes if any
|
|
if (data.missing_attributes && data.missing_attributes.length > 0) {
|
|
missingSection.style.display = 'block';
|
|
data.missing_attributes.forEach(attr => {
|
|
const row = document.createElement('tr');
|
|
row.style.cssText = 'border-bottom: 1px solid #e0e0e0;';
|
|
row.innerHTML = `
|
|
<td style="padding: 8px 10px; font-size: 0.85em; font-weight: 500; color: #667eea;">${attr.code}</td>
|
|
<td style="padding: 8px 10px; font-size: 0.85em;">${attr.label || 'N/A'}</td>
|
|
<td style="padding: 8px 10px; font-size: 0.85em; color: #666;">${attr.type || 'varchar'}</td>
|
|
`;
|
|
missingTableBody.appendChild(row);
|
|
});
|
|
}
|
|
|
|
// Add detailed logs
|
|
if (data.log && data.log.length > 0) {
|
|
data.log.forEach(logEntry => {
|
|
const entry = document.createElement('div');
|
|
entry.className = 'log-entry';
|
|
|
|
if (logEntry.includes('ERROR')) {
|
|
entry.style.cssText = 'color: #d32f2f; margin: 5px 0; padding: 5px;';
|
|
} else if (logEntry.includes('Created new product') || logEntry.includes('Added new') || logEntry.includes('Would create')) {
|
|
entry.style.cssText = 'color: #28a745; margin: 5px 0; padding: 5px;';
|
|
} else if (logEntry.includes('Updating existing') || logEntry.includes('Updated') || logEntry.includes('Would update')) {
|
|
entry.style.cssText = 'color: #1976D2; margin: 5px 0; padding: 5px;';
|
|
} else {
|
|
entry.style.cssText = 'color: #666; margin: 5px 0; padding: 5px;';
|
|
}
|
|
|
|
entry.textContent = logEntry;
|
|
logContent.appendChild(entry);
|
|
});
|
|
}
|
|
|
|
// Scroll to bottom of log container
|
|
const logContainer = document.getElementById('productMigrationLogContainer');
|
|
logContainer.scrollTop = logContainer.scrollHeight;
|
|
} else {
|
|
const errorEntry = document.createElement('div');
|
|
errorEntry.className = 'log-entry';
|
|
errorEntry.style.cssText = 'color: #d32f2f; font-weight: 600; margin: 5px 0; padding: 5px;';
|
|
errorEntry.textContent = '✗ ' + (dryRun ? 'Dry run' : 'Migration') + ' failed: ' + (data.message || 'Unknown error');
|
|
logContent.appendChild(errorEntry);
|
|
}
|
|
})
|
|
.catch(error => {
|
|
button.disabled = false;
|
|
otherButton.disabled = false;
|
|
button.textContent = originalText;
|
|
button.style.background = dryRun ? '#6c757d' : '#1976D2';
|
|
button.style.cursor = 'pointer';
|
|
|
|
const errorEntry = document.createElement('div');
|
|
errorEntry.className = 'log-entry';
|
|
errorEntry.style.cssText = 'color: #d32f2f; font-weight: 600; margin: 5px 0; padding: 5px;';
|
|
errorEntry.textContent = '✗ Error: ' + error.message;
|
|
logContent.appendChild(errorEntry);
|
|
});
|
|
}
|
|
|
|
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');
|
|
|
|
// Save active tab to localStorage
|
|
localStorage.setItem('activeTab', tabName);
|
|
|
|
// Load category trees if switching to categories tab
|
|
if (tabName === 'categories') {
|
|
loadCategoryTrees();
|
|
}
|
|
}
|
|
|
|
// Restore active tab from localStorage on page load
|
|
function restoreActiveTab() {
|
|
const savedTab = localStorage.getItem('activeTab');
|
|
if (savedTab) {
|
|
// Validate that the saved tab exists
|
|
const tabContent = document.getElementById('tab-' + savedTab);
|
|
if (tabContent) {
|
|
// Find the tab button for the saved tab
|
|
const tabs = document.querySelectorAll('.tab');
|
|
tabs.forEach(tab => {
|
|
const onclick = tab.getAttribute('onclick');
|
|
if (onclick && onclick.includes(`'${savedTab}'`)) {
|
|
switchTab(savedTab, tab);
|
|
return;
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
// 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>`;
|
|
});
|
|
}
|
|
|
|
// Show delete confirmation popup
|
|
function showDeleteConfirmPopup(buttonElement, categoryId, categoryName, source, hasChildren, childrenCount) {
|
|
// Remove any existing popup
|
|
const existingPopup = document.querySelector('.delete-confirm-popup');
|
|
const existingOverlay = document.querySelector('.popup-overlay');
|
|
if (existingPopup) existingPopup.remove();
|
|
if (existingOverlay) existingOverlay.remove();
|
|
|
|
// Create overlay
|
|
const overlay = document.createElement('div');
|
|
overlay.className = 'popup-overlay';
|
|
overlay.onclick = function() {
|
|
closeDeleteConfirmPopup();
|
|
};
|
|
document.body.appendChild(overlay);
|
|
|
|
// Create popup
|
|
const popup = document.createElement('div');
|
|
popup.className = 'delete-confirm-popup';
|
|
|
|
// Create popup content
|
|
const title = document.createElement('h3');
|
|
title.textContent = 'Delete Category';
|
|
|
|
const message = document.createElement('p');
|
|
if (hasChildren) {
|
|
message.innerHTML = `Are you sure you want to delete <strong style="color: #d32f2f; font-weight: bold;">"${categoryName}"</strong> and all ${childrenCount} subcategory(ies)? This action cannot be undone.`;
|
|
} else {
|
|
message.innerHTML = `Are you sure you want to delete the category <strong style="color: #d32f2f; font-weight: bold;">"${categoryName}"</strong>? This action cannot be undone.`;
|
|
}
|
|
|
|
const buttonsDiv = document.createElement('div');
|
|
buttonsDiv.className = 'popup-buttons';
|
|
|
|
const cancelBtn = document.createElement('button');
|
|
cancelBtn.className = 'popup-btn popup-btn-cancel';
|
|
cancelBtn.textContent = 'Cancel';
|
|
cancelBtn.onclick = function(e) {
|
|
e.stopPropagation();
|
|
closeDeleteConfirmPopup();
|
|
};
|
|
|
|
const deleteBtn = document.createElement('button');
|
|
deleteBtn.className = 'popup-btn popup-btn-delete';
|
|
deleteBtn.textContent = 'Delete';
|
|
deleteBtn.onclick = function(e) {
|
|
e.stopPropagation();
|
|
closeDeleteConfirmPopup();
|
|
deleteCategory(categoryId, categoryName, source);
|
|
};
|
|
|
|
buttonsDiv.appendChild(cancelBtn);
|
|
buttonsDiv.appendChild(deleteBtn);
|
|
|
|
popup.appendChild(title);
|
|
popup.appendChild(message);
|
|
popup.appendChild(buttonsDiv);
|
|
|
|
// Hide arrow when centered
|
|
popup.classList.add('no-arrow');
|
|
|
|
// Add to DOM
|
|
document.body.appendChild(popup);
|
|
|
|
// Center popup in viewport using CSS transform (works immediately)
|
|
popup.style.position = 'fixed';
|
|
popup.style.top = '50%';
|
|
popup.style.left = '50%';
|
|
popup.style.transform = 'translate(-50%, -50%)';
|
|
popup.style.zIndex = '10000';
|
|
|
|
// Close on Escape key
|
|
const escapeHandler = function(e) {
|
|
if (e.key === 'Escape') {
|
|
closeDeleteConfirmPopup();
|
|
document.removeEventListener('keydown', escapeHandler);
|
|
}
|
|
};
|
|
document.addEventListener('keydown', escapeHandler);
|
|
}
|
|
|
|
// Close delete confirmation popup
|
|
function closeDeleteConfirmPopup() {
|
|
const popup = document.querySelector('.delete-confirm-popup');
|
|
const overlay = document.querySelector('.popup-overlay');
|
|
if (popup) popup.remove();
|
|
if (overlay) overlay.remove();
|
|
}
|
|
|
|
// Refresh M2 categories not in M1 table
|
|
function refreshM2CategoriesNotInM1() {
|
|
fetch('{{ route("migration.m2-categories-not-in-m1") }}', {
|
|
method: 'GET',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
|
}
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
const tbody = document.getElementById('m2-categories-not-in-m1-tbody');
|
|
const totalDiv = document.getElementById('m2-categories-not-in-m1-total');
|
|
const emptyDiv = document.getElementById('m2-categories-not-in-m1-empty');
|
|
|
|
if (!tbody) return;
|
|
|
|
// Clear existing rows
|
|
tbody.innerHTML = '';
|
|
|
|
if (data.categories && data.categories.length > 0) {
|
|
// Show table and total, hide empty message
|
|
const tableWrapper = document.getElementById('m2-categories-not-in-m1-table-wrapper');
|
|
if (tableWrapper) tableWrapper.style.display = 'block';
|
|
if (emptyDiv) emptyDiv.style.display = 'none';
|
|
if (totalDiv) {
|
|
totalDiv.style.display = 'block';
|
|
totalDiv.innerHTML = `<strong>Total:</strong> ${data.count} ${data.count === 1 ? 'category' : 'categories'} found in Magento 2 but not in Magento 1.`;
|
|
}
|
|
|
|
// Add rows
|
|
data.categories.forEach(category => {
|
|
const row = document.createElement('tr');
|
|
row.style.borderBottom = '1px solid #dee2e6';
|
|
|
|
const statusClass = category.is_active ? 'active' : 'inactive';
|
|
const statusText = category.is_active ? 'Active' : 'Inactive';
|
|
|
|
let rootCategoryHtml = '';
|
|
if (category.root_category_name && category.root_category_name !== 'N/A') {
|
|
rootCategoryHtml = `<span style="font-weight: 500;">${category.root_category_name}</span>`;
|
|
if (category.root_category_id) {
|
|
rootCategoryHtml += `<span style="font-size: 0.85em; color: #666;"> (ID: ${category.root_category_id})</span>`;
|
|
}
|
|
} else {
|
|
rootCategoryHtml = '<span style="color: #999;">N/A</span>';
|
|
}
|
|
|
|
// Escape category name for use in JavaScript string
|
|
const categoryNameEscaped = (category.name || 'Unnamed Category')
|
|
.replace(/\\/g, '\\\\')
|
|
.replace(/'/g, "\\'")
|
|
.replace(/"/g, '\\"');
|
|
|
|
row.innerHTML = `
|
|
<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 ${statusClass}">${statusText}</span>
|
|
</td>
|
|
<td style="padding: 10px 12px;">${rootCategoryHtml}</td>
|
|
<td style="padding: 10px 12px; font-size: 0.9em; color: #666;">${category.path || 'N/A'}</td>
|
|
<td style="padding: 10px 12px;">
|
|
<button
|
|
class="tree-delete-btn"
|
|
onclick="showDeleteConfirmPopup(this, ${category.entity_id}, '${categoryNameEscaped}', 'm2', false, 0)"
|
|
title="Delete this category">
|
|
Delete
|
|
</button>
|
|
</td>
|
|
`;
|
|
|
|
tbody.appendChild(row);
|
|
});
|
|
} else {
|
|
// Hide table and total, show empty message
|
|
const tableWrapper = document.getElementById('m2-categories-not-in-m1-table-wrapper');
|
|
if (tableWrapper) tableWrapper.style.display = 'none';
|
|
if (totalDiv) totalDiv.style.display = 'none';
|
|
if (emptyDiv) {
|
|
emptyDiv.style.display = 'block';
|
|
} else {
|
|
// Create empty message if it doesn't exist
|
|
const section = tbody.closest('.section');
|
|
if (section) {
|
|
const newEmptyDiv = document.createElement('div');
|
|
newEmptyDiv.id = 'm2-categories-not-in-m1-empty';
|
|
newEmptyDiv.style.marginTop = '15px';
|
|
newEmptyDiv.style.padding = '15px';
|
|
newEmptyDiv.style.background = '#d4edda';
|
|
newEmptyDiv.style.borderLeft = '4px solid #28a745';
|
|
newEmptyDiv.style.borderRadius = '4px';
|
|
newEmptyDiv.style.color = '#155724';
|
|
newEmptyDiv.textContent = '✓ All Magento 2 categories have matching names in Magento 1.';
|
|
section.appendChild(newEmptyDiv);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error refreshing M2 categories not in M1:', error);
|
|
});
|
|
}
|
|
|
|
// 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();
|
|
// Refresh M2 categories not in M1 table after deleting from M2
|
|
refreshM2CategoriesNotInM1();
|
|
}
|
|
} else {
|
|
container.innerHTML = originalContent;
|
|
alert('Error: ' + (data.message || 'Failed to delete category'));
|
|
}
|
|
})
|
|
.catch(error => {
|
|
container.innerHTML = originalContent;
|
|
alert('Error: ' + error.message);
|
|
});
|
|
}
|
|
|
|
function migrateAttribute(attributeId, attributeCode) {
|
|
if (!confirm(`Are you sure you want to migrate the attribute "${attributeCode}" from Magento 1 to Magento 2?`)) {
|
|
return;
|
|
}
|
|
|
|
const button = document.getElementById(`migrate-btn-${attributeId}`);
|
|
const originalText = button.textContent;
|
|
button.disabled = true;
|
|
button.textContent = 'Migrating...';
|
|
button.style.background = '#999';
|
|
button.style.cursor = 'not-allowed';
|
|
|
|
const url = `{{ route("migration.migrate-attribute", ["attributeId" => ":id"]) }}`.replace(':id', attributeId);
|
|
|
|
fetch(url, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
|
}
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
// Remove the row from the table
|
|
const row = document.getElementById(`attr-row-${attributeId}`);
|
|
if (row) {
|
|
row.style.opacity = '0.5';
|
|
row.style.background = '#d4edda';
|
|
|
|
// Update button to show success
|
|
button.textContent = 'Migrated ✓';
|
|
button.style.background = '#28a745';
|
|
button.disabled = true;
|
|
|
|
// Update count
|
|
const totalSpan = document.getElementById('missingAttributesTotal');
|
|
if (totalSpan) {
|
|
const currentCount = parseInt(totalSpan.textContent);
|
|
if (currentCount > 0) {
|
|
totalSpan.textContent = currentCount - 1;
|
|
const countDiv = document.getElementById('missingAttributesCount');
|
|
if (countDiv && currentCount - 1 === 0) {
|
|
countDiv.innerHTML = '<strong>Total:</strong> 0 attributes found in Magento 1 but not in Magento 2.';
|
|
} else if (countDiv) {
|
|
const plural = (currentCount - 1) === 1 ? 'attribute' : 'attributes';
|
|
countDiv.innerHTML = `<strong>Total:</strong> ${currentCount - 1} ${plural} found in Magento 1 but not in Magento 2.`;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
alert('Attribute migrated successfully!');
|
|
} else {
|
|
button.disabled = false;
|
|
button.textContent = originalText;
|
|
button.style.background = '#1976D2';
|
|
button.style.cursor = 'pointer';
|
|
alert('Error: ' + (data.message || 'Failed to migrate attribute'));
|
|
}
|
|
})
|
|
.catch(error => {
|
|
button.disabled = false;
|
|
button.textContent = originalText;
|
|
button.style.background = '#1976D2';
|
|
button.style.cursor = 'pointer';
|
|
alert('Error: ' + error.message);
|
|
});
|
|
}
|
|
|
|
function migrateAttributeGroup(groupId, setId, groupName) {
|
|
if (!confirm(`Are you sure you want to migrate the attribute group "${groupName}" from Magento 1 to Magento 2?\n\nThis will also migrate any attributes in this group that exist in Magento 2.`)) {
|
|
return;
|
|
}
|
|
|
|
const button = document.getElementById(`migrate-group-btn-${groupId}-${setId}`);
|
|
const originalText = button.textContent;
|
|
button.disabled = true;
|
|
button.textContent = 'Migrating...';
|
|
button.style.background = '#999';
|
|
button.style.cursor = 'not-allowed';
|
|
|
|
const url = `{{ route("migration.migrate-attribute-group", ["groupId" => ":groupId", "setId" => ":setId"]) }}`
|
|
.replace(':groupId', groupId)
|
|
.replace(':setId', setId);
|
|
|
|
fetch(url, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
|
}
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
// Update the row
|
|
const row = document.getElementById(`group-row-${groupId}-${setId}`);
|
|
if (row) {
|
|
row.style.opacity = '0.5';
|
|
row.style.background = '#d4edda';
|
|
|
|
// Update button to show success
|
|
button.textContent = 'Migrated ✓';
|
|
button.style.background = '#28a745';
|
|
button.disabled = true;
|
|
}
|
|
const message = data.attributes_migrated !== undefined
|
|
? `Attribute group migrated successfully! ${data.attributes_migrated} attribute(s) were also migrated to the group.`
|
|
: 'Attribute group migrated successfully!';
|
|
alert(message);
|
|
} else {
|
|
button.disabled = false;
|
|
button.textContent = originalText;
|
|
button.style.background = '#1976D2';
|
|
button.style.cursor = 'pointer';
|
|
alert('Error: ' + (data.message || 'Failed to migrate attribute group'));
|
|
}
|
|
})
|
|
.catch(error => {
|
|
button.disabled = false;
|
|
button.textContent = originalText;
|
|
button.style.background = '#1976D2';
|
|
button.style.cursor = 'pointer';
|
|
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.id}] ${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';
|
|
deleteBtn.title = hasChildren ? 'Delete this category and all subcategories' : 'Delete this category';
|
|
deleteBtn.onclick = function(e) {
|
|
e.stopPropagation();
|
|
showDeleteConfirmPopup(deleteBtn, node.id, node.name, source, hasChildren, node.children ? node.children.length : 0);
|
|
};
|
|
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 childrenDivs = nodeDiv.querySelectorAll('.tree-children');
|
|
|
|
if (childrenDivs.length > 0) {
|
|
// Check if any child div is expanded
|
|
let isExpanded = false;
|
|
childrenDivs.forEach(div => {
|
|
if (div.style.display !== 'none') {
|
|
isExpanded = true;
|
|
}
|
|
});
|
|
|
|
if (isExpanded) {
|
|
// Collapse all children
|
|
childrenDivs.forEach(div => {
|
|
div.style.display = 'none';
|
|
});
|
|
toggleElement.classList.remove('expanded');
|
|
toggleElement.classList.add('collapsed');
|
|
} else {
|
|
// Expand all children
|
|
childrenDivs.forEach(div => {
|
|
div.style.display = 'block';
|
|
});
|
|
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 = `[${node.id}] ${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);
|
|
}
|
|
|
|
// Restore active tab when page loads
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
restoreActiveTab();
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|
|
|