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']]); } }