private function confirm() { if ($this->http->isActive('accept')) { if ($this->finalize()) { Location::To(URL . 'user/last'); } else { //Location::() } } $user = new User(\Lib\Session::get('id')); $shippment = array(); $name = $user->getFirstName(); $surname = $user->getSurname(); $country = $user->getCountry(); $zipcode = $user->getZipCode(); $city = $user->getCity(); $street = $user->getStreet(); $house = $user->getHousNr(); $appartment = $user->getAppartmentNr(); $shippment = array($name, $surname, $country, $zipcode, $city, $street, $house, $appartment); foreach ($shippment as $data) { if (empty($data)) { Location::To(URL . 'user/edition'); } } $cart = \Lib\Session::get('cart'); $price = 0; $cart_data = array(); if (!empty($cart)) { foreach ($cart as $key => $product) { $order = new Order($product['order_id']); if (!$order->getQuantity()) { continue; } $order->setUserId(\Lib\Session::get('id')); $price += $order->getQuantity() * $order->getPrice(); $order->writeData(true); $cart_data[$key]['product_name'] = $order->getProductName(); $cart_data[$key]['product_price'] = $order->getQuantity() * $order->getPrice(); $cart_data[$key]['product_quantity'] = $order->getQuantity(); } } $this->categories_m = new \models\Categories(); $this->categories = $this->categories_m->getCategories(); $this->category_ids = $this->categories_m->getCategoriesIds(); $this->products_m = new \models\Products(); $this->d_product = $this->products_m->getDayProduct(); $shipping_method = $this->http->get('shipping_method'); $shipping = new Shippment($shipping_method); $shipping_cost = $shipping->getCost(); if (empty($shipping_cost)) { Location::To(URL . 'cart/show'); } $method = $this->http->get('shipping_method'); $this->render('confirm', array('categories' => $this->categories, 'd_product' => $this->d_product, 'shippment' => $shippment, 'price' => $price, 'shipping_cost' => $shipping_cost, 'cart_data' => $cart_data, 'method' => $method, 'ids' => $this->category_ids)); }
public function buy(Order $order) { $query = "INSERT INTO cartsproducts (cartId, productId, quantity)\n VALUES (?, ?, ?)"; $params = [$order->getCartId(), $order->getProductId(), $order->getQuantity()]; $this->db->query($query, $params); $result = $this->db->row(); $query = "UPDATE carts SET value = value + ?\n WHERE carts.id = ?"; $params = [$order->getQuantity() * $order->getPrice(), $order->getCartId()]; $this->db->query($query, $params); $query = "UPDATE products SET quantity = quantity - ?\n WHERE products.id = ?"; $params = [$order->getQuantity(), $order->getProductId()]; $this->db->query($query, $params); return $result; }