/**
  * Display a listing of carts
  *
  * @return Response
  */
 public function index()
 {
     if (Session::get('cart_id')) {
         $carts = Cart::where('customer_id', Session::get('cart_id'))->get();
         return View::make('carts.index', compact('carts'));
     } else {
         return Redirect::route('landing');
     }
 }
 public function postOrder()
 {
     $member_id = Auth::user()->id;
     $address = Input::get('address');
     $cart_books = Cart::with('Books')->where('member_id', '=', $member_id)->get();
     $cart_total = Cart::with('Books')->where('member_id', '=', $member_id)->sum('total');
     $order = Order::create(['member_id' => $member_id, 'address' => $address, 'total' => $cart_total]);
     foreach ($cart_books as $cart_book) {
         $order->orderItems()->attach($cart_book->book_id, ['amount' => $cart_book->amount, 'price' => $cart_book->books->price, 'total' => $cart_book->books->price * $cart_book->amount]);
         //for other fields
     }
     Cart::where('member_id', '=', $member_id)->delete();
     return Redirect::route('index')->with('message', 'Your order processed successfully..');
 }
Ejemplo n.º 3
0
 public function checkout()
 {
     $query = Cart::where('user_id', Auth::user()->id)->where('checked_out', '0');
     if ($query) {
         if ($query->update(['checked_out' => '1'])) {
             Mail::send('emails.auth.order', array('query' => $query), function ($message) {
                 $message->form("*****@*****.**", "Nexus IT Zone");
                 $message->to(Auth::user()->email, Auth::user()->name)->subject('Nexus Order Process');
             });
             return Redirect::back()->with('event', '<p class="alert alert-success"><span class="glyphicon glyphicon-ok"></span> Thank you. We received your order. Please check your email</p>');
         }
         return Redirect::back()->with('event', '<p class="alert alert-danger"><span class="glyphicon glyphicon-ok"></span> Error occured</p>');
     }
     return Redirect::back()->with('event', '<p class="alert alert-danger"><span class="glyphicon glyphicon-remove"></span> Error occured</p>');
 }
 public function postAddToCart()
 {
     //validation
     $rules = ['amount' => 'required|numeric', 'book' => 'required|numeric|exists:books,id'];
     //inputs, rules
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::route('index')->with('error', 'The book could not be added to your cart');
     }
     $member_id = Auth::user()->id;
     $book_id = Input::get('book');
     $amount = Input::get('amount');
     $book = Book::find($book_id);
     $total = $amount * $book->price;
     //checking existing in the cart
     $count = Cart::where('book_id', '=', $book_id)->where('member_id', '=', $member_id)->count();
     if ($count) {
         return Redirect::route('index')->with('error', 'The book already exists in your cart.');
     }
     Cart::create(['member_id' => $member_id, 'book_id' => $book_id, 'amount' => $amount, 'total' => $total]);
     return Redirect::route('cart');
 }
