Пример #1
0
 public function homepage()
 {
     $customCSS = [];
     $customJS = [];
     $response = ['blade_custom_css' => $customCSS, 'blade_custom_js' => $customJS];
     $response['thumbs_path'] = Config::get('system_settings.product_public_path');
     $response['icon_size'] = Config::get('images.sm_icon_size');
     $response['sliders_path'] = Config::get('system_settings.sliders_public_path');
     $products = [];
     /* Load Carousels */
     $response['carousels'] = Model_Main::getCarousels($this->active_module);
     if (!empty($response['carousels']) && is_array($response['carousels'])) {
         foreach ($response['carousels'] as $key => $carousel) {
             if (!empty($carousel['products'])) {
                 $response['carousels'][$key]['products'] = is_array(json_decode(',', $carousel['products'], TRUE)) ? json_decode(',', $carousel['products'], TRUE) : explode(',', $carousel['products']);
                 $products = array_merge($products, $response['carousels'][$key]['products']);
             }
         }
     }
     // Get products data
     $response['products'] = Model_Main::getProducts($products, ['title', 'images', 'sizes']);
     // Send products to response
     $response['products'] = self::prepareProductsForResponse($response['products']);
     unset($products);
     /* Get Sliders */
     $sliders = Model_Main::getSliders('homepage');
     if (!empty($sliders) && is_array($sliders)) {
         foreach ($sliders as $key => $slider) {
             if (!empty($slider['slides']) && !empty($slider['slides_positions'])) {
                 $slider['slides'] = json_decode($slider['slides'], TRUE);
                 $slider['slides_positions'] = json_decode($slider['slides_positions'], TRUE);
                 //Sort by position
                 if (!empty($slider['slides_positions']) && is_array($slider['slides_positions'])) {
                     uasort($slider['slides_positions'], function ($a, $b) {
                         if ($a == $b) {
                             return 0;
                         }
                         return $a < $b ? -1 : 1;
                     });
                 }
                 $response['sliders'][$key] = $slider;
             }
         }
     }
     return Theme::view('homepage.homepage', $response);
 }
