/** * Place order and clear cart * @throws \Simplon\Mysql\MysqlException */ public function placeOrder($billingStreet, $billingCity, $billingState, $billingZip, $shippingStreet, $shippingCity, $shippingState, $shippingZip, $email) { $query = ' SELECT * FROM aca_cart_product WHERE cart_id= :cartId'; // Get all user orders that are in the cart $data = $this->cart->getCart(); // If there are products in the order if (!empty($data)) { // Add order to order table $orderId = $this->db->insert('aca_order', array('user_id' => $this->session->get('user_id'), 'billing_street' => $billingStreet, 'billing_city' => $billingCity, 'billing_state' => $billingState, 'billing_zip' => $billingZip, 'shipping_street' => $shippingStreet, 'shipping_city' => $shippingCity, 'shipping_state' => $shippingState, 'shipping_zip' => $shippingZip, 'email' => $email)); // Iterate through products and add to order product table foreach ($data as $product) { $this->db->insert('aca_order_product', array('order_id' => $orderId, 'product_id' => $product['cp_product_id'], 'quantity' => $product['cp_quantity'], 'price' => $product['cp_price'])); } // Delete order from cart $this->cart->removeCart(); // Add orderId to session $this->session->set('order_id', $orderId); } }
/** * Place an order * @return void * @todo: lets send a receipt email here */ public function placeOrder() { $cartProducts = $this->cart->getAllCartProducts(); $orderId = $this->createOrderRecord(); foreach ($cartProducts as $cartProduct) { $this->db->insert('aca_order_product', array('order_id' => $orderId, 'product_id' => $cartProduct['product_id'], 'quantity' => $cartProduct['qty'], 'price' => $cartProduct['price'])); } // Clear the existing cart $this->cart->nixCart(); $this->session->set('completed_order_id', $orderId); }
/** * Place an order * @return void */ public function placeOrder() { $orderProducts = $this->cart->getAllCartProducts(); $orderId = $this->createOrderRecord(); //$orderId = $this->cart->getCartId(); //use aca_order_product and aca_order tables in DB foreach ($orderProducts as $orderProduct) { $this->db->insert('aca_order_product', array('order_id' => $orderId, 'product_id' => $orderProduct['product_id'], 'quantity' => $orderProduct['qty'], 'price' => $orderProduct['unit_price'])); } $this->cart->nixCart(); $this->session->set('completed_order_id', $orderId); $this->session->save(); }