public function index() { if (isset($_SESSION['user_id']) || isset($_SESSION['user_id']) && $_SESSION['user_id'] > 0) { $sid = $_SESSION['user_id']; $products_collection = new ProductsCollection(); $product = $products_collection->get($_GET['id']); $orders_collection = new OrdersCollection($_SESSION['user_id']); $orders = $orders_collection->get_all(); $orders_is_accepted = 0; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $orders = new OrderEntity(); $orders->setName($_POST['name']); $orders->setEmail($_POST['email']); $orders->setPhone($_POST['phone']); $orders->setProductId($_GET['id']); $orders->setDate($_POST['date']); $orders->setIsComplete(0); $orders->setUserId($_POST['name']); $orders_collection = new OrdersCollection($_SESSION['user_id']); $orders_collection->save($orders); } else { $orders_is_accepted = 1; } $this->loadView('website/orders', array('orders' => $orders, 'sid' => $sid, 'product' => $product, 'orders_is_accepted' => $orders_is_accepted)); } else { header('Location: index.php?frontcontroller=login'); } }
public function get_by_ordername($ordername) { $tmp = $this->db->select_row('SELECT id, name FROM orders WHERE name = "' . $ordername . '"'); $entity = null; if (!empty($tmp)) { $entity = new OrderEntity(); $entity->setId($tmp['id']); $entity->setName($tmp['name']); } return $entity; }
public function initOrder() { if (!empty($this->order['id']) && is_numeric($this->order['id'])) { $orderEntity = new OrderEntity($this->order['id'], $this->doorGets); $orderData = $orderEntity->getData(); if (is_array($orderData)) { $this->order = array_merge($this->order, $orderData); } } }
/** * Delete a order * * @param OrderEntity the order object */ public function delete(OrderEntity $order) { $sql = "DELETE FROM Orders WHERE Id = :id"; $stmt = $this->db->prepare($sql); $result = $stmt->execute(["id" => $order->getId()]); if (!$result) { throw new Exception("could not delete record"); } }