Ejemplo n.º 5
0
    mw()->ui->module('admin.dashboard.menu', $admin_dashboard_btn);
}
event_bind('mw_edit_product_admin', function ($data) {
    if (isset($data['id'])) {
        if (get_option('shop_disabled', 'website') == 'y') {
            return;
        }
        print '<module type="shop/products/product_options" content-id="' . $data['id'] . '" />';
    }
});
event_bind('module.content.edit.main', function ($data) {
    if (isset($data['id']) and isset($data['content_type']) and $data['content_type'] == 'product') {
        $data['prices'] = mw()->fields_manager->get("field_type=price&for=content&for_id=" . $data['id']);
        if ($data['prices'] == false) {
            $create_price_field = mw()->fields_manager->save("field_value=0&field_type=price&for=content&for_id=" . $data['id']);
            $data['prices'] = mw()->fields_manager->get("field_type=price&for=content&for_id=" . $data['id']);
        }
        $btn = array();
        $btn['title'] = _e("Price", true);
        $btn['html'] = ' <module type="custom_fields" template="shop/products/edit_price" content_id="' . $data['id'] . '" />';
        //   $btn['class'] = 'mw-icon-product';
        mw()->modules->ui('content.edit.title.after', $btn);
    }
});
event_bind('mw.user.login', function ($data) {
    if (is_array($data) and isset($data['old_sid'])) {
        $cur_sid = mw()->user_manager->session_id();
        Cart::where('session_id', $data['old_sid'])->update(array('session_id' => $cur_sid));
        mw()->cache_manager->delete('cart');
    }
});
 public function postOrder($id)
 {
     $token = Input::get('token', '');
     $u_id = Input::get('u_id', 0);
     $p_id = Input::get('product', 0);
     $quantity = Input::get('quantity', 0);
     $shipping_name = Input::get('shipping_name', '');
     $shipping_phone = Input::get('shipping_phone', '');
     $shipping_address = Input::get('shipping_address', '');
     $comment = Input::get('comment', '');
     DB::beginTransaction();
     try {
         $funding = CrowdFunding::find($id);
         $funding->load(['eventItem']);
         $date_end = new DateTime($funding->eventItem->e_end_at);
         $date_start = new DateTime($funding->eventItem->e_start_at);
         $now = new DateTime();
         if ($now > $date_end) {
             throw new Exception("抱歉, 众筹已经结束", 2001);
         }
         if ($now < $date_start) {
             throw new Exception("抱歉, 众筹还未开始, 请耐心等待", 2001);
         }
         if ($funding->c_status != 4) {
             throw new Exception("抱歉, 无效的众筹状态", 2001);
         }
         if ($funding->u_id == $u_id) {
             throw new Exception("您不能认筹自己发起的众筹", 2001);
         }
         $validator = Validator::make(['收货人电话' => (string) $shipping_phone, '收货人姓名' => $shipping_name, '收获地址' => $shipping_address, '产品' => $p_id, '数量' => $quantity], ['收货人电话' => 'required|numeric|digits:11', '收货人姓名' => 'required', '收获地址' => 'required', '产品' => 'required|numeric', '数量' => 'required|numeric']);
         if ($validator->fails()) {
             $msg = $validator->messages();
             throw new Exception($msg->first(), 7001);
         }
         $user = User::chkUserByToken($token, $u_id);
         if (!$user->u_mobile && ($id = 30)) {
             throw new Exception("此众筹需要绑定联系电话,请到[我的-编辑资料]里绑定后进行支持", 2001);
         }
         if ($funding->c_local_only) {
             $funding_owner = User::find($funding->u_id);
             if ($funding_owner->u_school_id != $user->u_school_id) {
                 throw new Exception("该众筹仅限于同校参与", 2001);
             }
         }
         $product = CrowdFundingProduct::find($p_id);
         if ($product->p_price == 0) {
             if ($quantity != 1) {
                 throw new Exception("此类众筹只能认筹一份", 1);
             }
             // check if user has bought
             $chk = Cart::where('u_id', '=', $u_id)->where('c_type', '=', 2)->where('p_id', '=', $p_id)->where('c_status', '>', 0)->first();
             if (!empty($chk)) {
                 throw new Exception("此类众筹每人限认筹一次", 7001);
             }
         }
         // sku need to be calulated before cart generated
         $product->loadProduct($quantity);
         // add cart
         $cart = new Cart();
         $cart->p_id = $p_id;
         $cart->p_name = $product->p_title;
         $cart->u_id = $u_id;
         $cart->b_id = $product->b_id;
         $cart->created_at = Tools::getNow();
         $cart->c_quantity = $quantity;
         $cart->c_price = $product->p_price;
         $cart->c_amount = $product->p_price * $quantity;
         $cart->c_discount = 100;
         $cart->c_price_origin = $product->p_price;
         $cart->c_amount_origin = $product->p_price * $quantity;
         $cart->c_status = 2;
         $cart->c_type = 2;
         $re = $cart->save();
         if (!$re) {
             throw new Exception("提交库存失败", 7006);
         }
         if (!$funding->c_shipping) {
             $shipping_address = '';
         }
         $shipping_name = $shipping_name ? $shipping_name : $user->u_name;
         $shipping_phone = $shipping_phone ? $shipping_phone : $user->u_mobile;
         $date_obj = new DateTime($funding->eventItem->e_start_at);
         $delivery_time_obj = $date_obj->modify('+' . ($funding->c_time + $funding->c_yield_time) . 'days');
         // add order
         $order_group_no = Order::generateOrderGroupNo($u_id);
         $rnd_str = rand(10, 99);
         $order_no = $order_group_no . $cart->b_id . $rnd_str;
         $order = new Order();
         $order->u_id = $u_id;
         $order->b_id = $cart->b_id;
         $order->o_amount_origin = $cart->c_amount_origin;
         $order->o_amount = $cart->c_amount;
         $order->o_shipping_fee = $funding->c_shipping_fee;
         $order->o_shipping_name = $shipping_name;
         $order->o_shipping_phone = $shipping_phone;
         $order->o_shipping_address = $shipping_address;
         $order->o_delivery_time = $delivery_time_obj->format('Y-m-d H:i:s');
         $order->o_shipping = $funding->c_shipping;
         $order->o_comment = $comment;
         $order->o_number = $order_no;
         $order->o_group_number = $order_group_no;
         $o_id = $order->addOrder();
         Cart::bindOrder([$order->o_id => [$cart->c_id]]);
         // change order to finish if price = 0
         if ($order->o_amount == 0) {
             $cart->checkout();
             $order->o_status = Order::$STATUS_FINISHED;
             $order->o_shipping_status = Order::$SHIPPING_STATUS_FINISHED;
             $order->paied_at = Tools::getNow();
             $order->save();
         }
         $data = ['order_no' => $order_group_no];
         $re = Tools::reTrue('提交订单成功', $data);
         DB::commit();
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '提交订单失败:' . $e->getMessage());
         DB::rollback();
     }
     return Response::json($re);
 }
