public function index($slug, $sort = 'id', $dir = "ASC", $page = 0) { \CI::lang()->load('categories'); //define the URL for pagination $pagination_base_url = site_url('category/' . $slug . '/' . $sort . '/' . $dir); //how many products do we want to display per page? //this is configurable from the admin settings page. $per_page = config_item('products_per_page'); //grab the categories $categories = \CI::Categories()->get($slug, $sort, $dir, $page, $per_page); //no category? show 404 if (!$categories) { throw_404(); } //load up the pagination library \CI::load()->library('pagination'); $config['base_url'] = $pagination_base_url; $config['uri_segment'] = 5; $config['per_page'] = $per_page; $config['num_links'] = 3; $config['total_rows'] = $categories['total_products']; \CI::pagination()->initialize($config); //load the view $this->view('categories/category', $categories); }
public function generate() { $type = CI::uri()->segment(1); $slug = CI::uri()->segment(2); if (!$type || !$slug) { return; //return blank } if ($type == 'category') { $category = CI::Categories()->slug($slug); if (!$category) { return; } $this->trace_categories($category->id); } elseif ($type == 'product') { $product = CI::Products()->slug($slug); if (!$product) { return; } array_unshift($this->breadcrumbs, ['link' => site_url('product/' . $product->slug), 'name' => $product->name]); $this->trace_categories($product->primary_category); } elseif ($type == 'page') { $page = CI::Pages()->slug($slug); if (!$page) { return; } $this->trace_pages($page->id); } echo GoCart\Libraries\View::getInstance()->get('breadcrumbs', ['breadcrumbs' => $this->breadcrumbs]); }
public function shortcode($slug = false, $perPage = false) { if (!$perPage) { $perPage = config_item('products_per_page'); } $products = \CI::Categories()->get($slug, 'id', 'ASC', 0, $perPage); return $this->partial('categories/products', $products); }
public function generateCategories() { $categories = \CI::Categories()->get_categories_tiered(); $xml = $this->partial('category_xml', ['categories' => $categories['all']], true); echo $xml; $file = fopen('sitemap.xml', 'a'); fwrite($file, $xml); fclose($file); }
public function homepage() { //echo FCPATH.'themes/'.config_item('theme').'/views/homepage.php';exit; //do we have a homepage view? \CI::load()->model(['Products', 'Categories']); \CI::load()->helper('form'); \CI::lang()->load('products'); if (file_exists(FCPATH . 'themes/' . config_item('theme') . '/views/homepage.php')) { $data['power'] = @$_POST['power']; $data['hz'] = @$_POST['hz']; $engines = array(); $alternators = array(); $generators = array(); $data['engines'] = $engines; $data['alternators'] = $alternators; if ($data['power'] > 0) { $data['hz'] = @$_POST['hz']; $categories['sort'] = $data['sort'] = ''; $categories['dir'] = $data['dir'] = ''; $categories['slug'] = $data['slug'] = ''; $categories['page'] = $data['page'] = ''; $categories['$per_page'] = $data['per_page'] = ''; $categories = \CI::Categories()->get($data['slug'], $data['sort'], $data['dir'], $data['page'], $data['per_page']); $engines = \CI::Products()->getProductsCondition($data['power'], $data['hz']); $alternators = \CI::Products()->getProductsAlternators($data['power'], $data['hz']); //echo \CI::db()->last_query().'<pre>';print_r($alternators);exit; $data['engines'] = $engines; $data['alternators'] = $alternators; $generators = $this->results($data['hz'], $data['engines'], $data['alternators'], $data['power']); } $generators = $this->array_orderby(@$generators, 'kVA', SORT_ASC, 'price', SORT_ASC); $data['generators'] = @$generators; //echo '<pre>';print_r($generators);exit; $this->view('homepage', $data); return; } else { //if we don't have a homepage view, check for a registered homepage if (config_item('homepage')) { if (isset($this->pages['all'][config_item('homepage')])) { //we have a registered homepage and it's active $this->index($this->pages['all'][config_item('homepage')]->slug, false); return; } } } // wow, we do not have a registered homepage and we do not have a homepage.php // let's give them something default to look at. $this->view('homepage_fallback'); }
function category_filter($vars) { //set defaults $slug = false; $per_page = config_item('products_per_page'); if (isset($vars[0])) { $slug = $vars[0]; } else { return false; // there is nothing to display } if (isset($vars[1])) { $per_page = $vars[1]; } $categories = \CI::Categories()->get($slug, 'id', 'ASC', 0, $per_page); return View::getInstance()->get('categories/products', $categories); }
function category_loop($parent = 0, $ulattribs = false, $ul = true) { $cats = CI::Categories()->get_categories_tiered(); $items = false; if (isset($cats[$parent])) { $items = $cats[$parent]; } if ($items) { echo $ul ? '<ul ' . $ulattribs . '>' : ''; foreach ($items as $item) { $selected = CI::uri()->segment(2) == $item->slug ? 'class="selected"' : ''; //add the chevron if this has a drop menu $name = $item->name; if (CI::Categories()->tier($item->id)) { $name .= ' <i class="icon-chevron-down dropdown"></i>'; } $anchor = anchor('category/' . $item->slug, $name, $selected); echo '<li>' . $anchor; category_loop($item->id); echo '</li>'; } echo $ul ? '</ul>' : ''; } }
public function giftCardForm($id = false, $duplicate = false) { $this->product_id = $id; \CI::load()->library('form_validation'); \CI::load()->model(array('ProductOptions', 'Categories')); \CI::form_validation()->set_error_delimiters('<div class="error">', '</div>'); $data['categories'] = \CI::Categories()->get_categories_tiered(); $data['page_title'] = lang('giftcard_product_form'); $data['groups'] = \CI::Customers()->get_groups(); //default values are empty if the product is new $data['id'] = ''; $data['sku'] = ''; $data['primary_category'] = ''; $data['name'] = ''; $data['slug'] = ''; $data['description'] = ''; $data['excerpt'] = ''; $data['track_stock'] = ''; $data['seo_title'] = ''; $data['meta'] = ''; $data['is_giftcard'] = 1; $data['taxable'] = ''; $data['images'] = []; $data['product_categories'] = []; $data['product_files'] = []; foreach ($data['groups'] as $group) { $data['enabled_' . $group->id] = ''; } //create the photos array for later use $data['photos'] = []; if ($id) { // get product & options data $data['ProductOptions'] = \CI::ProductOptions()->getProductOptions($id); $product = \CI::Products()->find($id, true); //if the product does not exist, redirect them to the product list with an error if (!$product) { \CI::session()->set_flashdata('error', lang('error_not_found')); redirect('admin/products'); } //helps us with the slug generation $this->product_name = \CI::input()->post('slug', $product->slug); //set values to db values $data['id'] = $id; $data['sku'] = $product->sku; $data['primary_category'] = $product->primary_category; $data['name'] = $product->name; $data['seo_title'] = $product->seo_title; $data['meta'] = $product->meta; $data['slug'] = $product->slug; $data['description'] = $product->description; $data['excerpt'] = $product->excerpt; $data['quantity'] = $product->quantity; $data['taxable'] = $product->taxable; $data['fixed_quantity'] = $product->fixed_quantity; $data['is_giftcard'] = $product->is_giftcard; foreach ($data['groups'] as $group) { $data['enabled_' . $group->id] = $product->{'enabled_' . $group->id}; } //make sure we haven't submitted the form yet before we pull in the images/related products from the database if (!\CI::input()->post('submit')) { $data['product_categories'] = []; foreach ($product->categories as $product_category) { $data['product_categories'][] = $product_category->id; } $data['related_products'] = $product->related_products; $data['images'] = (array) json_decode($product->images); } } if (!is_array($data['product_categories'])) { $data['product_categories'] = []; } //no error checking on these \CI::form_validation()->set_rules('caption', 'Caption'); \CI::form_validation()->set_rules('primary_photo', 'Primary'); \CI::form_validation()->set_rules('sku', 'lang:sku', 'trim'); \CI::form_validation()->set_rules('seo_title', 'lang:seo_title', 'trim'); \CI::form_validation()->set_rules('meta', 'lang:meta_data', 'trim'); \CI::form_validation()->set_rules('name', 'lang:name', 'trim|required|max_length[64]'); \CI::form_validation()->set_rules('slug', 'lang:slug', 'trim'); \CI::form_validation()->set_rules('description', 'lang:description', 'trim'); \CI::form_validation()->set_rules('excerpt', 'lang:excerpt', 'trim'); \CI::form_validation()->set_rules('taxable', 'lang:taxable', 'trim|numeric'); \CI::form_validation()->set_rules('fixed_quantity', 'lang:fixed_quantity', 'trim|numeric'); \CI::form_validation()->set_rules('option[giftcard_values]', 'lang:giftcard_values', 'required'); foreach ($data['groups'] as $group) { \CI::form_validation()->set_rules('enabled_' . $group->id, lang('enabled') . '(' . $group->name . ')', 'trim|numeric'); } /* if we've posted already, get the photo stuff and organize it if validation comes back negative, we feed this info back into the system if it comes back good, then we send it with the save item submit button has a value, so we can see when it's posted */ if ($duplicate) { $data['id'] = false; } if (\CI::input()->post('submit')) { //reset the product options that were submitted in the post $data['ProductOptions'] = \CI::input()->post('option'); $data['product_categories'] = \CI::input()->post('categories'); $data['images'] = \CI::input()->post('images'); } if (\CI::form_validation()->run() == FALSE) { $this->view('giftcard_product_form', $data); } else { \CI::load()->helper('text'); //first check the slug field $slug = \CI::input()->post('slug'); //if it's empty assign the name field if (empty($slug) || $slug == '') { $slug = \CI::input()->post('name'); } $slug = url_title(convert_accented_characters($slug), '-', TRUE); //validate the slug $slug = $id ? \CI::Products()->validate_slug($slug, $product->id) : \CI::Products()->validate_slug($slug); $save['id'] = $id; $save['sku'] = \CI::input()->post('sku'); $save['name'] = \CI::input()->post('name'); $save['seo_title'] = \CI::input()->post('seo_title'); $save['meta'] = \CI::input()->post('meta'); $save['description'] = \CI::input()->post('description'); $save['excerpt'] = \CI::input()->post('excerpt'); foreach ($data['groups'] as $group) { $save['enabled_' . $group->id] = \CI::input()->post('enabled_' . $group->id); $save['price_' . $group->id] = '0.00'; $save['saleprice_' . $group->id] = '0.00'; } $save['is_giftcard'] = 1; $save['taxable'] = \CI::input()->post('taxable'); $save['taxable'] = \CI::input()->post('taxable'); $post_images = \CI::input()->post('images'); $save['slug'] = $slug; if ($primary = \CI::input()->post('primary_image')) { if ($post_images) { foreach ($post_images as $key => &$pi) { if ($primary == $key) { $pi['primary'] = true; continue; } } } } $save['images'] = json_encode($post_images); if (\CI::input()->post('related_products')) { $save['related_products'] = json_encode(\CI::input()->post('related_products')); } else { $save['related_products'] = ''; } //save categories $categories = \CI::input()->post('categories'); if (!$categories) { $categories = []; } //(\CI::input()->post('primary_category')) ? \CI::input()->post('primary_category') : 0; if (!\CI::input()->post('primary_category') && $categories) { $save['primary_category'] = $categories[0]; } elseif (!\CI::input()->post('primary_category') && !$categories) { $save['primary_category'] = 0; } else { $save['primary_category'] = \CI::input()->post('primary_category'); } // format options $options = []; array_push($options, ['type' => 'textfield', 'name' => 'from', 'required' => 1, 'values' => ['0' => ['name' => 'from', 'value' => '', 'price' => 0, 'limit' => 0]]]); array_push($options, ['type' => 'textfield', 'name' => 'to_email', 'required' => 1, 'values' => ['0' => ['name' => 'to_email', 'value' => '', 'price' => 0, 'limit' => 0]]]); array_push($options, ['type' => 'textarea', 'name' => 'personal_message', 'required' => 1, 'values' => ['0' => ['name' => 'personal_message', 'value' => '', 'price' => 0]]]); $giftcard_values = []; $postedValues = \CI::input()->post('option[giftcard_values]'); if ($postedValues) { foreach ($postedValues as $giftcard_value) { array_push($giftcard_values, ['name' => 'beginning_amount', 'value' => $giftcard_value, 'weight' => '', 'price' => $giftcard_value]); } } array_push($options, ['type' => 'droplist', 'name' => 'beginning_amount', 'required' => 1, 'values' => $giftcard_values]); // save product $product_id = \CI::Products()->save($save, $options, $categories); \CI::session()->set_flashdata('message', lang('message_saved_giftcard_product')); //go back to the product list redirect('admin/products'); } }
function delete($id) { $category = \CI::Categories()->find($id); //if the category does not exist, redirect them to the customer list with an error if ($category) { \CI::Categories()->delete($id); \CI::session()->set_flashdata('message', lang('message_delete_category')); redirect('admin/categories'); } else { \CI::session()->set_flashdata('error', lang('error_not_found')); } }
function delete($id) { $category = \CI::Categories()->find($id); //if the category does not exist, redirect them to the customer list with an error if ($category) { if ($category->image != '') { $file = []; $file[] = 'uploads/images/full/' . $category->image; $file[] = 'uploads/images/medium/' . $category->image; $file[] = 'uploads/images/small/' . $category->image; $file[] = 'uploads/images/thumbnails/' . $category->image; foreach ($file as $f) { //delete the existing file if needed if (file_exists($f)) { unlink($f); } } } \CI::Categories()->delete($id); \CI::session()->set_flashdata('message', lang('message_delete_category')); redirect('admin/categories'); } else { \CI::session()->set_flashdata('error', lang('error_not_found')); } }