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/test_row25_error.php
<?php
/**
 * Test to simulate the exact Row 25 error
 */

// Simulate WordPress functions
function __($text, $domain = '') { return $text; }
function apply_filters($hook, $value) { return $value; }
function wc_get_product_id_by_sku($sku) { return false; }

// Include classes
require_once 'includes/class-fcpi-product-mapper.php';
require_once 'includes/class-fcpi-validator.php';

echo "=== Simulating Row 25 Validation Error ===\n\n";

// Test with potentially problematic data
$test_cases = array(
    'Case 1: Missing Product Name' => array(
        'SKU' => 'TEST-001',
        'Price' => '29.99'
    ),
    'Case 2: Empty Product Name' => array(
        'Product Name' => '',
        'SKU' => 'TEST-002', 
        'Price' => '39.99'
    ),
    'Case 3: Null Product Name' => array(
        'Product Name' => null,
        'SKU' => 'TEST-003',
        'Price' => '49.99'
    ),
    'Case 4: Valid Product Name' => array(
        'Product Name' => 'Valid Product',
        'SKU' => 'TEST-004',
        'Price' => '59.99'
    )
);

$mapper = new FCPI_Product_Mapper();
$validator = new FCPI_Validator();

// Set up mapping (Product Name -> post_title)
$mapper->set_mapping('Product Name', 'post_title');
$mapper->set_mapping('SKU', '_sku');
$mapper->set_mapping('Price', '_sale_price');

foreach ($test_cases as $case_name => $csv_data) {
    echo "=== {$case_name} ===\n";
    echo "CSV: " . json_encode($csv_data) . "\n";
    
    $mapped_data = $mapper->map_row_data($csv_data);
    echo "Mapped: " . json_encode($mapped_data) . "\n";
    
    $validation = $validator->validate_product($mapped_data, 25);
    echo "Errors: " . count($validation['errors']) . "\n";
    foreach ($validation['errors'] as $error) {
        echo "- {$error}\n";
    }
    echo "\n";
}

echo "=== Field Mapping Analysis ===\n";
$wc_fields = $mapper->get_wc_fields();
$name_field = $wc_fields['name'];
echo "Name field config: " . json_encode($name_field) . "\n";

echo "\nValidator field map (from validate_product method):\n";
$wc_field_map = array(
    'name' => 'post_title',
    'sku' => 'sku',
    'regular_price' => 'regular_price',
    'sale_price' => 'sale_price',
    'description' => 'post_content',
    'short_description' => 'post_excerpt',
    'weight' => 'weight',
    'stock_quantity' => 'stock_quantity',
    'categories' => 'product_cat',
    'tags' => 'product_tag',
    'images' => 'images',
    'featured_image' => 'featured_image',
    'brand' => 'pa_brand'
);
echo "name -> " . $wc_field_map['name'] . "\n";