/**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     if ($request->get('customer_name') == null) {
         return response()->json(['response_order_message' => 'fail', 'response_order_message_detail' => 'Customer name is required']);
     }
     $customer = Customer::where('name', '=', $request->get('customer_name'))->first();
     if ($customer == null) {
         $customer = new Customer();
         $customer->name = $request->get('customer_name');
         $customer->slug = str_slug($customer->name);
         $customer->phone_number = $request->get('customer_phone_number');
         $customer->email = $request->get('customer_email');
         $customer->save();
         $customerAddress = new CustomerAddress();
         $customerAddress->line1 = $request->get('line1');
         $customerAddress->line2 = $request->get('line2');
         $customerAddress->district = $request->get('district');
         $customerAddress->province = $request->get('province');
         $customerAddress->post_code = $request->get('post_code');
         $customerAddress->customer_id = $customer->id;
         $customerAddress->save();
     }
     $order = new Order();
     $order->customer_id = $customer->id;
     $order->status = 0;
     $order->save();
     $orderDetail = new OrderDetail();
     $orderDetail->order_id = $order->id;
     $orderDetail->product_id = $request->get('product_id');
     $orderDetail->amount = $request->get('amount');
     $orderDetail->total_price = Product::findOrNew($orderDetail->product_id)->price * $orderDetail->amount;
     $orderDetail->save();
     return $order->id;
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $validator = Validator::make($request->all(), ['customer_name' => 'required', 'customer_email' => 'required', 'customer_phone_number' => 'required', 'line1' => 'required', 'district' => 'required', 'province' => 'required', 'post_code' => 'required', 'product_id' => 'required', 'product_name' => 'required', 'amount' => 'required|integer']);
     if ($validator->fails()) {
         return back()->withErrors($validator)->withInput();
     }
     $order = new Order();
     $order->server_order_id = 1;
     $order->product_id = $request->get('product_id');
     $order->product_name = $request->get('product_name');
     $order->product_amount = $request->get('amount');
     $order->status = 0;
     $order->is_paid = 0;
     $order->save();
     $data = array('order_id' => $order->id, 'customer_name' => $request->get('customer_name'), 'customer_email' => $request->get('customer_email'), 'customer_phone_number' => $request->get('customer_phone_number'), 'line1' => $request->get('line1'), 'district' => $request->get('district'), 'province' => $request->get('province'), 'post_code' => $request->get('post_code'), 'product_id' => $request->get('product_id'), 'product_name' => $request->get('product_name'), 'amount' => $request->get('amount'));
     $data_string = json_encode($data);
     $url = curl_init('http://localhost:8000/api/order/placeorder');
     curl_setopt($url, CURLOPT_CUSTOMREQUEST, "POST");
     curl_setopt($url, CURLOPT_POSTFIELDS, $data_string);
     curl_setopt($url, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($url, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($data_string)));
     $result = curl_exec($url);
     $this->getBackOrderId($result, $order->id);
     Session::flash('flash_message', $result);
     return redirect('/order');
 }
Example #3
0
 /**
  * @param Order $order
  * @param PaymentOperation $operation
  * @param mixed $transactionType
  */
 protected function processPaymentOperation($order, $operation, $transactionType)
 {
     $this->pixie->dispatcher->dispatch(Events::PAYMENT_OPERATION_SUCCEEDED, new PaymentOperationSucceededEvent($order->payment, $operation, $this->request));
     if ($transactionType == PaymentOperation::TR_TYPE_IMMEDIATE_PAYMENT) {
         if ($order->payment->isPayable()) {
             $order->payment->status = PaymentModel::STATUS_PAYED;
             $order->payment->save();
             $this->pixie->dispatcher->dispatch(Events::PAYMENT_PAYED, new PaymentPayedEvent($order->payment));
         }
         if ($order->isPayable()) {
             $order->status = Order::STATUS_PROCESSING;
             $order->save();
             $this->pixie->dispatcher->dispatch(Events::ORDER_STATUS_CHANGED, new OrderStatusChangedEvent($order, $order->status));
             $this->pixie->dispatcher->dispatch(Events::ORDER_PAYED, new OrderPayedEvent($order, $order->payment));
         }
         $this->redirect('/checkout/order/' . $order->uid);
     } else {
         if ($transactionType == PaymentOperation::TR_TYPE_REFUND) {
             if ($order->payment->isRefundable()) {
                 $order->payment->status = PaymentModel::STATUS_REFUNDED;
                 $order->payment->save();
                 $this->pixie->dispatcher->dispatch(Events::PAYMENT_REFUNDED, new PaymentRefundedEvent($order->payment));
             }
             if ($order->isRefundable()) {
                 $order->status = Order::STATUS_REFUNDED;
                 $order->save();
                 $this->pixie->dispatcher->dispatch(Events::ORDER_STATUS_CHANGED, new OrderStatusChangedEvent($order, $order->status));
                 $this->pixie->dispatcher->dispatch(Events::ORDER_REFUNDED, new OrderRefundedEvent($order, $order->payment));
             }
             $this->redirect('/account/orders/' . $order->uid);
         }
     }
 }
Example #4
0
 public function orderCreate(Request $request)
 {
     $validator = Validator::make($request->all(), ['customer_id' => 'required|exists:customers,id', 'product_list' => 'required']);
     if ($validator->fails()) {
         return response()->json(['success' => false, 'error_code' => ErrorConstants::CUSTOMER_ORDER_CREATE_VALIDATOR_FAILS, 'error_message' => $validator->errors()->getMessages()]);
     }
     $customer_id = $request->input('customer_id');
     $product_list = $request->input('product_list');
     $order = new Order();
     $order->order_state_id = 1;
     $order->customer_id = $customer_id;
     $order->order_date = Carbon::today();
     $order->order_price = 0;
     $order->save();
     $total_price = 0;
     foreach ($product_list as $product) {
         $stored_product = Product::find($product['product_id']);
         $order_item = new OrderItem();
         $order_item->order_id = $order->id;
         $order_item->product_id = $stored_product->id;
         $order_item->order_item_state_id = 1;
         $order_item->count = $product['amount'];
         $order_item->price = $product['amount'] * $stored_product->price;
         $order_item->save();
         $total_price += $order_item->price;
     }
     $order->order_price = $total_price;
     $order->save();
     return response()->json(['success' => true]);
 }
Example #5
0
 protected function addOrder($price, $orderBase)
 {
     $order = new Order($this->pixie);
     $order->amount = $price;
     $order->created_at = date('Y-m-d H:i:s');
     $order->customer_email = '*****@*****.**';
     $order->customer_firstname = 'Николай';
     $order->customer_id = 1;
     $order->customer_lastname = 'Червяков';
     $order->payment_method = 'credit_card';
     $order->shipping_method = 'post';
     $order->status = Order::STATUS_WAITING_PAYMENT;
     $order->uid = $orderBase + $price * 10;
     $order->updated_at = date('Y-m-d H:i:s');
     $order->save();
     $orderItem = new OrderItems($this->pixie);
     $orderItem->product_id = 22;
     $orderItem->order_id = $order->id();
     $orderItem->price = 38;
     $orderItem->name = "Запасной ремень All Terrain";
     $orderItem->created_at = date('Y-m-d H:i:s');
     $orderItem->updated_at = date('Y-m-d H:i:s');
     $orderItem->qty = 1;
     $orderItem->save();
     return $order;
 }