public function manageAction($id = false) { $this->permission('manage'); if ($id) { $commerce_brands = new \modules\commerce\models\Commerce_brands('edit'); $commerce_brands->commerce_brand_id = $id; } else { $commerce_brands = new \modules\commerce\models\Commerce_brands('add'); } $commerce_brands->set($this->Input->post()); $commerce_brands->language_id = $this->language->getDefaultLanguage(); if ($commerce_brands->save()) { Uri_helper::redirect("management/commerce_brands"); } else { return $this->render('commerce_brands/manage', ['item' => $id ? $commerce_brands->get() : null]); } }
public function indexAction($offset = 0) { $category = new \modules\commerce\models\Commerce_categories(); $brands = new \modules\commerce\models\Commerce_brands(); $product = new \modules\commerce\models\Commerce_products(); $category->_select = "commerce_category_id, title, parent"; $category->parent = 0; $sorting = ['' => 'Sort By', 'name' => 'Name', 'low_price' => 'Low Price', 'heigh_price' => 'Heigh Price']; if (is_array($this->input->get('category_id')) && count($this->input->get('category_id')) && !empty($this->input->get('category_id.0'))) { $product->where('commerce_category_id IN (SELECT commerce_category_id FROM commerce_categories WHERE parent IN ("' . implode('","', $this->input->get('category_id')) . '")) '); } //UNION ALL SELECT ("'. implode('","', $this->input->get('category_id')) .' if ($this->input->get('brand_id')) { $product->where('commerce_brand_id IN ("' . implode('","', $this->input->get('brand_id')) . '")'); } if ($this->input->get('q')) { $product->like('commerce_products.name', $this->input->get('q')); } if ($this->input->get('from_price')) { $product->like('commerce_products.price >=', $this->input->get('from_price')); } if ($this->input->get('to_price')) { $product->like('commerce_products.price <=', $this->input->get('to_price')); } if ($this->input->get('sorting')) { if ($this->input->get('sorting') == 'name') { $product->_order_by['name'] = 'ASC'; } elseif ($this->input->get('sorting') == 'low_price') { $product->_order_by['price'] = 'ASC'; } elseif ($this->input->get('sorting') == 'heigh_price') { $product->_order_by['price'] = 'DESC'; } } $this->load->library('pagination'); $product->_limit = $this->config->get('limit'); $product->_offset = $offset; return $this->render('commerce_search', ['categories' => $category->get(), 'brands' => $brands->get(), 'sorting' => $sorting, 'products' => $product->get(), 'product_model' => $product, 'pagination' => $this->Pagination->generate(['url' => Uri_helper::url('commerce_search/index'), 'total' => $product->get(true), 'limit' => $product->_limit, 'offset' => $product->_offset])]); }