Пример #2
0
 /**
  * @param int $id
  * @param $page
  *
  * @return array
  */
 private function loadCategory($id, $page)
 {
     $response = [];
     //Get category
     $category = Model_Main::getCategory($id);
     //If category not found - maybe it's disabled but still gotta stay hidden
     if (empty($category[$id])) {
         abort(404);
     } else {
         $response['category'] = $category[$id];
     }
     $response['all_categories'] = $this->categories['all'];
     $response['breadcrumbs'] = self::generateCategoryBreadcrumbs($category[$id]);
     //SEO
     if (!empty($category[$id]['title'])) {
         View::share('page_title', $category[$id]['title']);
     }
     if (!empty($category[$id]['meta_description'])) {
         View::share('page_meta_description', $category[$id]['meta_description']);
     }
     if (!empty($category[$id]['meta_keywords'])) {
         View::share('page_meta_keywords', $category[$id]['meta_keywords']);
     }
     // Order category products
     if (!empty(Input::get('order_by'))) {
         $order_by = Input::get('order_by');
     } else {
         $order_by = FALSE;
     }
     if (!empty($order_by) && in_array($order_by, ['newest', 'discounted', 'price_asc', 'price_desc'])) {
         $order_by = Input::get('order_by');
         $response['order_by'] = $order_by;
         session(['order_by' => $order_by]);
     } else {
         if (!empty(session('order_by'))) {
             $order_by = session('order_by');
             $response['order_by'] = $order_by;
         }
     }
     //Get products
     $response['products'] = Model_Main::getProductsToCategoryPage($id, $page, $this->system['quantity'], $order_by);
     $products_to_category = Model_Main::getProductsToCategoryId($id);
     $total_products = count($products_to_category);
     //Filters
     //Get submitted filters
     $filter_size = Input::get('size') ? Input::get('size') : '';
     //		$filter_material  = (Input::get('material')) ? Input::get('material') : '';
     $filter_color = Input::get('color') ? Input::get('color') : '';
     $filter_price_min = Input::get('price_min') ? Input::get('price_min') : '';
     $filter_price_max = Input::get('price_max') ? Input::get('price_max') : '';
     //If there are no submitted filters - try find them in SESSION
     if (empty($_POST)) {
         if (!empty(session('filter_size'))) {
             $filter_size = session('filter_size');
         }
         //			if ( ! empty(session('filter_material')))
         //			{
         //				$filter_material = session('filter_material');
         //			}
         if (!empty(session('filter_color'))) {
             $filter_color = session('filter_color');
         }
         if (!empty(session('price_min'))) {
             $filter_price_min = session('price_min');
         }
         if (!empty(session('price_max'))) {
             $filter_price_max = session('price_max');
         }
     }
     //Store filters inside session
     session(['filter_size' => $filter_size]);
     //		session(['filter_material' => $filter_material]);
     session(['filter_color' => $filter_color]);
     session(['price_min' => $filter_price_min]);
     session(['price_max' => $filter_price_max]);
     if (!empty($filter_size)) {
         $products_with_size = Model_Client::getProductsWithSize($filter_size);
         $products_without_size = array_diff($response['products'], $products_with_size);
         $response['products'] = array_diff($response['products'], $products_without_size);
         $total_products = count($response['products']) - count($products_without_size);
         $response['filter']['size'] = $filter_size;
     }
     //		if ( ! empty($filter_material))
     //		{
     //			$products_with_material         = Model_Client::getProductsWithMaterial($filter_material);
     //			$products_without_material      = array_diff($response['products'], $products_with_material);
     //			$response['products']           = array_diff($response['products'], $products_without_material);
     //			$total_products                 = count($response['products']) - count($products_without_material);
     //			$response['filter']['material'] = $filter_material;
     //		}
     if (!empty($filter_color)) {
         $products_with_color = Model_Client::getProductsWithColor($filter_color);
         $products_without_color = array_diff($response['products'], $products_with_color);
         $response['products'] = array_diff($response['products'], $products_without_color);
         $total_products = count(array_diff($response['products'], $products_without_color));
         $response['filter']['color'] = $filter_color;
     }
     if (!empty($filter_price_min) && !empty($filter_price_max) && (intval($filter_price_min) > 1 || intval($filter_price_max) < 100)) {
         $products_in_price = Model_Client::getProductsWithPrice($filter_price_min, $filter_price_max);
         $products_outside_price = array_diff($response['products'], $products_in_price);
         $response['products'] = array_diff($response['products'], $products_outside_price);
         $total_products = count($response['products']) - count($products_outside_price);
         $response['filter']['price_min'] = $filter_price_min;
         $response['filter']['price_max'] = $filter_price_max;
     }
     //Products to render
     $response['products_to_render'] = $response['products'];
     // Get Carousels
     $response['carousels'] = Model_Main::getCarousels($this->active_module, $id);
     //Send carousels to response and add products to fetch queue
     if (!empty($response['carousels']) && is_array($response['carousels'])) {
         foreach ($response['carousels'] as $key => $carousel) {
             if (!empty($carousel['products'])) {
                 $response['carousels'][$key]['products'] = explode(', ', $carousel['products']);
                 $response['products'] = array_merge($response['products'], $response['carousels'][$key]['products']);
             }
         }
     }
     //Get upcoming product
     $response['upcoming'] = Model_Client::getUpcomingProduct();
     if (!empty($response['upcoming']['product_id'])) {
         if (!array_search($response['upcoming']['product_id'], $response['products'])) {
             $response['products'][] = $response['upcoming']['product_id'];
         }
         if (!empty($response['upcoming']['date'])) {
             $response['upcoming']['date'] = date('Y/m/d', strtotime($response['upcoming']['date']));
         }
     }
     // Get products data
     $response['products'] = Model_Main::getProducts($response['products'], ['title', 'images', 'sizes', 'description']);
     // Send products to response
     $response['products'] = self::prepareProductsForResponse($response['products']);
     // Get Sliders
     $response['sliders'] = Model_Main::getSliders($this->active_module, $id);
     // Send sliders to response
     $response['sliders'] = self::prepareSliders($response['sliders']);
     // Get Sizes
     $response['sizes'] = Model_Client::getSizes();
     // Get Colors
     $response['colors'] = Model_Client::getColors();
     // Get Materials
     //		$response['materials'] = Model_Client::getMaterials();
     // Define other needable variables
     $response['thumbs_path'] = Config::get('system_settings.product_public_path');
     $response['icon_size'] = Config::get('images.sm_icon_size');
     $response['sliders_path'] = Config::get('system_settings.sliders_public_path');
     //Get current page
     if (empty($page) or $page < 1) {
         $response['current_page'] = 1;
     } else {
         $response['current_page'] = $page;
     }
     //Calculate total pages
     $response['total_pages'] = intval($total_products / $this->system['quantity']) + 1;
     dd($response);
     return $response;
 }