コード例 #1
0
 /**
  * Change number of specific product (amount) in the cart
  *
  * @param Request $request
  * @param $productId
  * @return \Illuminate\Http\RedirectResponse
  */
 public function changeAmount(CartRequest $request, $productId)
 {
     $amount = $request->input('product-amount');
     $products = $request->session()->pull('products');
     $products = $this->setArrayMemberCount($productId, $products, $amount);
     $request->session()->put('products', $products);
     return redirect()->back();
 }
コード例 #2
0
 public function update(CartRequest $request)
 {
     $product_id = $request->input('product_id');
     $product = Product::find($product_id);
     $vendor = User::find($product->user_id);
     $rowId = $request->input('product_rowid');
     $qty = $request->input('qty');
     if ($qty == 0) {
         Cart::remove($rowId);
     } else {
         Cart::update($rowId, $qty);
     }
     $products = Cart::content();
     if (Cart::count() == 0) {
         session()->flash('flash_message', 'Your cart is empty.');
     } else {
         session()->flash('flash_message', 'Your cart has been updated.');
     }
     return view('cart', compact('products', 'vendor'));
 }
コード例 #3
0
ファイル: CartController.php プロジェクト: kacana/kacana.com
 /**
  * @param CartRequest $request
  */
 public function processCart(CartRequest $request)
 {
     $re = array();
     if (Request::isMethod('post') && $request->all()) {
         //save user
         $user = new User();
         $uid = 0;
         $username = "";
         $email = "";
         $existUser = $user->getUserByEmail($request->get('email'));
         if (!empty($existUser)) {
             $uid = $existUser->id;
             $username = $existUser->name;
             $email = $existUser->email;
         } else {
             $item = array('name' => $request->get('name'), 'email' => $request->get('email'), 'phone' => $request->get('phone'), 'role' => BUYER);
             $createdUser = $user->createItem($item);
             $uid = $createdUser->id;
             $username = $createdUser->name;
             $email = $createdUser->email;
         }
         //save address receive
         $userReceive = new addressReceiveModel();
         $item2 = array('name' => $request->get('name_2'), 'phone' => $request->get('phone_2'), 'street' => $request->get('street'), 'city_id' => $request->get('city_id'), 'ward_id' => $request->get('ward_id'));
         $address = $userReceive->createItem($item2);
         if ($uid != 0 && $address) {
             //create user address
             $userAddress = new UserAddress();
             $option = array('user_id' => $uid, 'address_id' => $address->id);
             $userAddress->createItem($option);
             //create order and order detail
             $order = new Order();
             $orderAtt = array('user_id' => $uid, 'address_id' => $address->id, 'total' => Cart::total(), 'ship' => 0, 'address' => $address->street . ", " . addressWardModel::showName($address->ward_id) . ", " . addressCityModel::showName($address->city_id));
             $createdOrder = $order->createItem($orderAtt);
             $orderDetail = new OrderDetail();
             if ($orderDetail->createItems($createdOrder->id, Cart::content())) {
                 //send email
                 $data = array('username' => $username, 'linkWebsite' => SITE_LINK, 'receiveName' => $address->name, 'receiveAddress' => $createdOrder->address, 'receivePhone' => $address->phone, 'carts' => Cart::content(), 'total' => Cart::total());
                 Cart::destroy();
                 if ($this->sendEmailOrder($email, $username, $data)) {
                     $re = array('status' => 'ok', 'id' => $createdOrder->id);
                 } else {
                     $re = array('status' => 'error', 'message' => 'Bị lỗi trong quá trình gửi mail');
                 }
             }
         }
         echo json_encode($re);
     }
 }
コード例 #4
0
 /**
  * Update the specified resource in storage.
  * update cart 
  * @param  int  $id
  * @return Response
  */
 public function postUpdate(CartRequest $request, $id)
 {
     $data = \Session::get('giohang');
     $data[$id]['qty'] = $request->get('qty');
     $data[$id]['amount'] = $data[$id]['qty'] * $data[$id]['price'] * (100 - $data[$id]['discount']) / 100;
     \Session::put('giohang', $data);
     return redirect('/cart/index');
 }