Ejemplo n.º 7
0
 public function delete_cart($params)
 {
     if (is_string($params)) {
         $params = parse_params($params);
     }
     if (isset($params['session_id'])) {
         $id = $params['session_id'];
         \Cart::where('session_id', $id)->delete();
     }
     if (isset($params['order_id'])) {
         $id = $params['order_id'];
         \Cart::where('order_id', $id)->delete();
     }
     $this->app->cache_manager->delete('cart');
     $this->app->cache_manager->delete('cart_orders');
 }
Ejemplo n.º 8
0
 public function social()
 {
     $social_id = Input::get('id');
     if (Auth::check()) {
         $user_id = Auth::user()->id;
         $user = User::find($user_id);
         $user->social_id = $social_id;
         $user->save();
         $store = StoreLocation::where('zipcode', Auth::user()->zipcode)->first();
         if ($store) {
             $store_id = $store->id;
         } else {
             $store_id = 0;
         }
         $cart = Cart::where('user_id')->orderBy('updated_at', 'desc')->first();
         if ($cart) {
             $cart_id = $cart->id;
         } else {
             $cart = new Cart();
             $cart->cart_url = "";
             $cart->user_id = Auth::user()->id;
             $cart->save();
             $cart_id = $cart->id;
             $cart_user = new CartUser();
             $cart_user->cart_id = $cart_id;
             $cart_user->user_id = Auth::user()->id;
             $cart_user->save();
         }
         Session::put('zipcode', Auth::user()->zipcode);
         Session::put('store_id', $store_id);
         Session::put('cart_id', $cart_id);
         return Redirect::to('/user');
     } else {
         $user = User::where('social_id', $social_id)->first();
         if ($user) {
             $already = 'there';
             Auth::login($user);
         } else {
             $already = '';
             $zipcode = Session::get('zipcode');
             if ($zipcode == null) {
                 return Redirect::to("/")->with('message', 'Please Select the Zipcode and proceed');
             } else {
                 $social_id = Input::get('id');
                 $first_name = Input::get('first_name');
                 $last_name = Input::get('last_name');
                 $email = Input::get('email');
                 $user = User::add($first_name, $last_name, '', $email, '', $zipcode, $social_id, '');
             }
         }
         Auth::login($user);
         $store = StoreLocation::where('zipcode', Auth::user()->zipcode)->first();
         if ($store) {
             $store_id = $store->id;
         } else {
             $store_id = 0;
         }
         $cart = Cart::where('user_id')->orderBy('updated_at', 'desc')->first();
         if ($cart) {
             $cart_id = $cart->id;
         } else {
             $cart = new Cart();
             $cart->cart_url = "";
             $cart->user_id = Auth::user()->id;
             $cart->save();
             $cart_id = $cart->id;
             $cart_user = new CartUser();
             $cart_user->cart_id = $cart_id;
             $cart_user->user_id = Auth::user()->id;
             $cart_user->save();
         }
         // dd(Session::get('zipcode'));
         Session::put('zipcode', Auth::user()->zipcode);
         Session::put('store_id', $store_id);
         Session::put('cart_id', $cart_id);
         if ($already == 'there') {
             return Redirect::to("/store/{$store_id}");
         } else {
             return Redirect::to("/login");
         }
     }
     $response = Response::json($response_array, $response_code);
     return $response;
 }
 public function injectCart()
 {
     // Session::forget('cart_id');
     if (Session::get('cart_id')) {
         $customer_id = Session::get('cart_id');
     } else {
         $customer_id = Str::random(50);
         Session::put('cart_id', $customer_id);
     }
     // $item = Input::get('product_id');
     $size = Input::get('size');
     $item = Input::get('product');
     if (Cart::where('customer_id', $customer_id)->where('item', $item)->where('size', $size)->pluck('quantity')) {
         $quantit = Cart::where('customer_id', $customer_id)->where('item', $item)->where('size', $size)->pluck('quantity');
         $cart = Cart::where('customer_id', $customer_id)->where('item', $item)->where('size', $size)->first();
         $cart->customer_id = $customer_id;
         $cart->item = $item;
         $cart->size = $size;
         $cart->quantity = $quantit + 1;
         $cart->save();
     } else {
         $cart = new Cart();
         $cart->customer_id = $customer_id;
         $cart->size = $size;
         $cart->item = $item;
         $cart->quantity = 1;
         $cart->save();
         return 'sucksess';
     }
 }
