コード例 #1
0
 public function create()
 {
     $this->data['css_assets'] = Assets::load('css', ['admin_bootstrap', 'admin_css', 'font-awesome', 'skins', 'ionicons']);
     $this->data['js_assets'] = Assets::load('js', ['jquery', 'admin_js', 'admin_bootstrap-js', 'slimscroll', 'fastclick']);
     $this->data['title'] = 'Product | Create';
     $this->data['category'] = Category::get();
     $this->data['distributor'] = Distributor::get();
     $this->data['array'] = '';
     return view('admin_layout')->with('data', $this->data)->nest('content', 'admin/product_insert', array('data' => $this->data));
 }
コード例 #2
0
ファイル: AdminController.php プロジェクト: adeard/sayourshop
 public function list_product()
 {
     $this->data['css_assets'] = Assets::load('css', ['admin_bootstrap', 'admin_css', 'font-awesome', 'skins', 'dataTables_css']);
     $this->data['js_assets'] = Assets::load('js', ['jquery', 'admin_js', 'admin_bootstrap-js', 'slimscroll', 'fastclick', 'dataTables_js', 'dataTables_bootsjs']);
     $this->data['title'] = 'Product | List';
     $this->data['product'] = Product::where('category_id', 1)->orderBy('created_at', 'DESC')->get();
     $this->data['category'] = Category::get();
     $this->data['distributor'] = Distributor::get();
     return view('admin_layout')->with('data', $this->data)->nest('content', 'admin/product/list_produk', array('data' => $this->data));
 }
コード例 #3
0
 public function delete($id)
 {
     $products = Product::where('distributor_id', $id)->where('status', 'publish')->get();
     if ($products != '') {
         foreach ($products as $product) {
             $order = OrderDetail::where('product_id', $product->id)->where('review', '')->first();
             if ($order != '') {
                 return redirect('master/distributor/list')->with('error', 'Maaf masih terdapat order dari produk distributor yang belum selesai');
             }
         }
     }
     if ($item != '') {
         return redirect('master/distributor/list')->with('error', 'Maaf masih terdapat produk distributor yang aktif. Silahkan non-aktifkan');
     } else {
         Distributor::find($id)->delete();
         return redirect('master/distributor/list');
     }
 }
コード例 #4
0
ファイル: OrderController.php プロジェクト: adeard/sayourshop
 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');
         }
     }
 }