File: /home/luxbsolr/cardsord.store/wp-content/plugins/Csv_Uploader/test_price_and_brand.php
<?php
/**
* Test price switching and brand field functionality
*/
// Include necessary files
require_once 'includes/class-fcpi-product-mapper.php';
require_once 'includes/class-fcpi-batch-processor.php';
echo "=== Price Switching and Brand Field Test ===\n\n";
// Test 1: Price switching functionality
echo "Test 1: Price Auto-Switching\n";
echo "=====================================\n";
$mapper = new FCPI_Product_Mapper();
// Test data where sale price is higher than regular price (needs switching)
$csv_data = array(
'Product Name' => 'Test Product',
'Regular Price' => '80.00',
'Sale Price' => '100.00',
'Brand' => 'Test Brand'
);
// Set up mappings
$mapper->set_mapping('Product Name', 'name');
$mapper->set_mapping('Regular Price', 'regular_price');
$mapper->set_mapping('Sale Price', 'sale_price');
$mapper->set_mapping('Brand', 'brand');
// Map the data
$mapped_data = $mapper->map_row_data($csv_data);
echo "Original Data:\n";
echo "Regular Price: $80.00\n";
echo "Sale Price: $100.00\n";
echo "Brand: Test Brand\n\n";
echo "After Processing:\n";
echo "Regular Price: $" . $mapped_data['_regular_price'] . "\n";
echo "Sale Price: $" . $mapped_data['_sale_price'] . "\n";
echo "Brand: " . (isset($mapped_data['pa_brand']) ? $mapped_data['pa_brand'] : 'NOT MAPPED') . "\n\n";
// Check if prices were switched
if ($mapped_data['_regular_price'] == '100.00' && $mapped_data['_sale_price'] == '80.00') {
echo "✅ Prices were correctly auto-switched!\n";
echo " Regular Price is now higher: $100.00\n";
echo " Sale Price is now lower: $80.00\n";
} else {
echo "❌ Prices were NOT switched\n";
echo " Regular Price: $" . $mapped_data['_regular_price'] . "\n";
echo " Sale Price: $" . $mapped_data['_sale_price'] . "\n";
}
echo "\n";
// Test 2: Brand field mapping
echo "Test 2: Brand Field Mapping\n";
echo "=====================================\n";
if (isset($mapped_data['pa_brand'])) {
echo "✅ Brand field was mapped correctly!\n";
echo " Mapped to: pa_brand\n";
echo " Value: " . $mapped_data['pa_brand'] . "\n";
} else {
echo "❌ Brand field was NOT mapped\n";
echo "Available mapped fields:\n";
foreach ($mapped_data as $key => $value) {
echo " $key => $value\n";
}
}
echo "\n";
// Test 3: Check field definitions
echo "Test 3: Field Definitions Check\n";
echo "=====================================\n";
$wc_fields = $mapper->get_wc_fields();
if (isset($wc_fields['brand'])) {
echo "✅ Brand field is defined in WC fields\n";
echo " Label: " . $wc_fields['brand']['label'] . "\n";
echo " WC Field: " . $wc_fields['brand']['wc_field'] . "\n";
echo " Type: " . $wc_fields['brand']['type'] . "\n";
} else {
echo "❌ Brand field is NOT defined in WC fields\n";
}
echo "\n";
// Test 4: Price validation logic
echo "Test 4: Price Validation Logic\n";
echo "=====================================\n";
// Test normal case (sale < regular)
$normal_data = array(
'_regular_price' => '100.00',
'_sale_price' => '80.00'
);
echo "Normal case (sale < regular):\n";
echo "Regular: $100.00, Sale: $80.00\n";
// Simulate validation (since method is private, we'll test manually)
$regular = floatval($normal_data['_regular_price']);
$sale = floatval($normal_data['_sale_price']);
if ($sale > $regular && $regular > 0) {
echo "Would switch: YES\n";
} else {
echo "Would switch: NO ✅\n";
}
echo "\n";
// Test switched case (sale > regular)
$switched_data = array(
'_regular_price' => '80.00',
'_sale_price' => '100.00'
);
echo "Switched case (sale > regular):\n";
echo "Regular: $80.00, Sale: $100.00\n";
$regular = floatval($switched_data['_regular_price']);
$sale = floatval($switched_data['_sale_price']);
if ($sale > $regular && $regular > 0) {
echo "Would switch: YES ✅\n";
echo "Result would be: Regular: $100.00, Sale: $80.00\n";
} else {
echo "Would switch: NO\n";
}
echo "\n=== Summary ===\n";
echo "1. Price auto-switching: " . ($mapped_data['_regular_price'] == '100.00' ? "✅ WORKING" : "❌ NOT WORKING") . "\n";
echo "2. Brand field mapping: " . (isset($mapped_data['pa_brand']) ? "✅ WORKING" : "❌ NOT WORKING") . "\n";
echo "3. Brand field definition: " . (isset($wc_fields['brand']) ? "✅ DEFINED" : "❌ NOT DEFINED") . "\n";
?>