Пример #1
0
 public function getFieldVariantId($code)
 {
     if ($field = Field::findOne(['slug' => $code])) {
         if ($value = FieldValue::findOne(['field_id' => $field->id, 'item_id' => $this->owner->id])) {
             return $value->variant_id;
         }
     }
     return false;
 }
Пример #2
0
 public function actionUpdate()
 {
     $post = yii::$app->request->post('FieldValue');
     $model = FieldValue::findOne(['item_id' => $post['item_id'], 'field_id' => $post['field_id']]);
     if (!$model) {
         $model = new fieldValue();
     } else {
         $field = field::findOne($model->field_id);
         if ($field->type == 'radio') {
             FieldValue::deleteAll(['item_id' => $post['item_id'], 'field_id' => $post['field_id']]);
             $model = new fieldValue();
         }
     }
     $json = [];
     if ($model->load(yii::$app->request->post()) && $model->save()) {
         $json['result'] = 'success';
     } else {
         $json['result'] = 'fail';
         $json['error'] = $model->getErrors();
     }
     return json_encode($json);
 }