/** * Get the data */ private function getData() { // get cookie $this->orderId = Cookie::get('order_id'); // check if cookies are available $this->cookiesEnabled = Cookie::hasAllowedCookies(); // check if cookies exists if ($this->orderId || $this->cookiesEnabled == true) { // get the products $this->products = FrontendCatalogModel::getProductsByOrder($this->orderId); // count amount of products in shopping cart $this->amountOfProducts = count($this->products); // total price $this->totalPrice = '0'; // calculate total amount foreach ($this->products as &$product) { // calculate total $subtotal = (int) $product['subtotal_price']; $this->totalPrice = (int) $this->totalPrice; $this->totalPrice = $this->totalPrice + $subtotal; } $this->totalPriceArr['total'] = $this->totalPrice; // insert total price in db FrontendCatalogModel::updateOrder($this->totalPriceArr, $this->orderId); } }
/** * Validate the form */ private function validateForm() { // is the form submitted if ($this->frm->isSubmitted()) { // cleanup the submitted fields, ignore fields that were added by hackers $this->frm->cleanupFields(); // validate required fields $this->frm->getField('email')->isEmail(FL::err('EmailIsRequired')); $this->frm->getField('fname')->isFilled(FL::err('MessageIsRequired')); $this->frm->getField('lname')->isFilled(FL::err('MessageIsRequired')); $this->frm->getField('address')->isFilled(FL::err('MessageIsRequired')); $this->frm->getField('hnumber')->isFilled(FL::err('MessageIsRequired')); $this->frm->getField('postal')->isFilled(FL::err('MessageIsRequired')); $this->frm->getField('hometown')->isFilled(FL::err('MessageIsRequired')); // correct? if ($this->frm->isCorrect()) { // build array $order['email'] = $this->frm->getField('email')->getValue(); $order['fname'] = $this->frm->getField('fname')->getValue(); $order['lname'] = $this->frm->getField('lname')->getValue(); $order['address'] = $this->frm->getField('address')->getValue(); $order['hnumber'] = $this->frm->getField('hnumber')->getValue(); $order['postal'] = $this->frm->getField('postal')->getValue(); $order['hometown'] = $this->frm->getField('hometown')->getValue(); $order['status'] = 'moderation'; // insert values in database FrontendCatalogModel::updateOrder($order, $this->cookieOrderId); // delete cookie $argument = 'order_id'; unset($_COOKIE[(string) $argument]); setcookie((string) $argument, null, 1, '/'); // set cookies person --> optional Cookie::set('email', $order['email']); Cookie::set('fname', $order['fname']); Cookie::set('lname', $order['lname']); Cookie::set('address', $order['address']); Cookie::set('hnumber', $order['hnumber']); Cookie::set('postal', $order['postal']); Cookie::set('hometown', $order['hometown']); Cookie::set('status', $order['status']); // trigger event FrontendModel::triggerEvent('Catalog', 'after_add_order', array('order' => $order)); $url = FrontendNavigation::getURLForBlock('Catalog', 'OrderReceived'); $this->redirect($url); } } }