Esempio n. 1
0
 public function addItem($productId)
 {
     $cart = Cart::where('user_id', Auth::user()->id)->first();
     if (!$cart) {
         $cart = new Cart();
         $cart->user_id = Auth::user()->id;
         $cart->save();
     }
     $cartItem = new Cartitem();
     $cartItem->product_id = $productId;
     $cartItem->cart_id = $cart->id;
     $cartItem->save();
     return redirect('/cart');
 }
Esempio n. 2
0
 public function addItem(Request $request, $productId)
 {
     #check service
     $product = Product::find($productId);
     if (!$product) {
         return redirect()->route("home")->with("error", "No product select");
     }
     $qty = $request->get("qty", 0);
     $user = Sentinel::getUser();
     $cart = $this->_createCart();
     $this->billing($cart, $request);
     $cartItem = new Cartitem();
     $cartItem->product_id = $productId;
     $cartItem->cart_id = $cart->id;
     $cartItem->quantity = $qty;
     $cartItem->track_num = $request->get('track_num', '');
     $cartItem->carrier = $request->get('carrier', '');
     $cartItem->unit_price = $product->price;
     $cartItem->save();
     for ($i = 0; $i < $qty; $i++) {
         if (!$request->has("passenger_id-" . $i)) {
             $birthdate = $request->get("year-dob-" . $i) . '-' . $request->get("month-dob-" . $i) . '-' . $request->get("day-dob-" . $i);
             $passport_expirate = $request->get("year-passportExp-" . $i) . '-' . $request->get("month-passportExp-" . $i) . '-' . $request->get("day-passportExp-" . $i);
             $passenger = Passenger::create(['first_name' => $request->get("fname-" . $i), 'last_name' => $request->get("lname-" . $i), 'gender' => $request->get("gender-" . $i), 'birthdate' => $birthdate, 'passport_num' => $request->get("passport-" . $i), 'passport_expirate' => $passport_expirate]);
         }
         $passenger->cartitem()->attach($cartItem);
     }
     return redirect('/cart');
 }
Esempio n. 3
0
 function save($object = '', $related_field = '')
 {
     if (!$this->exists() || empty($this->code)) {
         $o = new Cartitem();
         $o->select_max('position');
         $o->get();
         if (count($o->all) != 0) {
             $max = $o->position + 1;
             $this->position = $max;
         } else {
             $this->postion = 1;
         }
         $position = (string) $this->position;
         $l = 6 - strlen($position);
         $st = "";
         for ($i = 0; $i < $l; $i++) {
             $st .= "0";
         }
         $position = $st . $position;
         $this->code = $position;
     }
     return parent::save($object, $related_field);
 }
Esempio n. 4
0
 function edit($id)
 {
     $cart = new Cartitem($id);
     if (!$cart->exists()) {
         show_404();
     }
     $cartDetail = $cart->cartdetail;
     if ($_SERVER['REQUEST_METHOD'] == "POST") {
         $cart->status = $this->input->post('cartStatus');
         $cart->description = $this->input->post('description');
         $cart->dateDeliver = $this->input->post('dateDeliver');
         $cart->prePaid = $this->input->post('prePaid');
         $cart->taxInfo = $this->input->post('taxInfo');
         $cart->linkOnline = $this->input->post('linkOnline');
         $cart->total = $this->input->post('hiTotal');
         $cart->shipType = $this->input->post('deliverMethod');
         $cart->paymentType = $this->input->post('payment');
         $cart->deliverStore_id = $this->input->post('branchReceive');
         $cart->paymentStore_id = $this->input->post('branchPayment');
         $cart->shipName = $this->input->post('info_name');
         $cart->shipEmail = $this->input->post('info_email');
         $cart->shipPhone = $this->input->post('info_phone');
         $cart->shipDescription = $this->input->post('info_description');
         $cart->shipAddress = $this->input->post('info_address');
         $cart->save();
         foreach ($cartDetail as $row) {
             $row->status = $this->input->post('cartDetailStatus_' . $row->id);
             $row->quantity = $this->input->post('cartDetailQuantity_' . $row->id);
             $row->inBox = $this->input->post('cartDetailInbox_' . $row->id);
             $row->price = $this->input->post('cartDetailPrice_' . $row->id);
             $row->save();
             $row->clear();
         }
         redirect('admin/carts/edit/' . $id);
     }
     $store = new store();
     $store->order_by('id', 'asc');
     $store->get_iterated();
     $dis['store'] = $store;
     $dis['menu_active'] = 'Giỏ hàng';
     $dis['cartdetail'] = $cartDetail;
     $dis['object'] = $cart;
     $dis['cart'] = $cart;
     $dis['title'] = "Chi tiết đơn hàng";
     $dis['base_url'] = base_url();
     $dis['view'] = 'cart/edit';
     $dis['nav_menu'] = array(array("type" => "back", "text" => "Back", "link" => "{$this->admin_url}carts/list_all/", "onclick" => ""));
     $this->viewadmin($dis);
 }
Esempio n. 5
0
 function sendMailCustomerService($id)
 {
     $cart = new Cartitem($id);
     if (!$cart->exists()) {
         show_404();
     }
     $cartDetail = $cart->cartdetail;
     $dis['menu_active'] = 'Giỏ hàng';
     $dis['cartdetail'] = $cartDetail;
     $dis['object'] = $cart;
     $dis['cart'] = $cart;
     $dis['title'] = "Xem trước email cho đơn hàng " . $cart->code;
     $dis['base_url'] = base_url();
     $dis['view'] = 'cart/emailPreview';
     $emailContent = $this->load->view('admin/cart/emailPreviewCustomerService', $dis, TRUE);
     $emailSubject = "didongviet.vn - Có đơn đặt hàng mới từ " . $cart->customer->name . " vào lúc " . date("d-m-Y h:i");
     //load email customer service
     $customerServiceEmail = getconfigkey('customerServiceEmail');
     if (trim($customerServiceEmail) != "") {
         $this->_send_email("myemail", $emailSubject, $emailContent, $customerServiceEmail);
     }
 }