Ejemplo n.º 1
0
 /**
  * Creates a new Product model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Product();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         if (isset($_POST['name']) && is_array($_POST['name'])) {
             foreach ($_POST['name'] as $lang => $val) {
                 $model->setName($lang, $val);
             }
         }
         if (isset($_POST['description']) && is_array($_POST['description'])) {
             foreach ($_POST['description'] as $lang => $val) {
                 $model->setDescription($lang, $val);
             }
         }
         if (isset($_POST['information']) && is_array($_POST['information'])) {
             foreach ($_POST['information'] as $lang => $val) {
                 $model->setInformation($lang, $val);
             }
         }
         $model->updateURLCode();
         return $this->redirect(['update', 'id' => $model->id, 'panel' => 'images']);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Creates a new Product model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  *
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Product();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Ejemplo n.º 3
0
 /**
  * Pjaxified version of ProductController actionCreate
  * @return partial
  */
 public function actionCreateProduct()
 {
     $model = new Product();
     if (Yii::$app->request->isPjax) {
         if ($model->load(Yii::$app->request->post()) && $model->save()) {
             $model = new Product();
         }
         return $this->renderPartial('_product_edit', ['model' => $model]);
     }
 }
Ejemplo n.º 4
0
 public function actionCreate()
 {
     $model = new Product();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['list']);
     } else {
         $model->status = Product::STATUS_ENABLED;
         return $this->render('create', ['model' => $model]);
     }
 }
Ejemplo n.º 5
0
 /**
  * @param $node
  * @return string|\yii\web\Response
  */
 public function actionCreate($node)
 {
     $model = new Product();
     $model->loadDefaultValues();
     $model->category_id = $node;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['list', 'node' => $node]);
     }
     return $this->render('create', ['model' => $model]);
 }
