Exemplo n.º 1
0
 public function del_wishlist(Request $request)
 {
     $product = Product::where('id', $request->product_id)->where('status', 'publish')->first();
     $user = Sentinel::getUser();
     $wishlist = UserMeta::where('meta_key', 'wishlist')->where('user_id', $user->id)->first();
     $wish = unserialize($wishlist->meta_value);
     foreach ($wish as $value) {
         if ($value == $product->slug) {
             $wish = array_diff($wish, array($product->slug));
         }
     }
     $new = array_values($wish);
     if (count($new) == 0) {
         $delete = UserMeta::where('meta_key', 'wishlist')->where('user_id', $user->id)->delete();
     } else {
         $wishlist->meta_value = serialize($new);
         $wishlist->save();
     }
 }
Exemplo n.º 2
0
 public function address_content(Request $request)
 {
     $usermeta = UserMeta::where('user_id', Sentinel::getUser()->id)->where('meta_key', 'address')->first();
     $address = unserialize($usermeta->meta_value);
     $this->data['address'] = $address[$request->id];
     $this->data['province'] = Province::where('id', $this->data['address']['provinsi'])->first();
     $this->data['district'] = District::where('id', $this->data['address']['kecamatan'])->first();
     $this->data['city'] = City::where('id', $this->data['address']['kota'])->first();
     $this->data['weight'] = $request->weight;
     $costs = app('App\\Http\\Controllers\\OrderController')->get_cost($this->data['address']['kota']);
     $cost = json_decode($costs);
     $this->data['cost_data'] = serialize($cost->rajaongkir->results[0]->costs);
     return view('address_content')->with('data', $this->data);
 }
