Пример #1
0
 public function indexAction()
 {
     $this->permission('index');
     $settings = $this->module->getSettings($this->_module);
     if ($this->validation->validate($this)) {
         $this->module->saveSettings($this->_module, ['default_home_page' => $this->input->post('default_home_page')]);
         Uri_helper::redirect('management/' . $this->_module);
     } else {
         return $this->render('home/index', ['home_pages' => Form_helper::arrayToDropdown($this->Config->get('Home')), 'setting' => $settings]);
     }
 }
 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']]);
     }
 }