public function show() { $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(); $cart = \Lib\Session::get('cart'); $cart_data = array(); $shippments_m = new Shippments(); $shippments = $shippments_m->getShippmentMethods(); $ship_array = array(); foreach ($shippments as $k => $m) { $ship_array[$k]['id'] = $m->getId(); $ship_array[$k]['cost'] = $m->getCost(); $ship_array[$k]['shipping_name'] = $m->getShippingName(); } if (!empty($cart)) { foreach ($cart as $key => $product) { $order = new Order($product['order_id']); if (!$order->getQuantity()) { continue; } $cart_data[$key]['product_id'] = $order->getProductId(); $cart_data[$key]['product_name'] = $order->getProductName(); $cart_data[$key]['product_price'] = $order->getQuantity() * $order->getPrice(); $cart_data[$key]['product_quantity'] = $order->getQuantity(); } } $this->render('cart', array('categories' => $this->categories, 'd_product' => $this->d_product, 'shipping' => $ship_array, 'cart_data' => $cart_data, '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; }