File: /home/luxbsolr/cardsord.store/wp-content/plugins/Csv_Uploader/test_price_logic.php
<?php
/**
* Test price logic to verify sale/regular price handling
*/
// Include necessary files
require_once 'includes/class-fcpi-product-mapper.php';
require_once 'includes/class-fcpi-batch-processor.php';
echo "=== Price Logic Test ===\n\n";
// Test 1: Normal case - sale price lower than regular price
echo "Test 1: Normal case (sale < regular)\n";
$test_data_1 = array(
'_regular_price' => '100.00',
'_sale_price' => '80.00'
);
echo "Regular Price: $100.00\n";
echo "Sale Price: $80.00\n";
echo "Expected Display Price: $80.00 (sale price)\n";
// Simulate the price logic from batch processor
if (isset($test_data_1['_sale_price']) && !empty($test_data_1['_sale_price'])) {
$display_price = $test_data_1['_sale_price'];
echo "Actual Display Price: $$display_price ✓\n\n";
} elseif (isset($test_data_1['_regular_price'])) {
$display_price = $test_data_1['_regular_price'];
echo "Actual Display Price: $$display_price\n\n";
}
// Test 2: Potential switched case - sale price higher than regular price
echo "Test 2: Potential switched case (sale > regular)\n";
$test_data_2 = array(
'_regular_price' => '80.00',
'_sale_price' => '100.00'
);
echo "Regular Price: $80.00\n";
echo "Sale Price: $100.00\n";
echo "⚠️ WARNING: Sale price is higher than regular price!\n";
echo "This suggests the fields might be mapped incorrectly.\n";
// Validate price logic
$regular_price = floatval($test_data_2['_regular_price']);
$sale_price = floatval($test_data_2['_sale_price']);
if ($sale_price > $regular_price && $regular_price > 0) {
echo "❌ Price validation failed: Sale price ($sale_price) > Regular price ($regular_price)\n";
echo "Recommendation: Check your CSV field mapping\n\n";
}
// Test 3: Only regular price provided
echo "Test 3: Only regular price provided\n";
$test_data_3 = array(
'_regular_price' => '100.00'
);
echo "Regular Price: $100.00\n";
echo "Sale Price: (not provided)\n";
echo "Expected Display Price: $100.00 (regular price)\n";
if (isset($test_data_3['_sale_price']) && !empty($test_data_3['_sale_price'])) {
$display_price = $test_data_3['_sale_price'];
echo "Actual Display Price: $$display_price\n\n";
} elseif (isset($test_data_3['_regular_price'])) {
$display_price = $test_data_3['_regular_price'];
echo "Actual Display Price: $$display_price ✓\n\n";
}
echo "=== WooCommerce Price Field Explanation ===\n";
echo "_regular_price: The normal/original price of the product\n";
echo "_sale_price: The discounted price (should be lower than regular)\n";
echo "_price: The actual selling price (equals sale_price if exists, otherwise regular_price)\n\n";
echo "=== Common Mapping Issues ===\n";
echo "1. CSV column 'Price' gets auto-mapped to 'Regular Price'\n";
echo "2. If your CSV 'Price' column contains sale prices, manually map it to 'Sale Price'\n";
echo "3. Always ensure Sale Price < Regular Price for proper WooCommerce behavior\n";
?>