Exemplo n.º 1
0
 protected function show($slug = false)
 {
     if (isset($sorting)) {
         Model_Category::$sorting = $sorting;
     }
     if ($category = Model_Category::get_by_slug($slug)) {
         // TODO delete this
         srand($category->id);
         $items = null;
         $parent_category = null;
         if ($category->parent_id == 0) {
             $view_file = 'category';
             // Categories
             $items = Model_Category::find(array('where' => array('parent_id' => $category->id, 'status' => 1), 'order_by' => array('sort' => 'asc')));
             if (!$items) {
                 $view_file = 'subcategory';
                 $items = $category->products;
             }
         } else {
             $view_file = 'subcategory';
             // Products
             $items = $category->products;
             // echo '<pre>';
             // print_r($items);
             // echo '</pre>';
             $parent_category = Model_Category::find_one_by_id($category->parent_id);
         }
         \Helper::sorting($items);
         // Reset to empty array if there are no result found by query
         if (is_null($items)) {
             $items = array();
         }
         // Initiate pagination
         $pagination = \Hybrid\Pagination::make(array('total_items' => count($items), 'per_page' => \Input::get('per_page', 15), 'uri_segment' => null));
         // Remove unwanted items, and show only required ones
         $items = array_slice($items, $pagination->offset, $pagination->per_page);
         $category_parents = false;
         if ($parent_category) {
             $parents = array();
             if ($category_parents_id = Model_Category::find_parents($category->parent_id, $parents, true)) {
                 $category_parents = Model_Category::find(array('where' => array(array('id', 'in', $category_parents_id))));
             }
         }
         $stock_options = \Config::load('stock-option.db');
         \Theme::instance()->set_partial('content', $this->view_dir . $view_file)->set('category', $category, false)->set('parent_category', $parent_category, false)->set('items', $items, false)->set('category_parents', $category_parents, false)->set('pagination', $pagination, false)->set('manage_stock', $stock_options['manage_stock'], false)->set('hide_out_of_stock', $stock_options['hide_out_of_stock'], false);
         \View::set_global('title', $category->seo->meta_title ?: $category->title);
         \View::set_global('meta_description', $category->seo->meta_description ?: '');
         \View::set_global('meta_keywords', $category->seo->meta_keywords ?: '');
         $robots = array('meta_robots_index' => $category->seo->meta_robots_index == 1 ? 'index' : 'noindex', 'meta_robots_follow' => $category->seo->meta_robots_follow == 1 ? 'follow' : 'nofollow');
         \View::set_global('robots', $robots);
         \View::set_global('canonical', $category->seo->canonical_links);
         \View::set_global('h1_tag', $category->seo->h1_tag);
         if ($category->seo->redirect_301) {
             \Response::redirect($category->seo->redirect_301);
         }
     } else {
         throw new \HttpNotFoundException();
     }
 }
Exemplo n.º 2
0
 /**
  * Index page
  * 
  * @access  public
  * @param   $slug
  */
 public function action_index($slug = false, $my_products = null)
 {
     $category_parents = false;
     if ($my_products == 1) {
         Model_Product::$filter_by_pricing_group = 'assigned';
     } else {
         Model_Product::$filter_by_pricing_group = 'not_assigned';
     }
     if ($product = Model_Product::get_by_slug($slug)) {
         // Find main category
         if (!empty($product->categories)) {
             $parents = array();
             if ($category_parents_id = Model_Category::find_parents(key($product->categories), $parents, true)) {
                 $category_parents = Model_Category::find(array('where' => array(array('id', 'in', $category_parents_id))));
             }
         }
         \Theme::instance()->set_partial('content', $this->view_dir . 'product')->set('product', $product, false)->set('category_parents', $category_parents, false)->set('product_data', $product->data, false);
     } else {
         throw new \HttpNotFoundException();
     }
 }
Exemplo n.º 3
0
 /**
  * Index page
  * 
  * @access  public
  * @param   $slug
  */
 public function action_index($slug = false, $my_products = null)
 {
     $category_parents = false;
     if ($my_products == 1) {
         Model_Product::$filter_by_pricing_group = 'assigned';
     } else {
         Model_Product::$filter_by_pricing_group = 'not_assigned';
     }
     if ($product = Model_Product::get_by_slug($slug)) {
         // Find main category
         if (!empty($product->categories)) {
             $parents = array();
             if ($category_parents_id = Model_Category::find_parents(key($product->categories), $parents, true)) {
                 $category_parents = Model_Category::find(array('where' => array(array('id', 'in', $category_parents_id))));
             }
         }
         $stock_options = \Config::load('stock-option.db');
         if ($product->attributes[0]->stock_quantity > 0 || $stock_options['manage_stock'] && $product->attributes[0]->stock_quantity < 1 && $stock_options['hide_out_of_stock'] == 0) {
             \Theme::instance()->set_partial('content', $this->view_dir . 'product')->set('product', $product, false)->set('category_parents', $category_parents, false)->set('product_data', $product->data, false)->set('allow_buy_out_of_stock', $stock_options['allow_buy_out_of_stock']);
         } else {
             \Messages::error('Item is not available.');
             \Response::redirect('page/products');
         }
         \View::set_global('title', $product->seo->meta_title ?: $product->title);
         \View::set_global('meta_description', $product->seo->meta_description ?: '');
         \View::set_global('meta_keywords', $product->seo->meta_keywords ?: '');
         $robots = array('meta_robots_index' => $product->seo->meta_robots_index == 1 ? 'index' : 'noindex', 'meta_robots_follow' => $product->seo->meta_robots_follow == 1 ? 'follow' : 'nofollow');
         \View::set_global('robots', $robots);
         \View::set_global('canonical', $product->seo->canonical_links);
         \View::set_global('h1_tag', $product->seo->h1_tag);
         if ($product->seo->redirect_301) {
             \Response::redirect($product->seo->redirect_301);
         }
     } else {
         throw new \HttpNotFoundException();
     }
 }
Exemplo n.º 4
0
 public static function find_parents($id = false, &$parents = array(), $return_requested = false)
 {
     if (is_numeric($id)) {
         if ($category = Model_Category::find_one_by_id($id)) {
             if ($category->parent_id > 0) {
                 $parents[$id] = $category->parent_id;
                 Model_Category::find_parents($category->parent_id, $parents, $return_requested);
             }
         }
     }
     if ($return_requested) {
         $parents[$id] = $id;
     }
     return array_reverse($parents);
 }