HEX
Server: LiteSpeed
System: Linux premium127.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
User: luxbsolr (925)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: /home/luxbsolr/cardsord.store/wp-content/plugins/Csv_Uploader/DEBUG_QUICK.md
# 🐛 DEBUGGING - QUICK REFERENCE

## ✅ What I Added

**JavaScript (assets/js/admin-new.js):**
- ✅ Detailed console logs at every step
- ✅ Shows AJAX request/response
- ✅ Shows data parsing
- ✅ Shows table building
- ✅ Shows dropdown selection

**PHP (includes/class-fcpi-ajax-handler-rebuilt.php):**
- ✅ Error logs for backend processing
- ✅ Shows file analysis
- ✅ Shows automapper results
- ✅ Shows mappings generated

---

## 🔍 How to Debug

### 1. Open Browser Console
```
Press F12 → Console tab
```

### 2. Upload CSV & Click "Continue to Mapping"

### 3. Look for These Logs:

**✅ SUCCESS (you should see):**
```javascript
=== ANALYZE CSV STARTED ===
Current File ID: abc123xyz
📤 Sending AJAX request
📥 AJAX Response received: {success: true}
✅ Analysis successful

=== HANDLING ANALYSIS RESULT ===
📊 Parsed data:
  - CSV Headers: ["SKU", "Name", "Price"]
  - Auto Mappings: {SKU: "sku", Name: "name"}
  - Confidence Scores: {SKU: 1, Name: 1}

=== BUILD MAPPING TABLE ===
Row 1: {csvHeader: "SKU", autoMapping: "sku"}
  Creating row for: SKU
    Auto-mapping to: sku
    ✓ Dropdown pre-selected: SKU

=== SHOW AUTO-MAPPING RESULTS ===
  - Auto-mapped fields: 12
  - Success rate: 80%
✅ Auto-mapping summary displayed

=== ANALYSIS HANDLING COMPLETE ===
```

**❌ PROBLEM (if you see):**
```javascript
❌ CSV Headers: [] (empty)
❌ Auto Mappings: {} (empty)
❌ Auto-mapped fields: 0
```

---

## 🔧 Common Issues

### Issue 1: Empty Auto-Mappings
**Console shows:**
```javascript
Auto Mappings: {}
Auto-mapped fields: 0
```

**Check PHP error log:**
```
wp-content/debug.log
```

**Look for:**
```
Auto-mappings count: 0
```

**Fix:** Automapper not working - check file exists:
```
includes/class-fcpi-automapper-rebuilt.php
```

---

### Issue 2: No Headers Found
**Console shows:**
```javascript
CSV Headers: []
```

**Fix:** 
- Check CSV file has headers in first row
- Ensure UTF-8 encoding
- Re-save CSV without BOM

---

### Issue 3: Dropdowns Not Selected
**Console shows:**
```javascript
Auto Mappings: {SKU: "sku"}
(but no "✓ Dropdown pre-selected" messages)
```

**Fix:** 
- Check WC field keys match auto-mapping values
- Run in console:
```javascript
console.log('Auto mappings:', FCPI.autoMappings);
console.log('WC fields:', Object.keys(FCPI.wcFields));
```

---

## 📊 Quick Diagnostic

**Run in browser console:**
```javascript
// Check state
console.log('File ID:', FCPI.currentFileId);
console.log('Headers:', FCPI.csvHeaders);
console.log('Mappings:', FCPI.autoMappings);
console.log('Mapped count:', Object.keys(FCPI.autoMappings).length);

// Check table
console.log('Rows:', $('#fcpi-mapping-table-body tr').length);
console.log('Selected:', $('select[name^="mapping["]').filter(function() {
    return $(this).val() !== '';
}).length);
```

**Expected:**
```javascript
File ID: "abc123..."
Headers: (15) ["SKU", "Name", ...]
Mappings: {SKU: "sku", Name: "name", ...}
Mapped count: 12
Rows: 15
Selected: 12
```

---

## 🎯 What to Share

If still not working, send me:

1. **Browser console** (full log)
2. **PHP error log** (`wp-content/debug.log`)
3. **First 3 rows of CSV file**
4. **Diagnostic output** (from Quick Diagnostic above)

---

## 📚 Full Guide

See: `DEBUG_AUTO_MAPPING.md` for complete troubleshooting

---

**Now:** Upload CSV and check console! 🚀