<?PHP
function readCSV($csvFile){
$file_handle = fopen($csvFile, 'r');
while (!feof($file_handle) ) {
$line_of_text[] = fgetcsv($file_handle, 0);
}
fclose($file_handle);
return $line_of_text;
}
if (isset($_POST['submit']) && isset($_FILES['csv']) && ($_FILES['csv']['name'] !== '' && strpos($_FILES['csv']['name'], '.csv') !== false)) {
$working_file = 'temp/redirects.csv';
move_uploaded_file($_FILES['csv']['tmp_name'], $working_file);
// Set path to CSV file;
$csv = readCSV($working_file);
$lastParent = '';
$counter = 0;
$handle = fopen('import.xml', 'w');
foreach ( $csv as $p ) {
$counter++;
$parent = $p[0];
$child = $p[1];
$quantity = $p[2];
if ($parent == $lastParent) {
fwrite($handle, '<Part product_code="'.$child.'" quantity="1" />');
} else {
if ($counter > 1) {
fwrite($handle, '</Parts>');
fwrite($handle, '<ProductVariantPricing>');
fwrite($handle, '<Method>master</Method>');
fwrite($handle, '</ProductVariantPricing>');
fwrite($handle, '</ProductVariant_Update_Default>');
}