updating importing items 2
This commit is contained in:
parent
a4b81a5393
commit
20fbd07aef
15
index.php
15
index.php
@ -1185,10 +1185,17 @@ function getPromotionalPrice($item) {
|
|||||||
$message = "Error: It looks like you uploaded an Excel (.xlsx) file. Please save it as CSV (UTF-8) and try again.";
|
$message = "Error: It looks like you uploaded an Excel (.xlsx) file. Please save it as CSV (UTF-8) and try again.";
|
||||||
} else {
|
} else {
|
||||||
$handle = fopen($tmpPath, "r");
|
$handle = fopen($tmpPath, "r");
|
||||||
fgetcsv($handle); // Skip header
|
$firstLine = fgets($handle);
|
||||||
|
rewind($handle);
|
||||||
|
|
||||||
|
$sep = ",";
|
||||||
|
if (strpos($firstLine, ";") !== false && strpos($firstLine, ",") === false) $sep = ";";
|
||||||
|
elseif (strpos($firstLine, "\t") !== false) $sep = "\t";
|
||||||
|
|
||||||
|
fgetcsv($handle, 0, $sep); // Skip header
|
||||||
$count = 0; $errors = 0;
|
$count = 0; $errors = 0;
|
||||||
while (($data = fgetcsv($handle)) !== FALSE) {
|
while (($data = fgetcsv($handle, 0, $sep)) !== FALSE) {
|
||||||
if (empty($data[1]) && empty($data[2])) continue;
|
if (empty($data[0]) && empty($data[1]) && empty($data[2])) continue;
|
||||||
try {
|
try {
|
||||||
foreach ($data as &$val) {
|
foreach ($data as &$val) {
|
||||||
if ($val === null) continue;
|
if ($val === null) continue;
|
||||||
@ -1203,7 +1210,7 @@ function getPromotionalPrice($item) {
|
|||||||
sale_price=VALUES(sale_price), purchase_price=VALUES(purchase_price)")
|
sale_price=VALUES(sale_price), purchase_price=VALUES(purchase_price)")
|
||||||
->execute([$data[0] ?? '', $data[1] ?? '', $data[2] ?? '', (float)($data[3] ?? 0), (float)($data[4] ?? 0)]);
|
->execute([$data[0] ?? '', $data[1] ?? '', $data[2] ?? '', (float)($data[3] ?? 0), (float)($data[4] ?? 0)]);
|
||||||
$count++;
|
$count++;
|
||||||
} catch (Exception $e) {
|
} catch (Throwable $e) {
|
||||||
$errors++;
|
$errors++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user