Esempio n. 1
0
 function placeOrder($request)
 {
     //@TODO: transaction starts
     //        DB::beginTransaction();
     \Illuminate\Support\Facades\DB::beginTransaction();
     try {
         $order = $this->create($request);
         $orderHasItemsDao = new OrderHasItemsDao();
         $eoahDao = new OrderAddressHistoryDao();
         $eoahDao->create(array('order_id' => $order->id, 'address_id' => $request['address_id']));
         $orderOrderHistoryObj = new OrderHistoryDao();
         foreach ($request['items'] as $value) {
             $orderHasItemsObj = $orderHasItemsDao->create(array('item_id' => $value['_id'], 'order_id' => $order->id, 'quantity' => $value['_quantity']));
             //$orderOrderHistoryObj->addToOrderHistory(array("item_id"=>$value['_id'],'order_id' => $order->id));
         }
         \Illuminate\Support\Facades\DB::commit();
         return $order;
     } catch (\Exception $e) {
         \Illuminate\Support\Facades\DB::rollback();
         //            throw
         print_r($e->getMessage());
         throw new \Exception("Error internal server error", 500);
     }
     // transsaction ends
     //\Illuminate\Support\Facades\Event::fire(new OrderWasMade());
 }
Esempio n. 2
0
 function placeOrder($data)
 {
     //        print_r($data);
     //        die();
     //@TODO: put transaction checkpoint
     //@TODO: put validation rules
     $orderArray = array();
     $orderArray['address_id'] = $data['address_id'];
     $orderArray['updated_by'] = $data['updated_by'];
     $order = $this->create($orderArray);
     // insert into orderHasItems
     $odhiDao = new OrderHasItemsDao();
     $orderHasitemArray = array();
     $orderHasitemArray['order_id'] = $order->id;
     //        print_r($order);
     //        print_r($data);
     //        die();
     foreach ($data['items'] as $val) {
         $orderHasitemArray['item_id'] = $val;
         $odhiDao->create($orderHasitemArray);
     }
     return $order;
     //@TODO: put transaction commit
 }