public function getFullUserProfile() { try { if (!$this->id) { throw new Exception('Не задан id пользователя'); } $user['profile'] = $this->userTableModel->readRecordsById(); $this->userTableModel->readUserAddress(); $this->userTableModel->readUserPhones(); $user['contacts'] = $this->userTableModel->getUserContacts(); $orderModel = new OrderTableModel(); $orderModel->setTable('order_body as b, order_type as t, order_status as s, order_delivery_type as d'); $orderModel->setId($this->id); $user['orders'] = $orderModel->readRecordsById('user_id', '*', 'AND b.status_id = s.id AND b.delivery_type = d.id AND s.type_id = t.id'); if (!empty($user['orders'])) { foreach ($user['orders'] as $key => $order) { if ($key !== 'rowCount') { $user['orders'][$key]['body'] = Basket::getProductsList($order['body']); } } } $user['profile']['photo'] = !empty($user['profile'][0]['photo']) ? $user['profile'][0]['photo'] : \app\helpers\Path::DEFAULT_USER_AVATAR; $this->fullProfile = $user; return $user; } catch (Exception $ex) { $ex->getMessage(); } }
public function checkoutAction() { $fc = FrontController::getInstance(); $model = new FrontModel(); if ($_SERVER['REQUEST_METHOD'] === 'POST') { $orderModel = new OrderTableModel(); $orderModel->setData(); $orderModel->addRecord(); Basket::deleteBasket(); \app\services\Session::setMsg('Ваш заказ принят. Наш менеджер свяжется с вами в ближайшее время', 'success'); header('Location: /'); exit; } else { $output = $model->render('../views/order/order.php', 'withoutSliderAndSidebar'); $fc->setPage($output); } }
public function setData($formType = '', $method = '') { $data = []; $method = 'INPUT_POST'; $data['basket'] = Basket::get(); $data['user_id'] = Validate::validateInputVar('user_id', $method, 'int'); $data['delivery_type'] = Validate::validateInputVar('delivery_type', $method, 'int'); $data['user_address'] = Validate::validateInputVar('user_address', $method, 'int'); $data['city'] = Validate::validateInputVar('city', $method, 'str'); $data['street'] = Validate::validateInputVar('street', $method, 'str'); $data['home'] = Validate::validateInputVar('home', $method, 'str'); $data['flat'] = Validate::validateInputVar('flat', $method, 'int'); $data['postal'] = Validate::validateInputVar('postal', $method, 'int'); $data['user_phone'] = Validate::validateInputVar('user_phone', $method, 'int'); $data['number'] = Validate::validateInputVar('number', $method, 'int'); $data['numType'] = Validate::validateInputVar('numType', $method, 'int'); $data['deliveryDate'] = Validate::validateInputVar('deliveryDate', $method, 'str'); $data['deliveryTime'] = Validate::validateInputVar('deliveryTime', $method, 'str'); $data['note'] = Validate::validateInputVar('note', $method, 'str'); $data['rememberAddress'] = Validate::validateInputVar('rememberAddress', $method, 'int'); $data['rememberPhone'] = Validate::validateInputVar('rememberPhone', $method, 'int'); $this->order = new Order($data); }
<tr> <td><?php echo $order['id']; ?> </td> <td><?php echo Basket::getBasketId($order['body']); ?> </td> <td> <table class="table table-bordered table-striped prodList"> <tr> <th>Название</th> <th>Количество</th> </tr> <? $prodList = Basket::getProductsList($order['body']) ?> <? if ($prodList && is_array($prodList)): ?> <? foreach ($prodList as $key => $p):?> <tr> <td><a href="/admin/view/product/<?php echo $key; ?> "><?php echo $p['title']; ?> </a></td> <td><?php echo $p['quantity']; ?> </td> </tr>
static function getProductsFromBasket($image = FALSE) { try { self::init(); $products = []; $productModel = new ProductTableModel(); $productModel->setTable('product as p'); $imageModel = new ImageTableModel(); foreach (self::$basket as $id => $quantity) { if ($id !== 'id' && is_int($id)) { $productModel->setId($id); $product = $productModel->readRecordsById('id', 'p.title, p.price')[0]; if ($image) { $imageModel->setId($id); $imageModel->setTable('image'); $product['image'] = $imageModel->readRecordsById('product_id', 'image', 'AND main = 1')[0]['image']; } $product['total'] = (int) $product['price'] * $quantity; if (is_array($product)) { $products[$id] = new Product($id, $quantity); $products[$id]->setData($product); } } } return $products; } catch (Exception $ex) { Basket::cleanBasket(); Basket::init(); header('Location: /'); exit; } }
public function cleanBasketAction() { header('Content-type: text/plain; charset=utf-8'); header('Cache-Control: no-store, no-cache'); header('Expires: ' . date('r')); echo Basket::cleanBasket(); }
<?php use app\controllers\FrontController; use app\helpers\Basket; use app\services\Session; /* Пути по-умолчанию для поиска файлов */ set_include_path(get_include_path() . PATH_SEPARATOR . 'app/controllers' . PATH_SEPARATOR . 'app/models' . PATH_SEPARATOR . 'app/services' . PATH_SEPARATOR . 'app/helpers' . PATH_SEPARATOR . 'app/tests' . PATH_SEPARATOR . 'app/widgets' . PATH_SEPARATOR . 'app/dataContainers'); /* Автозагрузчик классов */ spl_autoload_register(function ($class) { require_once $class . '.class.php'; }); //классы composer require_once '/app/extensions/vendor/autoload.php'; Session::init(); Basket::init(); /* Инициализация и запуск FrontController */ $controller = FrontController::getInstance(); $controller->route(); /* Вывод данных */ echo $controller->getPage();