/** * Создание контента * @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]); } }
public function anyManageShop() { $product_types = ProductTypes::where('hidden', 0)->orderBy('name', 'ASC')->get(); $success_msg = []; $error_msg = []; $rules = ['product_name' => 'required', 'product_category' => 'required', 'short_description' => 'required', 'product_description' => 'required', 'price' => 'required', 'quantity' => 'required|numeric']; $validator = Validator::make(Input::all(), $rules); if (Request::method() == 'POST') { if (!$validator->fails()) { $category_select = Input::get('product_category'); $category = ProductTypes::find($category_select); if ($category) { /** @var Products $product */ $product = new Products(); $product->uid = Uuid::generate()->string; $product->name = Input::get('product_name'); $product->short_description = Input::get('short_description'); $product->description = Input::get('product_description'); $product->price_in_cents = Input::get('price') * 100; $product->quantity = Input::get('quantity'); $product->product_type_id = $category->id; $product->allow_review = 1; $product->save(); if ($product->save()) { if (Input::file('main_product_image')) { $filename = Input::file('main_product_image')->getClientOriginalName(); $destination = storage_path() . '/app/upload/'; $file_path = Input::file('main_product_image')->move($destination, $filename); // $diskLocal = Storage::disk('local'); $product_image = new ProductImages(); $product_image->url = $filename; $product_image->product_id = $product->id; $product_image->name = $filename; $product_image->is_primary = 1; $product_image->save(); } } $success_msg[] = 'Product Added!'; } else { $error_msg[] = 'Whoops! Sorry, product category not found'; } } else { return Redirect::back()->withErrors($validator->messages())->withInput(Input::all()); } } return View::make('shop.manage_store', ['product_types' => $product_types, 'success_msg' => $success_msg, 'error_msg' => $error_msg]); }
/** * 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]); } }
/** * 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]); } }
/** * 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]); } }
/** * 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]); } }
/** * 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]); } }
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]); } }
/** * Добавление товара * @return string */ public function actionAddProduct() { if (Yii::$app->getRequest()->getQueryParam('user')) { $user = Yii::$app->getRequest()->getQueryParam('user'); if (Yii::$app->getRequest()->getQueryParam('name') && Yii::$app->getRequest()->getQueryParam('cat')) { $product = new Products(); if (Categories::find()->where(['name' => Yii::$app->getRequest()->getQueryParam('cat')])->one()) { // return var_dump(Categories::find()->where(['name' => Yii::$app->getRequest()->getQueryParam('cat')])->one()->id); $product->cat_id = Categories::find()->where(['name' => Yii::$app->getRequest()->getQueryParam('cat')])->one()->id; } else { $product->cat_id = 63; } $product->name = Yii::$app->getRequest()->getQueryParam('name'); $product->currency = 35; $product->currency_out = 35; $product->photo = ''; $product->description = ''; $product->formatted_val = ''; $product->price = 0.0; //return var_dump($product); try { if ($product->save(false)) { return "<span style='color:green; font-size: 15px;'>Товар сохранен!</span>"; } // else return var_dump($product); } catch (\ErrorException $e) { return $e->getMessage(); } } return $this->renderPartial('add_product'); } }
public function addProduct($storeId, Request $request) { $store = UserStores::find($storeId); $user = Users::find($store->user_id); $product = new Products(); $product->product_name = $request->input('product_name'); $product->description = $request->input('description'); $product->display_description = $request->input('display_description'); $product->Author = $store->name; $product->retail = $request->input('retail'); $product->non_member = $request->input('retail'); $product->shipping_weight = $request->input('shipping_weight'); $product->member = $request->input('retail'); $product->cost_shipping = $request->input('cost_shipping'); $product->pay_bonus = 1; $product->physical_description = $request->input('physical_description'); $product->store_id = $store->id; $product->one_of_a_kind = $request->input('one_of_a_kind'); $product->product_category = $request->input('product_category'); $product->save(); $picture = $this->addProductImage($request, $product->id); if ($picture > '') { $product->image = $picture; $product->save(); } return redirect("store/{$store->id}"); }