Exemple #1
0
 protected static function actionActive()
 {
     $product = new ProductModel($_GET['id']);
     $product->active = $product->active ? '0' : '1';
     $product->save();
     self::redirect(App::getLink('admin-products'));
 }
 function handleSaveSequence($data)
 {
     //zoberieme normalne poradie
     $before_list = ProductModel::getFluent()->orderBy('product_sequence');
     if ($this->getParam('id_category') != '') {
         $before_list->where('id_category = %i', $this->getParam('id_category'));
     }
     $before_list = $before_list->fetchAll();
     foreach ($before_list as $k => $l) {
         if (isset($data[$k])) {
             list($tmp, $id_product) = explode("index_", $data[$k]);
             ProductModel::save(array('product_sequence' => $l['product_sequence']), $id_product, 1);
             //				echo dibi::$sql;
         }
     }
     //		print_r($data);exit;
     //		foreach( $data as $k=>$s){
     //			list( $tmp,$id_product) = explode("index_",$s);
     //			ProductModel::save(array('product_sequence'=>$k), $id_product, 1);
     //		}
     exit;
 }
 function save(NFORM $form)
 {
     $values = $form->getValues();
     $langs = Setting::getLangs();
     $id_product = $values['id_product'];
     $table_product_cols = Tools::getCollum('product');
     $table_product_lang_cols = Tools::getCollum('product_lang');
     //ulozenie jazuka
     foreach ($langs as $l) {
         $save_val = array();
         foreach ($table_product_lang_cols as $k => $c) {
             if (isset($values[$c . CategoryFormControl::$_separator . $l['iso']])) {
                 $save_val[$c] = $values[$c . CategoryFormControl::$_separator . $l['iso']];
             }
         }
         //pridanie linky rewrite
         if ($save_val['link_rewrite'] == '') {
             $save_val['link_rewrite'] = NStrings::webalize($values['name' . CategoryFormControl::$_separator . $l['iso']]);
         } else {
             $save_val['link_rewrite'] = NStrings::webalize($save_val['link_rewrite']);
         }
         ProductModel::save($save_val, $id_product, $l['id_lang']);
     }
     //ulozenie zakladnych hodnot
     $save_val = array();
     foreach ($table_product_cols as $p) {
         if (isset($values[$p])) {
             $save_val[$p] = $values[$p];
         }
     }
     ProductModel::save($save_val, $id_product, $l['id_lang']);
     //ulozit param
     /*
      * Iba ak je product bez parametrov
      */
     $val_product_param = Tools::getValuesForTable('product_param', $values);
     //prvy parameter
     $id_product_param = dibi::fetchSingle("SELECT id_product_param FROM [product_param] WHERE id_product = %i", $id_product, "ORDER BY sequence");
     ProductModel::setProductParamValue($val_product_param, $id_product_param);
     ProductModel::saveProductAlternative($id_product, $values['product_alternative']);
     dibi::begin();
     ProductModel::deleteProductFromCategories($id_product);
     ProductModel::addProductToCategory($values['id_categories'], $id_product);
     dibi::commit();
     ProductModel::invalidateCache();
     $this->flashMessage(_('Produkt bol uložený'));
     if ($form['btn_save']->isSubmittedBy()) {
         $s = NEnvironment::getSession("Admin_Eshop");
         $back_url = $s['back_url'];
         if ($back_url != '') {
             $this->redirectUrl($back_url);
         } else {
             $this->redirect('Eshop:default');
         }
     } else {
         $this->redirect('this');
     }
 }
 /**
  * Copy record
  * If copy is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be copy
  */
 public function actionCopy($id)
 {
     $data = $this->loadModel($id);
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['ProductModel'])) {
         $model = new ProductModel();
         $model->attributes = $_POST['ProductModel'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('copy', array('model' => $data));
 }