Beispiel #1
0
 public static function storeOrderCart($orderId)
 {
     $cart = Cart::instance('shopping')->content();
     foreach ($cart as $product) {
         $newRecord = new OrderProducts();
         if (Auth::check()) {
             $newRecord->user_id = Auth::user()->id;
         }
         $newRecord->order_id = $orderId;
         $newRecord->product_id = $product->id;
         $newRecord->current_price = $product->price;
         $newRecord->count = $product->qty;
         $newRecord->discount = $product->options->discount;
         $newRecord->discount_type = $product->options->discount_type;
         if ($product->options->size) {
             $newRecord->size_id = $product->options->size->id;
         }
         if ($product->options->color) {
             $newRecord->color_id = $product->options->color->id;
         }
         $newRecord->save();
     }
     Cart::instance('shopping')->destroy();
     return ['error' => ['type' => 'none'], 'success' => 'Your order was successfully stored'];
 }
Beispiel #2
0
 public static function storeOrder($data, $isFirm = false)
 {
     $validator = Validator::make($data, Order::rules($isFirm), Order::messages($isFirm));
     if ($validator->fails()) {
         return ['error' => ['type' => 'validation', 'messages' => $validator]];
     }
     $order = new Order();
     if ($isFirm) {
         $order->firm = $data['firm'];
         $order->kvk = $data['kvk'];
         $order->btw = $data['btw'];
     }
     $order->first_name = $data['first_name'];
     $order->last_name = $data['last_name'];
     $order->email = $data['email'];
     $order->phone = $data['phone'];
     $order->city = $data['city'];
     $order->address = $data['address'];
     $order->comment = $data['comment'];
     $order->save();
     $cartResponse = OrderProducts::storeOrderCart($order->id);
     return $cartResponse;
 }