コード例 #1
0
 public function single_shelf()
 {
     $store_id = Request::segment(2);
     $department_id = Request::segment(4);
     $shelf_id = Request::segment(6);
     $base_search_url = web_url() . "/store/" . $store_id . "/department/" . $department_id . "/shelf/" . $shelf_id . "?shelf_id=" . $shelf_id;
     if (Input::has('per_page')) {
         $per_page = Input::get('per_page');
     } else {
         $per_page = 20;
     }
     if (Input::has('page')) {
         $page = Input::get('page');
     } else {
         $page = 0;
     }
     $shelf = Shelf::where('id', $shelf_id)->where('store_id', $store_id)->where('department_id', $department_id)->first();
     if (!$shelf) {
         if (Request::format() == 'html') {
             // Not Found Page
             die;
         } else {
             $response_array = array('success' => 'false', 'error_code' => '402', 'error' => 'Shelf not found in the choosen store');
             $response_code = 200;
             $response = Response::json($response_array, $response_code);
             return $response;
         }
     }
     $shelf_data = $shelf->toArray();
     $shelf_data['products'] = array();
     $query = Product::where('shelf_id', $shelf_id)->where('store_id', $store_id);
     $brands = $query->leftJoin('brands', 'products.brand_id', '=', 'brands.id')->select(DB::raw('distinct brands.*'))->get();
     $query = Product::where('shelf_id', $shelf_id)->where('store_id', $store_id);
     $options = $query->leftJoin('product_tag', 'products.id', '=', 'product_tag.product_id')->Join('options', 'product_tag.option_id', '=', 'options.id')->select(DB::raw('distinct options.*'))->get();
     $query = Product::where('shelf_id', $shelf_id)->where('store_id', $store_id);
     $base_search_url_options = $base_search_url;
     if (Input::has('options')) {
         $option_ids = Input::get('options');
         $query = $query->leftJoin('product_tag', 'products.id', '=', 'product_tag.product_id')->whereIn('product_tag.option_id', Input::get('options'));
         foreach (Input::get('options') as $option) {
             $base_search_url_options .= "&options[]=" . $option;
         }
     } else {
         $option_ids = array();
     }
     $base_search_url_brand = $base_search_url;
     if (Input::has('brand')) {
         $brand_id = Input::get('brand');
         $query = $query->where('brand_id', Input::get('brand'));
         $base_search_url_brand .= "&brand=" . Input::get('brand');
     } else {
         $brand_id = 0;
     }
     if (Input::has('sort_by') && Input::get('sort_by') == 'price') {
         $query = $query->orderBy('price');
     } else {
         $query = $query->orderBy('total_sale', 'desc');
     }
     $products = $query->select('products.*')->distinct()->get();
     foreach ($products as $product) {
         $shelf_product = $product->toarray();
         array_push($shelf_data['products'], $shelf_product);
     }
     $response_array['options'] = $options->toArray();
     $response_array['brands'] = $brands->toArray();
     $response_array['shelf'] = $shelf_data;
     if (Request::format() == 'html' && $page == 0) {
         return View::make('shelf')->with('data', $response_array)->with('store', $this->store)->with('departments', $this->departments)->with('zipcode', $this->zipcode)->with('city', $this->city)->with('stores', $this->stores)->with('q', Input::get('q'))->with('base_search_url_brand', $base_search_url_brand)->with('base_search_url_options', $base_search_url_options)->with('option_ids', $option_ids)->with('brand_id', $brand_id);
     } else {
         $response_array['success'] = 'true';
         $response_code = 200;
         $response = Response::json($response_array, $response_code);
         return $response;
     }
 }
コード例 #2
0
 public function get_shelf_ajax()
 {
     $department_id = Input::get('department_id');
     $shelves = Shelf::where('department_id', $department_id)->get()->toArray();
     $response_code = 200;
     $response = Response::json($shelves, $response_code);
     return $response;
 }