示例#1
0
 public function actionCreate()
 {
     if (Yii::app()->request->getParam('type', false)) {
         $type = new ProductType();
         $type->attributes = Yii::app()->request->getParam('type', array());
         $type->save();
     }
     $this->redirect(Yii::app()->createUrl('/type/index'));
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $validation = Validate::TipoproductoValidation(Input::all());
     if ($validation->fails()) {
         return Redirect::to('tipoproducto/create')->withErrors($validation)->withInput();
     } else {
         $tipoproducto = new ProductType();
         $tipoproducto->type = Input::get('type');
         $tipoproducto->save();
         return Redirect::to('tipoproducto');
     }
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new ProductType();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['ProductType'])) {
         $model->attributes = $_POST['ProductType'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
 public function updateProductType()
 {
     if (!Request::ajax()) {
         return App::abort(404);
     }
     $arrReturn = ['status' => 'error'];
     if (Input::has('pk')) {
         $id = (int) Input::get('pk');
         $name = (string) Input::get('name');
         $value = e((string) Input::get('value'));
         try {
             $type = ProductType::findorFail($id);
             $type->{$name} = $value;
         } catch (Illuminate\Database\Eloquent\ModelNotFoundException $e) {
             return App::abort(404);
         }
     } else {
         $type = new ProductType();
         $type->name = Input::get('name');
         $type->description = Input::get('description');
     }
     $pass = $type->valid();
     if ($pass->passes()) {
         $type->save();
         $arrReturn = ['status' => 'ok'];
         $arrReturn['message'] = $type->name . ' has been saved';
         $arrReturn['data'] = $type;
     } else {
         $arrReturn['message'] = '';
         $arrErr = $pass->messages()->all();
         foreach ($arrErr as $value) {
             $arrReturn['message'] .= "{$value}\n";
         }
     }
     $response = Response::json($arrReturn);
     $response->header('Content-Type', 'application/json');
     return $response;
 }
示例#5
0
foreach ($sugar_demodata['productcategory_seed_data_names'] as $v) {
    $category = new ProductCategory();
    $category->name = $v;
    $category->list_order = "1";
    $key = array_rand($sugar_demodata['users']);
    $category->assigned_user_id = $sugar_demodata['users'][$key]['id'];
    $category->save();
    $productcategory_id_arr[] = $category->id;
}
echo '.';
$list_order = 1;
foreach ($sugar_demodata['producttype_seed_data_names'] as $v) {
    $type = new ProductType();
    $type->name = $v;
    $type->list_order = $list_order;
    $type->save();
    $producttype_id_arr[] = $type->id;
    $list_order++;
}
echo '.';
foreach ($sugar_demodata['taxrate_seed_data'] as $v) {
    $taxrate = new TaxRate();
    $taxrate->name = $v['name'];
    $taxrate->value = $v['value'];
    $taxrate->status = "Active";
    $taxrate->list_order = "1";
    $taxrate->disable_num_format = TRUE;
    $taxrate->save();
    $taxrate_id_arr[] = $taxrate->id;
}
echo '.';
 public function actionAddProductType()
 {
     $ptypeName = $_POST['ptypeName'];
     // $ptypeName = "糕点2";
     // echo $ptypeName;
     $sql = 'SELECT * FROM  `product_type` WHERE name="' . $ptypeName . '"';
     $type = ProductType::model()->findBySql($sql);
     // echo var_dump($type);
     $result = true;
     if ($type) {
         //该种类已存在
         $result = false;
     } else {
         $ptype = new ProductType();
         $ptype->name = $ptypeName;
         if (!$ptype->save()) {
             $result = false;
         }
     }
     echo json_encode($result);
 }