Session->getData();
//Bestellung abgesendet
if($this->Input->post('submit')){
$areas = unserialize($GLOBALS['TL_CONFIG']['delivery_area']);
if($this->Input->post('name') == 'Vorname Nachname' || $this->Input->post('city') == 'Ort' || $this->Input->post('postal') == 'Postleitzahl' || $this->Input->post('phone') == 'Telefonnummer' || $this->Input->post('street') == 'Straße Hausnummer' || $this->Input->post('email') == 'Emailadresse') {
$this->Template->status = 'Bitte alle Felder ausfüllen!';
} else {
foreach($areas as $area) {
if($this->Input->post('postal') == $area[0]){
if($session['sum'] <= $area[3]){
$this->Template->status = 'Du hast den Mindestbestellwert für '.$area[1].' nicht erreicht';
} else {
//Bestellung erfolgreich
$this->Template->status = 'Wir haben deine Bestellung erhalten und sind schon unterwegs nach '.$this->Input->post('city');
//Datenbankeintrag
$this->Database->prepare("INSERT INTO tl_delivery_offer (tstamp, articles, sum, time, name, street, additional, postal, city, phone, email, comment) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")->execute(time(), $session['articles'], $session['sum'], $this->Input->post('time'), $this->Input->post('name'), $this->Input->post('street'), $this->Input->post('street_additional'), $this->Input->post('postal'), $this->Input->post('city'), $this->Input->post('phone'), $this->Input->post('email'), $this->Input->post('comment'));
//Email an Subway
$mail_text = '
| Wohin?: |
'.$this->Input->post('name').' |
|
'.$this->Input->post('street').' ('.$this->Input->post('street_additional').') |
|
'.$this->Input->post('postal').' '.$this->Input->post('city').' |
|
Telefon: '.$this->Input->post('phone').' / Email: '.$this->Input->post('email').' |
| Wann |
'.$this->Input->post('time').' |
| Kommentar: |
'.$this->Input->post('comment').' |
| Bestellung-Nr. '.date('dmyHi').' / Datum: '.date('d.m.Y').' / Uhrzeit: '.date('H:i').' |
';
foreach($session['articles'] as $article){
$article = unserialize($article);
$mail_text .= '
| '.$article['amount'].' x |
'.$article['category'].': '.$article['title'].' |
'.$article['amount'] * $article['price'].' € |
| Auswahl |
'.$article['variant'].' |
|
';
$options = explode(',', $article['options']);
foreach($options as $option){
$mail_text .= '
|
'.$option.' |
|
';
}
if($article['menu'] == 'true'){
$mail_text .= '
|
|
|
|
als Menu mit '.$article['menu_snack'].' und '.$article['menu_drink'].' (+ Pfand) |
|
';
}
}
$mail_text .= '
| Gesamtsumme: |
'.$session['sum'].' € |
';
$objEmail = new Email();
$objEmail->from = $GLOBALS['TL_ADMIN_EMAIL'];
$objEmail->subject = "Lieferservice nach ".$this->Input->post('city');
$objEmail->html = html_entity_decode($mail_text);
$objEmail->sendTo($GLOBALS['TL_CONFIG']['delivery_email']);
//Session löschen
unset($session['articles']);
unset($session['sum']);
$this->Session->setData($session);
}
break;
} else {
$this->Template->status = 'Leider liefern wir noch nicht nach '.$this->Input->post('city');
}
}
}
}
//Artikel gelöscht
if(is_numeric($this->Input->get('delete'))){
$article = unserialize($session['articles'][$this->Input->get('delete')]);
$session['sum'] = $session['sum'] - $article['price'] * $article['amount'];
unset($session['articles'][$this->Input->get('delete')]);
sort($session['articles']);
$this->Session->setData($session);
}
if($session['articles']){
$articles = array();
foreach($session['articles'] as $article)
{
$articles[] = unserialize($article);
}
$arrArticles = array();
foreach($articles as $article)
{
$arrArticles[] = array(
'amount' => $article['amount'],
'title' => $article['title'],
'menu' => $article['menu'],
'menu_drink' => $article['menu_drink'],
'menu_snack' => $article['menu_snack'],
'price' => $article['amount'] * $article['price']
);
}
}
$this->Template->sum = $session['sum'];
$this->Template->articles = $arrArticles;
}
}
?>