private function getCategories()
 {
     if ($categories = Model_Main::getCategory(FALSE, ['title'], TRUE)) {
         $categories_ids = [];
         $main_categories = [];
         $second_level_categories = [];
         $third_level_categories = [];
         if (!empty($categories) && is_array($categories)) {
             //Loop and get ID's
             foreach ($categories as $key => $category) {
                 $categories_ids[] = $category['id'];
             }
             //Get urls
             if ($urls = Model_Client::getURL($categories_ids, 'category')) {
                 if (!empty($urls) && is_array($urls)) {
                     foreach ($urls as $url) {
                         $categories[$url['object']]['slug'] = $url['slug'];
                     }
                 }
             }
             foreach ($categories as $key => $category) {
                 if ($category['level'] == 0) {
                     $main_categories[$category['id']] = ['id' => $category['id'], 'slug' => !empty($category['slug']) ? $category['slug'] : '', 'title' => $category['title']];
                 } elseif ($category['level'] == 1) {
                     $second_level_categories[$category['parent_id']][] = ['id' => $category['id'], 'slug' => !empty($category['slug']) ? $category['slug'] : '', 'title' => $category['title'], 'parent' => $category['parent_id']];
                 } elseif ($category['level'] == 2) {
                     $third_level_categories[$category['parent_id']][] = ['id' => $category['id'], 'slug' => !empty($category['slug']) ? $category['slug'] : '', 'title' => $category['title'], 'parent' => $category['parent_id']];
                 }
             }
         }
         $this->categories['all'] = $categories;
         View::share('main_categories', $main_categories);
         View::share('second_level_categories', $second_level_categories);
         View::share('third_level_categories', $third_level_categories);
     } else {
         return FALSE;
     }
 }
Example #2
0
 public static function sitemap()
 {
     $customCSS = [];
     $customJS = [];
     $response = ['page_title' => trans('client.sitemap'), 'blade_custom_css' => $customCSS, 'blade_custom_js' => $customJS];
     if ($response['categories'] = Model_Main::getCategory(FALSE, ['title'], FALSE)) {
         $categories_ids = [];
         $main_categories = [];
         $second_level_categories = [];
         //			$third_level_categories  = [];
         if (!empty($response['categories']) && is_array($response['categories'])) {
             //Loop and get ID's
             foreach ($response['categories'] as $key => $category) {
                 $categories_ids[] = $category['id'];
             }
             //Get urls
             if ($urls = Model_Client::getURL($categories_ids, 'category')) {
                 if (!empty($urls) && is_array($urls)) {
                     foreach ($urls as $url) {
                         $response['categories'][$url['object']]['slug'] = $url['slug'];
                     }
                 }
             }
             foreach ($response['categories'] as $key => $category) {
                 if ($category['level'] == 0) {
                     $main_categories[$category['id']] = ['id' => $category['id'], 'slug' => !empty($category['slug']) ? $category['slug'] : '', 'title' => $category['title']];
                 } elseif ($category['level'] == 1) {
                     $second_level_categories[$category['parent_id']][] = ['id' => $category['id'], 'slug' => !empty($category['slug']) ? $category['slug'] : '', 'title' => $category['title'], 'parent' => $category['parent_id']];
                 }
                 //					elseif ($category['level'] == 2)
                 //					{
                 //						$third_level_categories[$category['parent_id']][] = [
                 //							'id'     => $category['id'],
                 //							'slug'   => ! empty($category['slug']) ? $category['slug'] : '',
                 //							'title'  => $category['title'],
                 //							'parent' => $category['parent_id'],
                 //						];
                 //					}
             }
         }
         $response['map_cat_lvl_1'] = $main_categories;
         $response['map_cat_lvl_2'] = $second_level_categories;
         //			$response['map_cat_lvl_3'] = $third_level_categories;
         $response['map_pages'] = Model_Main::getSitemapPages();
     }
     return Theme::view('homepage.sitemap', $response);
 }
Example #3
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;
 }
Example #4
0
 public function sitemapCategories()
 {
     $categories = Model_Main::getCategory(FALSE, ['title']);
     if (!empty($categories) && is_array($categories)) {
         //Loop and get ID's
         foreach ($categories as $key => $category) {
             $categories_ids[] = $category['id'];
         }
         //Get urls
         if ($urls = Model_Client::getURL($categories_ids, 'category')) {
             if (!empty($urls) && is_array($urls)) {
                 foreach ($urls as $url) {
                     $categories[$url['object']]['slug'] = $url['slug'];
                 }
             }
         }
         foreach ($categories as $id => $data) {
             Sitemap::addTag(url('/' . $data['slug']), $data['updated_at']);
         }
     }
     // Return the sitemap to the client.
     return Sitemap::render();
 }