/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Values();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Values'])) {
         $model->attributes = $_POST['Values'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Esempio n. 2
0
 public function actionSaveProduct()
 {
     $product = Products::model()->findByPk($_POST['productId']);
     $attributes = json_decode($_POST['attributes']);
     //удмлим все значения, связанные с текущим атрибутом и сам атрибут
     $attributes_AR = Attributes::model()->findAll("product_id=:product_id", array(':product_id' => $_POST['productId']));
     foreach ($attributes_AR as $attribute) {
         Values::model()->deleteAll("attribute_id=:attribute_id", array(':attribute_id' => $attribute->id));
         $attribute->delete();
     }
     foreach ($attributes as $attribute) {
         $attribute_AR = new Attributes();
         $attribute_AR->product_id = $product->id;
         $attribute_AR->name = $attribute->name;
         $res = $attribute_AR->save();
         if ($res == false) {
             echo "false-attr";
             return;
         }
         foreach ($attribute->values as $value) {
             $value_AR = new Values();
             $value_AR->name = $value->name;
             $value_AR->add_price = $value->add_price;
             $value_AR->attribute_id = $attribute_AR->id;
             $res = $value_AR->save();
             if ($res == false) {
                 echo "false-value";
                 return;
             }
         }
     }
     $product->discount = $_POST['discount'];
     $product->name = $_POST['name'];
     $product->text = $_POST['text'];
     if ($_POST['photo'] != '') {
         $product->photo = $_POST['photo'];
     }
     $product->main_price = $_POST['main_price'];
     $product->sostav = $_POST['sostav'];
     $res = $product->update();
     if ($res == false) {
         var_dump($product->errors);
         echo "false-prod";
         return;
     }
     echo "true";
 }
 public function insertaddon()
 {
     //Initialization
     Session::put('goToChecklist', 'true');
     $otherDetails_id = Input::get('otherDetails_id');
     $purchase_request_id = Input::get('purchase_request_id');
     $value = strip_tags(Input::get('value'));
     if (ctype_alnum(str_replace(str_split(' !\\/:*?".,|'), '', $value))) {
         $insertvalue = new Values();
         $insertvalue->otherDetails_id = $otherDetails_id;
         $insertvalue->purchase_request_id = $purchase_request_id;
         $insertvalue->value = $value;
         $insertvalue->save();
         Session::forget('retainOtherDetails');
         Session::forget('retainId');
         Session::put('successlabel', 'Successfully saved.');
         return Redirect::back();
     } else {
         Session::put('retainOtherDetails', $value);
         Session::put('retainId', $otherDetails_id);
         Session::put('errorlabel', 'Invalid input.');
         return Redirect::back();
     }
 }