Exemplo n.º 3
0
 public function checkout(Request $request)
 {
     $user = Sentinel::getUser();
     $order = new Order();
     $order->user_id = $user->id;
     $order->order_status = 'Menunggu Pembayaran';
     foreach (Cart::content() as $key) {
         $product = Product::where('id', $key->id)->first();
         $distributor = Distributor::where('id', $product->distributor_id)->first();
         $unserialize = unserialize($product->properties);
         $color = $key->options[1];
         $size = $key->options[0];
         $stock = $unserialize[$color][$size];
         if ($key->qty > $stock) {
             return redirect('keranjang')->with('fail', 'Stock Produk <b>' . $key->name . '</b> yang Anda pesan tersisa <b>' . $stock . '</b>');
         }
         if ($distributor == '') {
             return redirect('keranjang')->with('fail', 'Maaf produk <b>' . $key->name . '</b> telah habis');
         }
         if ($product->status != 'publish') {
             return redirect('keranjang')->with('fail', 'Maaf produk <b>' . $key->name . '</b> telah habis');
         }
     }
     if (is_numeric($request->address_check)) {
         $meta = UserMeta::where('user_id', $user->id)->where('meta_key', 'address')->first();
         $unserialize = unserialize($meta->meta_value);
         $address = $unserialize[$request->address_check];
         $order->order_name = $address['nama'];
         $order->order_phone = $address['telepon'];
         $order->order_address = $address['alamat'];
         $order->province_id = $address['provinsi'];
         $order->city_id = $address['kota'];
         $order->district_id = $address['kecamatan'];
         $order->courier = $request->courier_check;
         $order->shipping_price = $request->shipping_price;
         $order->email = $user->email;
         if ($request->coupon_code) {
             $order->discount_code = $request->coupon_code;
             $order->total_discount = $request->discount;
             $order->total_price = Cart::total() + $request->shipping_price - $request->discount;
         } else {
             $order->total_price = $request->cart_total + $request->shipping_price;
         }
         $order->save();
         $insert_id = $order->id;
         $order = Order::find($insert_id);
         foreach (Cart::content() as $key) {
             $product = Product::where('id', $key->id)->first();
             $result = $product->weight * $key->qty;
             $rowid = 'properties_' . $key->rowid;
             $orderdetail = new OrderDetail();
             $orderdetail->order_id = $insert_id;
             $orderdetail->properties = $request->{$rowid};
             $orderdetail->product_id = $key->id;
             $orderdetail->quantity = $key->qty;
             $orderdetail->total_price = $key->price * $key->qty;
             $orderdetail->total_weight = $result;
             $orderdetail->save();
         }
         $order->total_weight = $request->weight;
         $order->no_invoice = date('Ymd') . $user->id . $insert_id;
         $order->save();
         //update quantity product
         $orderdetail = OrderDetail::where('order_id', $insert_id)->get();
         foreach ($orderdetail as $detail) {
             $unserialize = unserialize($detail->properties);
             $product = Product::where('id', $detail->product_id)->first();
             $productqty = unserialize($product->properties);
             $productqty[$unserialize[1]][$unserialize[0]] -= $detail->quantity;
             $product->properties = serialize($productqty);
             $product->quantity -= $detail->quantity;
             $product->save();
         }
         return redirect('order_review/' . $insert_id);
     } else {
         $rules = array('name' => 'required', 'province' => 'required', 'city' => 'required', 'district' => 'required', 'address' => 'required', 'phone' => 'required');
         $validator = Validator::make($request->all(), $rules);
         if (!$validator->fails()) {
             $order->order_address = $request->address;
             $order->courier = $request->courier_check_new;
             $order->order_name = $request->name;
             $order->order_phone = $request->phone;
             $order->province_id = $request->province;
             $order->city_id = $request->city;
             $order->district_id = $request->district;
             $order->shipping_price = $request->shipping_price_new;
             $alamat = ['nama' => $request->name, 'telepon' => $request->phone, 'provinsi' => $request->province, 'kota' => $request->city, 'kecamatan' => $request->district, 'alamat' => $request->address];
             if ($user_meta = UserMeta::where('user_id', Sentinel::getUser()->id)->where('meta_key', 'address')->first()) {
                 $unserialize = unserialize($user_meta->meta_value);
                 $sum_array = array_push($unserialize, $alamat);
                 $serialize = serialize($unserialize);
                 $total = UserMeta::where('user_id', $user_meta->user_id)->where('meta_key', 'address')->update(['meta_value' => $serialize]);
             } else {
                 $usermeta = new UserMeta();
                 $usermeta->user_id = Sentinel::getUser()->id;
                 $usermeta->meta_key = "address";
                 $usermeta->meta_value = serialize(array($alamat));
                 $usermeta->save();
             }
             if ($request->coupon_code) {
                 $order->discount_code = $request->coupon_code;
                 $order->total_discount = $request->discount;
                 $order->total_price = Cart::total() + $request->shipping_price_new - $request->discount;
             } else {
                 $order->total_price = $request->cart_total_new + $request->shipping_price_new;
             }
             $order->save();
             $insert_id = $order->id;
             $order = Order::find($insert_id);
             foreach (Cart::content() as $key) {
                 $product = Product::where('id', $key->id)->first();
                 $result = $product->weight * $key->qty;
                 $rowid = 'properties_' . $key->rowid;
                 $orderdetail = new OrderDetail();
                 $orderdetail->order_id = $insert_id;
                 $orderdetail->properties = $request->{$rowid};
                 $orderdetail->product_id = $key->id;
                 $orderdetail->quantity = $key->qty;
                 $orderdetail->total_price = $key->price * $key->qty;
                 $orderdetail->total_weight = $result;
                 $orderdetail->save();
             }
             $order->total_weight = $request->weight_new;
             $order->no_invoice = date('Ymd') . $user->id . $insert_id;
             $order->save();
             //update quantity product
             $orderdetail = OrderDetail::where('order_id', $insert_id)->get();
             foreach ($orderdetail as $detail) {
                 $unserialize = unserialize($detail->properties);
                 $product = Product::where('id', $detail->product_id)->first();
                 $productqty = unserialize($product->properties);
                 $productqty[$unserialize[1]][$unserialize[0]] -= $detail->quantity;
                 $product->properties = serialize($productqty);
                 $product->quantity -= $detail->quantity;
                 $product->save();
             }
             return redirect('order_review/' . $insert_id);
         } else {
             return redirect('keranjang')->with('fail', 'Silahkan isi alamat baru sesuai form yang disediakan');
         }
     }
 }