/** * 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); $products->where('rate', 'IS NOT', NULL)->order_by('rate', 'desc')->order_by('created', 'asc'); $products = $products->limit($this->products_limit)->cached()->find_all(); $this->products = $products; }
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_search() { //template header $this->template->title = __('Advanced Search'); $this->template->meta_description = __('Search in') . ' ' . Core::config('general.site_name'); $this->template->styles = array('//cdn.jsdelivr.net/bootstrap.datepicker/0.1/css/datepicker.css' => 'screen'); $this->template->scripts['footer'] = array('//cdn.jsdelivr.net/bootstrap.datepicker/0.1/js/bootstrap-datepicker.js'); //breadcrumbs Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Home'))->set_url(Route::url('default'))); Breadcrumbs::add(Breadcrumb::factory()->set_title($this->template->title)); $categories = Model_Category::get_as_array(); $order_categories = Model_Category::get_multidimensional(); $pagination = NULL; $products = NULL; if ($this->request->query()) { $products = new Model_Product(); $category = NULL; //filter by category if (core::get('category') !== NULL) { $category = new Model_Category(); $category->where('seoname', '=', core::get('category'))->limit(1)->find(); if ($category->loaded()) { $products->where('id_category', 'IN', $category->get_siblings_ids()); } } //filter by title description if (core::get('search') !== NULL and strlen(core::get('search')) >= 3) { $products->where_open()->where('title', 'like', '%' . core::get('search') . '%')->or_where('description', 'like', '%' . core::get('search') . '%')->where_close(); } //filter by price if (is_numeric(core::get('price-min')) and is_numeric(core::get('price-max'))) { $products->where('price', 'BETWEEN', array(core::get('price-min'), core::get('price-max'))); } //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)); //we sort all products with few parameters $products = $products->order_by('created', 'desc')->limit($pagination->items_per_page)->offset($pagination->offset)->find_all(); } } $this->template->bind('content', $content); $this->template->content = View::factory('pages/search', array('categories' => $categories, 'order_categories' => $order_categories, 'products' => $products, 'pagination' => $pagination)); }
public function action_import() { if ($this->request->post()) { ini_set('auto_detect_line_endings', true); $csv = $_FILES['file_source']['tmp_name']; if (($handle = fopen($csv, "r")) !== FALSE) { $i = 0; while (($data = fgetcsv($handle, 0, ";")) !== false) { //avoid first line if ($i != 0) { list($email, $pay_date, $product_seotitle, $amount, $currency) = $data; $pay_date = Date::from_format($pay_date, 'd/m/yy', 'Y-m-d H:i:s'); $user = Model_User::create_email($email, substr($email, 0, strpos($email, '@'))); $product = new Model_Product(); $product->where('seotitle', '=', $product_seotitle)->limit(1)->find(); if ($product->loaded()) { $order = Model_Order::new_order($user, $product); $order->confirm_payment('import', NULL, $pay_date, $amount, $currency); } } $i++; } } fclose($handle); //redirect to orders Alert::set(Alert::SUCCESS, __('Import correct')); $this->redirect(Route::url('oc-panel', array('controller' => 'order', 'action' => 'index'))); } //template header $this->template->title = __('Import Orders'); Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Import Orders'))); $this->template->content = View::factory('oc-panel/pages/order/import'); }