Acme -- Custom CSV to XML (Variant based) Volume Pricing Pricing (variant based) custom field (minmum)
<?php
if ( isset($_POST['username']) && isset($_POST['password']) ) {
if ($_POST['username'] == 'YOURUSERNAME' && $_POST['password'] == 'YOURPASSWORD') {
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)) {
header('Content-Type: application/xhtml+xml');
header('Content-Disposition: attachment; filename='.basename('import.xml'));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize(''));
$csv = readCSV($_FILES['csv']['tmp_name']);
$counter = 0;
$volumePricingName = 'Per Product Volume Pricing';
//Volume Pricing
echo '<Module code="discount_volume" feature="discount">' . PHP_EOL;
$oldCode = '';
$lastCode = '';
foreach ($csv as $c) {
$counter++;
if ($counter > 1 && $c[1]) {
if($c['0']) {
$code = $c['0'];
}
if ($oldCode !== '' && $oldCode !== $code ) {
echo "\t".'</ProductPricingTable>' . PHP_EOL;
}
if($c['0']) {
echo "\t".'<ProductPricingTable group_name="'.$volumePricingName.'" product_code="'.$code.'">' . PHP_EOL;
echo "\t\t".'<Entry quantity="1" type="absolute" amount="'.$c[3].'" />' . PHP_EOL;
} else {
echo "\t\t".'<Entry quantity="'.$c[1].'" type="absolute" amount="'.$c[3].'" />' . PHP_EOL;
}
$oldCode = $code;
}
}
echo "\t".'</ProductPricingTable>' . PHP_EOL;
echo '</Module>';
echo PHP_EOL . PHP_EOL;
$counter = 0;
// Price
foreach ($csv as $c) {
$counter++;
if ($c['0'] && $counter > 1) {
echo '<Product_Update code="'.$c[0].'">'. PHP_EOL;;
echo "\t".'<Price>'.$c[3].'</Price>'. PHP_EOL;;
echo '</Product_Update>'. PHP_EOL;;
}
}
echo PHP_EOL . PHP_EOL;
$counter = 0;
// Customfields
/*
echo '<Module code="customfields" feature="fields_prod">' . PHP_EOL;
foreach ($csv as $c) {
$counter++;
if ($c['0'] && $c['1'] !== '1' && $counter > 1) {
echo "\t".'<ProductField_Value product="'.$c['0'].'" field="minimum">'.$c['1'].'</ProductField_Value>' . PHP_EOL;
}
}
echo '</Module>' . PHP_EOL; */
exit;
} else {
//form here.
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<div class="row">
<input type="file" name="csv" class="custom-file-input" />
</div>
<div class="row">
<input type="submit" name="submit" value="Create XML File"/>
</div>
<input type="hidden" name="username" value="<?php echo $_POST['username']; ?>" />
<input type="hidden" name="password" value="<?php echo $_POST['password']; ?>" />
</form>
<br />
<a href="example.csv">Click here for an example csv.</a>
<?php
}
} else { ?>
<strong>Incorrect. Please try again.</strong>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<div class="row">
Username:<br /><input type="text" name="username" />
</div>
<div class="row">
Password:<br /><input type="password" name="password"/>
</div>
<div class="row">
<input type="submit" name="Enter" value="submit" />
</div>
</form>
<?PHP }
} else { ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<div class="row">
Username:<br /><input type="text" name="username" />
</div>
<div class="row">
Password:<br /><input type="password" name="password"/>
</div>
<div class="row">
<input type="submit" name="Enter" value="submit" />
</div>
</form>
<?php } ?>- Adding example CSV for acme