Ejemplo n.º 10
0
 public function payFailed()
 {
     $order_no = Input::get('order_no', '');
     $u_id = Input::get('u_id', '');
     $token = Input::get('token', '');
     DB::beginTransaction();
     try {
         $orders = Order::getGroupOrdersByNo($order_no);
         foreach ($orders as $key => $order) {
             $carts = Cart::where('o_id', '=', $order->o_id)->get();
             foreach ($carts as $cart) {
                 $cart->delete();
             }
             $order->delete();
         }
         $re = Tools::reTrue('取消成功');
         DB::commit();
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '取消失败:' . $e->getMessage());
         DB::rollback();
     }
     return Response::json($re);
 }
Ejemplo n.º 11
0
 /**
  * Show the form for creating a new cart
  *
  * @return Response
  */
 public function create()
 {
     $customer_id = Input::get('customer_id');
     $customer = Customer::find($customer_id);
     $cart = Cart::where('customer_id', $customer_id)->get();
     return View::make('admin.carts.create')->with('customer', $customer)->with('cart', $cart);
 }
Ejemplo n.º 12
0
 public function getIndex()
 {
     $query = Cart::where('status', '0')->paginate(10);
     return View::make('Dashboard.Orders.All', ['query' => $query]);
 }
Ejemplo n.º 13
0
 /**
  * Admin home page
  */
 public function home()
 {
     $query = Cart::where('status', '0')->take(10)->orderBy("created_at", "DESC");
     return View::make('Dashboard.Index', ['query' => $query]);
 }
Ejemplo n.º 14
0
					<div class="col-sm-8">
						<div class="shop-menu pull-right">
							<ul class="nav navbar-nav">
								@if (Auth::user() && Auth::user()->type == "member")
									<li>
										<a href="{{ url("account") }}" class="{{ Request::path() == 'account' ? 'active' : '' }}">
											<?php 
