public function action_index() { //template header $this->template->title = ''; // $this->template->meta_keywords = 'keywords'; $this->template->meta_description = Core::config('general.site_name') . ' ' . __('official homepage for the online store'); $products = new Model_Product(); $products->where('status', '=', Model_Product::STATUS_ACTIVE); switch (core::config('product.products_in_home')) { case 3: $id_products = Model_Review::best_rated(); $array_ids = array(); foreach ($id_products as $id => $id_product) { $array_ids = $id_product; } if (count($id_products) > 0) { $products->where('id_product', 'IN', $array_ids); } break; case 2: $id_products = array_keys(Model_Visit::popular_products()); if (count($id_products) > 0) { $products->where('id_product', 'IN', $id_products); } break; case 1: $products->where('featured', 'IS NOT', NULL)->where('featured', '>', Date::unix2mysql())->order_by('featured', 'desc'); break; case 0: default: $products->order_by('created', 'desc'); break; } $products = $products->limit(Theme::get('num_home_products', 21))->cached()->find_all(); $categs = Model_Category::get_category_count(); $this->template->bind('content', $content); $this->template->content = View::factory('pages/home', array('products' => $products, 'categs' => $categs)); }
/** * Automatically executed before the widget action. Can be used to set * class properties, do authorization checks, and execute other custom code. * * @return void */ public function before() { $products = new Model_Product(); $products->where('status', '=', Model_Product::STATUS_ACTIVE); switch ($this->products_type) { case 'popular': $id_products = array_keys(Model_Visit::popular_products()); if (count($id_products) > 0) { $products->where('id_product', 'IN', $id_products); } break; case 'featured': $products->where('featured', 'IS NOT', NULL)->where('featured', '>', Date::unix2mysql())->order_by('featured', 'desc'); break; case 'latest': default: $products->order_by('created', 'desc'); break; } $products = $products->limit($this->products_limit)->cached()->find_all(); //die(print_r($products)); $this->products = $products; }
public function action_listing() { if (Theme::get('infinite_scroll')) { $this->template->scripts['footer'][] = '//cdn.jsdelivr.net/jquery.infinitescroll/2.0b2/jquery.infinitescroll.js'; $this->template->scripts['footer'][] = 'js/listing.js'; } $this->template->scripts['footer'][] = 'js/sort.js'; Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Home'))->set_url(Route::url('default'))); /** * we get the model of category from controller to filter and generate urls titles etc... */ $category = NULL; $category_parent = NULL; if (Model_Category::current()->loaded()) { $category = Model_Category::current(); //adding the category parent if ($category->id_category_parent != 1 and $category->parent->loaded()) { $category_parent = $category->parent; } } //base title if ($category !== NULL) { //category image if (($icon_src = $category->get_icon()) !== FALSE) { Controller::$image = $icon_src; } $this->template->title = $category->name; if ($category->description != '') { $this->template->meta_description = $category->description; } else { $this->template->meta_description = $category->name . ' ' . __('sold in') . ' ' . Core::config('general.site_name'); } } else { $this->template->title = __('all'); $this->template->meta_description = __('List of all products in') . ' ' . Core::config('general.site_name'); } if ($category_parent !== NULL) { $this->template->title .= ' (' . $category_parent->name . ')'; Breadcrumbs::add(Breadcrumb::factory()->set_title($category_parent->name)->set_url(Route::url('list', array('category' => $category_parent->seoname)))); } if ($category !== NULL) { Breadcrumbs::add(Breadcrumb::factory()->set_title($category->name)->set_url(Route::url('list', array('category' => $category->seoname)))); } //user recognition $user = Auth::instance()->get_user() == NULL ? NULL : Auth::instance()->get_user(); $products = new Model_Product(); //filter by category if ($category !== NULL) { $products->where('id_category', 'in', $category->get_siblings_ids()); } //only published products $products->where('status', '=', Model_Product::STATUS_ACTIVE); $res_count = $products->count_all(); // check if there are some advet.-s if ($res_count > 0) { // pagination module $pagination = Pagination::factory(array('view' => 'pagination', 'total_items' => $res_count, 'items_per_page' => core::config('general.products_per_page')))->route_params(array('controller' => $this->request->controller(), 'action' => $this->request->action(), 'category' => $category !== NULL ? $category->seoname : NULL)); Breadcrumbs::add(Breadcrumb::factory()->set_title(__("Page ") . $pagination->current_page)); /** * order depending on the sort parameter */ switch (core::request('sort', core::config('general.sort_by'))) { //title z->a case 'title-asc': $products->order_by('title', 'asc')->order_by('created', 'desc'); break; //title a->z //title a->z case 'title-desc': $products->order_by('title', 'desc')->order_by('created', 'desc'); break; //cheaper first //cheaper first case 'price-asc': $products->order_by('price', 'asc')->order_by('created', 'desc'); break; //expensive first //expensive first case 'price-desc': $products->order_by('price', 'desc')->order_by('created', 'desc'); break; //featured //featured case 'featured': default: $products->order_by('featured', 'desc')->order_by('created', 'desc'); break; //oldest first //oldest first case 'published-asc': $products->order_by('created', 'asc'); break; //newest first //newest first case 'published-desc': $products->order_by('created', 'desc'); break; } //we sort all products with few parameters $products = $products->limit($pagination->items_per_page)->offset($pagination->offset)->find_all(); // array of categories sorted for view $data = array('products' => $products, 'pagination' => $pagination, 'user' => $user, 'category' => $category); } else { // array of categories sorted for view $data = array('products' => NULL, 'pagination' => NULL, 'user' => $user, 'category' => $category); } $this->template->bind('content', $content); $this->template->content = View::factory('pages/product/listing', $data); }