public function indexAction($id) { $products = new \modules\commerce\models\Commerce_products(); $category = new \modules\commerce\models\Commerce_categories(); $category->commerce_category_id = $id; $products->commerce_category_id = $id; return $this->render('commerce_category', ['item' => $category->get(), 'products' => $products->get(), 'product_model' => $products]); }
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])]); }
public function manageAction($id = false) { $this->permission('manage'); $commerce = new \modules\commerce\models\Commerce_products(); $product_images = new \modules\commerce\models\Commerce_product_images(false); $commerce->set('name', $this->input->post('name')); $commerce->set('commerce_category_id', $this->input->post('commerce_category_id')); $commerce->set('price', $this->input->post('price')); $commerce->set('type', $this->input->post('type')); $commerce->set('discount', $this->input->post('discount')); $commerce->set('commerce_brand_id', $this->input->post('commerce_brand_id')); $categories = []; $cats = Form_helper::queryToDropdown('commerce_categories', 'commerce_category_id', 'title', FALSE, 'WHERE parent="0"'); foreach ($cats as $catk => $catv) { $categories[$catk] = $catv; foreach (Form_helper::queryToDropdown('commerce_categories', 'commerce_category_id', 'title', FALSE, 'WHERE parent="' . $catk . '"') as $subk => $subv) { $categories[$subk] = ' |-- ' . $subv; } } $categories = Form_helper::arrayToDropdown($categories); $brands = Form_helper::queryToDropdown('commerce_brands', 'commerce_brand_id', 'name'); if ($id) { $commerce->commerce_product_id = $id; } $commerce->language_id = $this->language->getDefaultLanguage(); if ($id = $commerce->save()) { $product_images->commerce_product_id = $id; $product_images->delete(); foreach ($this->input->post('uploaded_files') as $file) { $product_images->commerce_product_id = $id; $product_images->product_image = $file; $product_images->save(); } Uri_helper::redirect("management/commerce_products"); } else { return $this->render('commerce_products/manage', ['item' => $id ? $commerce->get() : null, 'categories' => $categories, 'brands' => $brands, 'type' => ['normal' => 'Normal', 'weighted' => 'Weighted', 'digital' => 'Digital']]); } }