Пример #1
0
 /**
  * Создание контента
  * @return string
  */
 public function actionCreate()
 {
     $model = new Products();
     $uploadImg = new UploadForm();
     if (Yii::$app->request->isPost) {
         $uploadImg->img = UploadedFile::getInstance($uploadImg, 'img');
         if ($uploadImg->img && $uploadImg->validate()) {
             $uploadImg->img->saveAs('uploads/' . Yii::$app->translater->translit($uploadImg->img->baseName) . '.' . $uploadImg->img->extension);
         } else {
             print_r($uploadImg->getErrors());
         }
     }
     if ($model->load(Yii::$app->request->post())) {
         $model->name = Yii::$app->request->post('Products')['name'];
         $model->cat_id = Yii::$app->request->post('Products')['cat_id'];
         $model->price = Yii::$app->request->post('Products')['price'];
         $model->description = Yii::$app->request->post('Products')['description'];
         if (isset($uploadImg->img)) {
             $model->photo = Url::base() . 'uploads/' . Yii::$app->translater->translit($uploadImg->img->baseName) . '.' . $uploadImg->img->extension;
         }
         $model->save();
         return $this->redirect(Url::toRoute('products/index'));
     } else {
         return $this->render('_form', ['model' => $model, 'uploadImg' => $uploadImg]);
     }
 }
Пример #2
0
 public function actionCreate($parent_id)
 {
     @session_start();
     if (!isset($_SESSION['cat']) or !isset($_SESSION['cat_r'])) {
         return $this->redirect('zapchasti');
     }
     $model = new Products();
     if ($model->load(Yii::$app->request->post())) {
         $model->imageFile = UploadedFile::getInstance($model, 'imageFile');
         if ($model->validate()) {
             if (!empty($model->imageFile)) {
                 $model->upload();
                 $model->image = md5($model->imageFile->baseName . date("Y-m-d-H-i-s")) . '.' . $model->imageFile->extension;
             }
             $model->cat_id = $parent_id;
             if ($model->save()) {
                 $last_id = Yii::$app->db->lastInsertID;
                 foreach (Yii::$app->request->post('character') as $key => $value) {
                     $model1 = new CharacteristicsProducts();
                     $model1->character_id = $key;
                     $model1->product_id = $last_id;
                     $model1->value = empty($value) ? 'none' : $value;
                     $model1->save();
                 }
                 return $this->redirect('create?parent_id=' . $parent_id);
             }
             // form inputs are valid, do something here
         }
     }
     $parent = ModArendaTree::findOne(['id' => $parent_id]);
     return $this->render('create', ['model' => $model, 'parent' => $parent]);
 }
Пример #3
0
 /**
  * Creates a new Products model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Products();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->No]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Пример #4
0
 /**
  * Creates a new Products model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Products();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'product_id' => $model->product_id, 'category_id' => $model->category_id, 'manufacturer_id' => $model->manufacturer_id, 'size_id' => $model->size_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Пример #5
0
 /**
  * Creates a new Products model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Products();
     $commodityArray = $this->getAllSection();
     if ($model->load(Yii::$app->request->post()) && $model->beforeSave(true) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'commodityArray' => $commodityArray]);
     }
 }
Пример #6
0
 /**
  * Creates a new Products model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Products();
     $brands = Brands::find()->all();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'brands' => $brands]);
     }
 }
Пример #7
0
 /**
  * Creates a new Products model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     if (Yii::$app->user->can('create-product')) {
         $model = new Products();
         if ($model->load(Yii::$app->request->post()) && $model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     } else {
         throw new \yii\web\ForbiddenHttpException();
     }
 }
 /**
  * Creates a new Products model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Products();
     $imageModel = new ProductImages(['scenario' => 'create']);
     $tagsModel = new ProductTags();
     $toppingsModel = new ProductToppings();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         if (!is_dir($this->imagePath . DIRECTORY_SEPARATOR . $model->slug)) {
             mkdir($this->imagePath . DIRECTORY_SEPARATOR . $model->slug, 0755, true);
         }
         $imageModel->load(\Yii::$app->request->getBodyParams());
         $file = UploadedFile::getInstance($imageModel, 'image');
         $fileDir = $this->imagePath . DIRECTORY_SEPARATOR . $model->slug . DIRECTORY_SEPARATOR;
         $file->saveAs($fileDir . $file->getBaseName() . "." . $file->getExtension());
         $save = Image::open($fileDir . $file->getBaseName() . "." . $file->getExtension())->zoomCrop(365, 365)->merge(Image::open($this->defaultImagePath . "/logo.png")->cropResize(100, 100), 10, 10)->save($fileDir . $file->getBaseName() . "_thumb." . $file->getExtension(), $file->getExtension(), 80);
         $imageModel->saveImages($model->slug . "/" . $file->getBaseName() . "." . $file->getExtension(), $model->slug . "/" . $file->getBaseName() . "_thumb." . $file->getExtension(), $model->id);
         $tagsModel->saveTags($_POST["ProductTags"]["tag_name"], $model->id);
         $toppingsModel->saveToppings($_POST["ProductToppings"], $model->id);
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['parents' => ArrayHelper::map(ProductCategories::find()->orderBy('title')->all(), 'id', 'title'), 'model' => $model, 'imageModel' => $imageModel, 'tagsModel' => $tagsModel, 'toppingsModel' => $toppingsModel]);
     }
 }
Пример #9
0
 public function actionPurchase()
 {
     $new_product = new Products();
     if ($new_product->load(Yii::$app->request->post()) && $new_product->save()) {
         return $this->redirect(['index']);
     } else {
         return $this->render('purchase', ['new_product' => $new_product]);
     }
 }