Ejemplo n.º 1
0
 /**
  * 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();
 }
Ejemplo n.º 2
0
 /**
  * Create a cart record, and return the id if it doesn't exist
  * If it does exist, just return the ID
  * @return int
  * @throws Exception
  */
 public function getCartId()
 {
     //        $db = $this->get('acadb');
     $user_id = $this->session->get('user_id');
     $query = '
     select
         *
     from
         aca_cart
     WHERE
         user_id = :userId';
     $data = $this->db->fetchRow($query, array('userId' => $user_id));
     if (empty($user_id)) {
         throw new Exception('Please login first');
     } else {
         if (empty($data)) {
             $cartId = $this->db->insert('aca_cart', array('user_id' => $user_id));
         } else {
             $cartId = $data['cart_id'];
         }
         $this->session->set('cart_id', $cartId);
         $this->session->save();
         return $cartId;
         //        return $this->getCartId();
     }
 }