Ejemplo n.º 6
0
 /**
  * Creates a new Product model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Product();
     if ($model->load(Yii::$app->request->post())) {
         // var_dump($_POST);
         $this->isUploaded($model);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Ejemplo n.º 7
0
 /**
  * Creates a new Product model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $categories = Categories::find()->all();
     // need this for dropDownList in views/product/_form.php
     $model = new Product();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'itemId' => $model->item_id]);
     } else {
         return $this->render('create', ['model' => $model, 'categories' => $categories]);
     }
 }
Ejemplo n.º 8
0
 public function actionSearchProducts()
 {
     $modelForm = new Product();
     $results = null;
     if ($modelForm->load(Yii::$app->request->post())) {
         $results = $modelForm->giveAllProductsByName($modelForm->name);
         Yii::$app->session->setFlash('contactFormSubmitted');
         return $this->render('searchProducts', ['modelForm' => $modelForm, 'results' => $results]);
     } else {
         return $this->render('searchProducts', ['modelForm' => $modelForm, 'results' => $results]);
     }
 }
Ejemplo n.º 9
0
 /**
  * Creates a new Product model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $app = \Yii::$app;
     $model = new Product();
     $render = "render";
     if ($app->request->isPjax || $app->request->isAjax) {
         $render = "renderPartial";
     }
     if ($model->load($app->request->post()) && $model->save()) {
         $model = new Product();
     }
     return $this->{$render}('form', ['model' => $model]);
 }
Ejemplo n.º 10
0
 /**
  * Creates a new Product model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Product();
     if ($model->load(Yii::$app->request->post())) {
         $model->created_time = date("Y-m-d H:i:s");
         $model->last_update = $model->created_time;
         $model->user_id = \Yii::$app->user->id;
         Util::save($model);
         $model = new Product();
     }
     $searchModel = new ProductSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     return $this->render('create', ['model' => $model, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }
Ejemplo n.º 11
0
 public function store(Request $request)
 {
     $input = $request->json()->all();
     unset($input['categories']);
     $product = new Product($input);
     $product->save();
     if (($categories = $request->json()->get('categories')) && !empty($categories)) {
         if (is_string($categories)) {
             $categories = explode(',', $categories);
         }
         $product->categories()->attach($categories);
     }
     $product->load('categories');
     return response()->created($product);
 }
Ejemplo n.º 12
0
 /**
  * Creates a new Product model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Product();
     $model_can_save = false;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $model->fileImage = \yii\web\UploadedFile::getInstance($model, 'fileImage');
         if ($model->fileImage) {
             $model->fileImage->saveAs(Yii::getAlias('@uploadedfilesdir'));
         }
         $model_can_save = true;
         return $this->redirect(['view', 'id' => $model->product_id]);
     } else {
         return $this->render('create', ['model' => $model, 'model_can_save' => $model_can_save]);
     }
 }
Ejemplo n.º 13
0
 /**
  * Creates a new Product model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Product();
     $model->setScenario('create');
     if ($model->load(Yii::$app->request->post())) {
         $model->images = UploadedFile::getInstances($model, images);
         $model->image = FileUploader::upload(UploadedFile::getInstance($model, 'image'), 'product', $model->image);
         if ($model->validate()) {
             if ($model->save()) {
                 return $this->redirect(['index']);
             }
         }
     }
     return $this->render('create', ['model' => $model]);
 }
Ejemplo n.º 14
0
 /**
  * Creates a new Product model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Product();
     $model->scenario = 'create';
     if ($model->load(Yii::$app->request->post())) {
         $image1 = UploadedFile::getInstance($model, 'image1');
         if ($image1 != NULL) {
             $name1 = date('Y_m_d_H_i_s_') . $image1->baseName . '.' . $image1->extension;
             $model->image1 = $name1;
         }
         $image2 = UploadedFile::getInstance($model, 'image2');
         if ($image2 != NULL) {
             $name2 = date('Y_m_d_H_i_s_') . $image2->baseName . '.' . $image2->extension;
             $model->image2 = $name2;
         }
         $image3 = UploadedFile::getInstance($model, 'image3');
         if ($image3 != NULL) {
             $name3 = date('Y_m_d_H_i_s_') . $image3->baseName . '.' . $image3->extension;
             $model->image3 = $name3;
         }
         if ($model->save()) {
             if ($model->auction == "YES") {
                 $auction = new Auction();
                 $auction->product_id = $model->id;
                 $auction->value = $model->price;
                 $auction->save();
             }
             if ($image1 != NULL) {
                 $image1->saveAs('img/products/' . $name1);
             }
             if ($image2 != NULL) {
                 $image2->saveAs('img/products/' . $name2);
             }
             if ($image3 != NULL) {
                 $image3->saveAs('img/products/' . $name3);
             }
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Ejemplo n.º 15
0
 /**
  * Creates a new Product model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $this->checkLogin();
     $this->layout = 'admin';
     $model = new Product();
     $modelType = new Type();
     $allType = $modelType->getAllType();
     if ($model->load(Yii::$app->request->post())) {
         $model->image = UploadedFile::getInstances($model, 'image');
         foreach ($model->image as $file) {
             $file->saveAs('images/' . $file->baseName . '.' . $file->extension);
             $images[] = $file->baseName . '.' . $file->extension;
         }
         $model->image = implode(',', $images);
         $model->save();
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'allType' => $allType]);
     }
 }
 /**
  * Creates a new Product model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Product();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         // data product
         $data_product = $_POST['Product'];
         // name product
         foreach ($data_product as $vlProduct) {
             $name_product = $vlProduct;
         }
         // last id catalog
         $last_product = Product::find()->orderBy('id_product DESC')->one();
         $last = $last_product->id_product;
         // insert search_table
         $search_product = new SearchTable(['name_search' => $name_product, 'type_search' => '3', 'link_search' => $last]);
         $search_product->save();
         return $this->redirect(['view', 'id' => $model->id_product]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Ejemplo n.º 17
0
 /**
  * Creates a new Product model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Product();
     $attributes = Yii::$app->session->get(Product::className());
     if ($attributes) {
         $model->attributes = $attributes;
     }
     if ($model->load(Yii::$app->request->post())) {
         if (Yii::$app->request->getBodyParam('action')) {
             Yii::$app->session->set(Product::className(), $model->attributes);
             return $this->redirect(["supplier/create"]);
         } else {
             Yii::$app->session->remove(Product::className());
         }
         if ($model->save()) {
             $estimateEntry = Yii::$app->session->get(EstimateEntry::className());
             if ($estimateEntry) {
                 return $this->redirect(['estimate/create-entry', 'id' => $estimateEntry['estimate_id']]);
             }
             return $this->redirect(['view', 'id' => $model->id]);
         }
     }
     return $this->render('create', ['model' => $model]);
 }
Ejemplo n.º 18
0
 /**
  * Creates a new Product model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Product();
     $categories = Category::find()->orderBy('category_id')->all();
     $tax = Tax::find()->orderBy('tax_id')->all();
     $tax2 = Tax2::find()->orderBy('tax_id')->all();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->product_id]);
     } else {
         return $this->render('create', ['model' => $model, 'categories' => $categories, 'tax' => $tax, 'tax2' => $tax2]);
     }
 }