Script


SUBMITTED BY: Guest

DATE: April 20, 2015, 11:05 p.m.

FORMAT: Text only

SIZE: 1.5 kB

HITS: 1118

  1. <?PHP
  2. function readCSV($csvFile){
  3. $file_handle = fopen($csvFile, 'r');
  4. while (!feof($file_handle) ) {
  5. $line_of_text[] = fgetcsv($file_handle, 0);
  6. }
  7. fclose($file_handle);
  8. return $line_of_text;
  9. }
  10. if (isset($_POST['submit']) && isset($_FILES['csv']) && ($_FILES['csv']['name'] !== '' && strpos($_FILES['csv']['name'], '.csv') !== false)) {
  11. $working_file = 'temp/redirects.csv';
  12. move_uploaded_file($_FILES['csv']['tmp_name'], $working_file);
  13. // Set path to CSV file;
  14. $csv = readCSV($working_file);
  15. $lastParent = '';
  16. $counter = 0;
  17. $handle = fopen('import.xml', 'w');
  18. foreach ( $csv as $p ) {
  19. $counter++;
  20. $parent = $p[0];
  21. $child = $p[1];
  22. $quantity = $p[2];
  23. if ($parent == $lastParent) {
  24. fwrite($handle, '<Part product_code="'.$child.'" quantity="1" />');
  25. } else {
  26. if ($counter > 1) {
  27. fwrite($handle, '</Parts>');
  28. fwrite($handle, '<ProductVariantPricing>');
  29. fwrite($handle, '<Method>master</Method>');
  30. fwrite($handle, '</ProductVariantPricing>');
  31. fwrite($handle, '</ProductVariant_Update_Default>');
  32. }

comments powered by Disqus