/** * Index function. Lists items items under specific category * * @return view */ public function index(Request $request, $cat_code = '') { if ($cat_code != '') { //get category info $objCategory = App\CategoryMaster::where('cat_code', $cat_code)->first(); if (null == $objCategory) { abort(404); } //create an object of a pagination class $pagination = new \Pagination(); //set number of records per page $pagination->setRecordsPerPage(18); //set links call method (PHP for simple full callback or JS for javascript function call (in case your fetching data using ajax)) $pagination->setRenderMode('PHP'); //get page number if its been ser in URL if (isset($_GET['page'])) { $page = $_GET['page']; } else { $page = 1; } //set page number $pagination->setPage($page); //get items for the category $itemCount = DB::table('item_master')->join('type_master', 'item_master.item_type', '=', 'type_master.type_id')->join('category_master', 'type_master.category', '=', 'category_master.cat_id')->select('item_master.*')->where('status', 1)->where('category_master.cat_code', $cat_code)->count(); //set number of total records $pagination->setTotalRecords($itemCount); //calculate offset (copy and paste this to your code) $offset = ($page - 1) * $pagination->getRecordsPerPage(); //get items for the category $objItems = DB::table('item_master')->join('type_master', 'item_master.item_type', '=', 'type_master.type_id')->join('category_master', 'type_master.category', '=', 'category_master.cat_id')->select('item_master.*', 'type_master.type_code', 'type_master.name as type_name', 'category_master.name as cat_name', 'category_master.cat_code')->where('status', 1)->where('category_master.cat_code', $cat_code)->skip($offset)->take($pagination->getRecordsPerPage())->get(); return view('category_items', compact('objCategory', 'objItems', 'pagination')); } else { abort(404); } }
/** * Landing function * * @return view */ public function index() { //fetch all the categories $objCategory = App\CategoryMaster::all(); //fetch all the item types $objType = App\TypeMaster::all(); //get category id versus category name array $arrCetegory_id_obj = getKeyValueArray('cat_id', 'name', $objCategory, 'object', true); $arrType_id_obj = getKeyValueArray('type_id', 'name', $objType, 'object', true); foreach ($objCategory as $key => $category) { $arrItemCategoryWise[$category->cat_id] = DB::table('item_master')->join('type_master', 'item_master.item_type', '=', 'type_master.type_id')->join('category_master', 'type_master.category', '=', 'category_master.cat_id')->select('item_master.*', 'type_master.type_code', 'type_master.name as type_name', 'category_master.name as cat_name', 'category_master.cat_code')->where('status', 1)->where('category_master.cat_id', $category->cat_id)->limit(4)->get(); $arrItemCategoryWise_featured[$category->cat_id] = DB::table('item_master')->join('type_master', 'item_master.item_type', '=', 'type_master.type_id')->join('category_master', 'type_master.category', '=', 'category_master.cat_id')->select('item_master.*', 'type_master.type_code', 'type_master.name as type_name', 'category_master.name as cat_name', 'category_master.cat_code')->where('status', 1)->where('category_master.cat_id', $category->cat_id)->where('item_master.featured', 1)->limit(4)->get(); } return view('home', compact('arrItemCategoryWise_featured', 'objCategory', 'objType', 'arrCetegory_id_obj', 'arrType_id_obj', 'arrItemCategoryWise')); }
public function index(Request $request, $item_id = '') { if ($item_id != '') { $objItem = App\ItemMaster::where('item_id', $item_id)->where('status', 1)->first(); if (null != $objItem) { //fetch all the categories $objCategory = App\CategoryMaster::all(); //fetch all the item types $objType = App\TypeMaster::all(); //get category id versus category name array $arrCetegory_id_obj = getKeyValueArray('cat_id', 'name', $objCategory, 'object', true); $arrType_id_obj = getKeyValueArray('type_id', 'name', $objType, 'object', true); //get coupon information if any $objCouponMaster = DB::table('coupon_master')->join('coupon_type_master', 'coupon_type_master.coupon_id', '=', 'coupon_master.coupon_id')->where('coupon_master.status', 1)->where('coupon_type_master.type_id', $objItem->item_type)->select('coupon_master.*')->get(); $size = null; $message = ''; $show_size_chart = false; if ($objItem->qty == null) { $show_size_chart = true; } if ($show_size_chart == true) { //get item sizes $objSizes = DB::table('item_size_master')->where('item_id', $objItem->item_id)->join('size_master', 'size_master.size_id', '=', 'item_size_master.size_id')->select('item_size_master.*', 'size_master.*')->get(); $arrSize_id_size_code = getKeyValueArray('size_id', 'size_code', $objSizes, 'object', false); } //get total available quantity $total_available_qty = 0; if ($show_size_chart) { foreach ($objSizes as $key => $value) { $total_available_qty = $total_available_qty + $value->qty; } } else { if ($objItem->qty != null) { $total_available_qty = $objItem->qty; } } //add to cart if ($request->isMethod('post')) { //check size is valid if ($show_size_chart == true) { $size = filter_form_input($request->input('size', '')); $size_valid = false; foreach ($objSizes as $key => $value) { if ($value->qty > 0 && $value->size_code == $size) { $size_valid = true; } } if (!$size_valid) { $message[] = 'Plese select size first.'; } } $qty = filter_form_input($request->input('qty', '')); if ($message == '') { if ($qty != '' && is_numeric($qty) && $qty <= $total_available_qty) { if ($this->user_session->is_logged_in == true) { $user_id = $this->user_session->user_id; } else { $user_id = null; } if ($this->user_session->is_logged_in) { $check_if_already_added = App\CartMaster::where(function ($query) { $query->where('user_id', (int) $this->user_session->user_id)->orWhere('session_id', session_id()); })->where('item_id', (int) $objItem->item_id)->first(); } else { $check_if_already_added = App\CartMaster::where('session_id', session_id())->where('item_id', (int) $objItem->item_id)->first(); } if (null == $check_if_already_added) { //add to cart DB::connection('mongodb')->table('cart')->insert(['item_id' => (int) $objItem->item_id, 'user_id' => (int) $user_id, 'session_id' => session_id(), 'qty' => (int) $qty, 'size' => $size, 'price' => $objItem->price, 'coupon_added' => 0]); return redirect()->route('cart'); } else { $message[] = 'You already have added this item to your cart.'; } } else { $message[] = 'Oops! the selected quantity is not available. Plese select lesser quantity.'; } } } //other product images $objProductImages = array(); if (is_array($message)) { $temp = ''; foreach ($message as $value) { $temp = $temp . $value . '<br>'; } $message = $temp; } return view('product.product', compact('objCouponMaster', 'total_available_qty', 'message', 'show_size_chart', 'objSizes', 'objProductImages', 'objItem', 'objCategory', 'objType', 'arrCetegory_id_obj', 'arrType_id_obj')); } else { abort(404); } } else { abort(404); } }