Added Preorder discount code import and statusupdate import
This commit is contained in:
@@ -756,7 +756,83 @@ class PreorderController extends mfBaseController {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected function statusupdateimport() {
|
||||
$this->layout()->setTemplate("Preorder/Statusupdateimport");
|
||||
}
|
||||
|
||||
protected function saveStatusupdateimport() {
|
||||
$headline_included = $this->request->headline;
|
||||
|
||||
if(is_array($_FILES) && array_key_exists("statusupdate_csv", $_FILES) && !$_FILES['statusupdate_csv']['error']) {
|
||||
// look for uploaded import file
|
||||
try {
|
||||
// returns File object or throws Exception on error
|
||||
$file = mfUpload::handleFormUpload("statusupdate_csv");
|
||||
} catch(Exception $ex) {
|
||||
$this->layout()->setFlash("Fehler beim Dateiupload: " . $ex->getMessage(), "error");
|
||||
$this->redirect("Preorder", "statusupdateimport");
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
$notfound = 0;
|
||||
$invalidcode = 0;
|
||||
$nochange = 0;
|
||||
$saved = 0;
|
||||
|
||||
$filename = $file->getFullPath();
|
||||
$input = fopen($filename, "r");
|
||||
while($csv = fgetcsv($input, 0, ";")) {
|
||||
$i++;
|
||||
if($i == 1 && $headline_included) continue;
|
||||
|
||||
if(!trim($csv[0])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$oaid = trim($csv[0]);
|
||||
$new_status_code = trim($csv[1]);
|
||||
|
||||
$preorder = PreorderModel::getFirstActive(["oaid" => $oaid]);
|
||||
if(!$preorder) {
|
||||
$notfound++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if($preorder->status->code != $new_status_code) {
|
||||
$new_status = PreorderstatusModel::getFirst(["code" => $new_status_code]);
|
||||
if(!$new_status_code) {
|
||||
$invalidcode++;
|
||||
continue;
|
||||
}
|
||||
$preorder->status_id = $new_status->id;
|
||||
$preorder->save();
|
||||
$saved++;
|
||||
} else {
|
||||
$nochange++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$message = "Import erfolgreich. $saved Statusupdates importiert";
|
||||
if($notfound) {
|
||||
$message .= "<br />$notfound Bestellungen nicht gefunden";
|
||||
}
|
||||
if($nochange) {
|
||||
$message .= "<br />$nochange Bestelllungen haben bereits den neuen Status";
|
||||
}
|
||||
if($invalidcode) {
|
||||
$message .= "<br />$invalidcode ungültige Statuscodes";
|
||||
}
|
||||
$this->layout()->setFlash($message);
|
||||
$this->redirect("Preorder", "statusupdateimport");
|
||||
|
||||
} else {
|
||||
$this->layout()->setFlash("Nichts importiert!", "info");
|
||||
$this->redirect("Preorder", "statusupdateimport");
|
||||
}
|
||||
}
|
||||
|
||||
protected function exportAction() {
|
||||
$rfilter = $this->request->filter;
|
||||
if(!is_array($rfilter)) {
|
||||
|
||||
Reference in New Issue
Block a user