$picture = User::select('name')->where('id', '=', Auth::id());
?>
											<i class="fa fa-user"></i> {{ $picture->first()->name }}
										</a>
									</li>
									<li><a href="#"><i class="fa fa-star"></i> Wishlist</a></li>
									<li><a href="{{ url("checkout") }}"><i class="fa fa-crosshairs"></i> Checkout</a></li>
									<li class="{{ Request::path() == 'cart' ? 'active' : '' }}"><a href="{{ url("cart") }}" class="{{ Request::path() == 'cart' ? 'active' : '' }}"><i class="fa fa-shopping-cart"></i> Cart (<?php 
$cart = Cart::where('user_id', '=', Auth::user()->id)->where('checked_out', '0')->get();
echo count($cart);
?>
)</a></li>
									<li><a href="{{ url("logout") }}"><i class="fa fa-lock"></i> Logout</a></li>
								@elseif(Auth::user() && Auth::user()->type == "admin")
									<li>
										<a href="{{ url("account") }}" class="{{ Request::path() == 'account' ? 'active' : '' }}">
											<?php 
$picture = User::select('name')->where('id', '=', Auth::id());
?>
											<i class="fa fa-user"></i> {{ $picture->first()->name }}
										</a>
									</li>
									<li><a href="{{ url("logout") }}"><i class="fa fa-lock"></i> Logout</a></li>
								@else
Ejemplo n.º 15
0
 function empty_cart()
 {
     $sid = mw()->user_manager->session_id();
     $cart_table = $this->tables['cart'];
     \Cart::where('order_completed', 0)->where('session_id', $sid)->delete();
     $this->no_cache = true;
     $this->app->cache_manager->delete('cart');
     $this->app->cache_manager->delete('cart_orders/global');
 }
Ejemplo n.º 16
0
                                {{ Form::open(['url' => '/cart/delete']) }}
                                    <td>
                                        {{ Form::hidden('id', $row->id) }}
                                        <button type="submit" class="cart_quantity_delete"><i class="fa fa-times"></i></button>
                                    </td>
                                {{ Form::close() }}
                            </tr>
                        @endforeach
                    @endif
                </tbody>
            </table>

            <div class="pull-right">
                {{-- Show total price --}}
                @if (count($query) == 0)
                @else
                    <?php 
$price = Cart::where('user_id', Auth::user()->id)->sum('price');
?>
                    <p><strong>Total</strong> - ৳ {{ $price }}</p>
                    <p>
                        <a href="cart/cancel" class="btn btn-warning">Cancel</a>
                        <a href="cart/checkout" class="btn btn-success"><span class="glyphicon glyphicon-ok"></span> Check out</a>
                    </p>
                @endif
            </div>
        </div>
    </div>
</section> <!--/#cart_items-->

@stop
Ejemplo n.º 17
0
 public static function sumIncome($from = null, $to = null, $b_id = null, $u_id = null, $owner_id = null)
 {
     $query = Cart::where('c_status', '=', 3);
     if ($from) {
         $query = $query->where('checkout_at', '>', $from);
     }
     if ($to) {
         $query = $query->where('checkout_at', '<', $to);
     }
     if ($b_id) {
         $query = $query->where('b_id', '=', $b_id);
     }
     if ($u_id) {
         $query = $query->where('u_id', '=', $u_id);
     }
     $amount = $query->sum('c_amount');
     return $amount;
 }
Ejemplo n.º 18
0
 public function postCart()
 {
     $token = Input::get('token', '');
     $u_id = Input::get('u_id', 0);
     $p_id = Input::get('product');
     $b_id = Input::get('booth');
     $quantity = Input::get('quantity');
     try {
         $user = User::chkUserByToken($token, $u_id);
         $cart = Cart::where('p_id', '=', $p_id)->where('u_id', '=', $u_id)->where('c_status', '=', 1)->first();
         // add new when there is not any cart before
         if (empty($cart->c_id)) {
             $cart = new Cart();
             $cart->b_id = $b_id;
             $cart->u_id = $u_id;
             $cart->p_id = $p_id;
             $cart->c_quantity = $quantity;
             $cart->c_type = 1;
             $cart->addCart();
             // cumilate quantity
         } else {
             $quantityOri = $cart->c_quantity;
             $cart->c_quantity += $quantity;
             $cart->updateCart($quantityOri);
         }
         $re = Tools::reTrue('添加购物车成功');
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), $e->getMessage());
     }
     return Response::json($re);
 }