public function store(EditProductRequest $request) { $product = new Product(); $product->fill($request->only($product->getFillable())); $product->save(); return redirect()->route('product.index')->with('success_message', 'The product has been successfully saved.'); }
/** * 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]); } }
/** * * @param $item */ public function createItem($item) { $product = new Product(); $product->name = $item['name']; $product->description = $item['description']; $product->price = $item['price']; $product->sell_price = $item['sell_price']; $product->created = date('Y-m-d H:i:s'); $product->updated = date('Y-m-d H:i:s'); $product->save(); //update image after save product if (isset($item['image']) && $item['image'] !== 'undefined') { $this->updateImage($item['image'], $product->id); } //update description with image if (!empty($item['description'])) { $this->updateDescWithImg($item['description'], $product->id); } //add tags if (!empty($item['tags'])) { foreach ($item['tags'] as $k => $v) { $product->tag()->attach($v); } } }
public function uploadMenuJson($restaurant_id) { $col0 = "col_0"; $col1 = "col_1"; $col2 = "col_2"; $warehouse = null; $product = null; Yii::$app->params['uploadPath'] = Yii::$app->basePath . '/web/upload/'; $this->jsonFile = UploadedFile::getInstance($this, 'jsonFile'); $this->jsonFile->saveAs(Yii::$app->params['uploadPath'] . $this->jsonFile->baseName . '.' . $this->jsonFile->extension); $json = json_decode(file_get_contents(Yii::$app->params['uploadPath'] . $this->jsonFile), true); $product_id = Product::find()->orderBy(['product_id' => SORT_DESC])->one()->product_id; $product_id++; foreach ($json as $array) { $warehouse = new Warehouse(); $product = new Product(); $product->name = $array[$col0]; $product->description = $array[$col1]; $product->save(); $warehouse->restaurant_id = $restaurant_id; $warehouse->product_id = $product_id; $warehouse->price = $array[$col2]; $warehouse->save(); $product_id++; } return true; }
public function postCreate() { $validator = Validator::make(Input::all(), Product::$rules); if ($validator->passes()) { $product = new Product(); $product->name = Input::get('name'); $product->category_id = Input::get('category_id'); $product->short_description = Input::get('short_description'); $product->long_description = Input::get('long_description'); $product->is_discount = Input::get('is_discount'); $product->discount = Input::get('discount'); $product->count_for_discount = Input::get('count_for_discount'); $product->is_default_discount = Input::get('is_default_discount'); $product->default_discount = Input::get('default_discount'); $product->price = Input::get('price'); $product->amount = Input::get('amount'); $product->yellow_qty = Input::get('yellow_qty'); $product->red_qty = Input::get('red_qty'); $product->code_1c = Input::get('code_1c'); $product->article = Input::get('article'); $product->availability = Input::get('availability'); $product->save(); return Redirect::to("admin/products/edit/{$product->id}")->with('message', "Продукт {$product->name} создан"); } return Redirect::back()->with('message', 'Ошибка сохранения')->withErrors($validator)->withInput(); }
/** * 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]); } }
public function setUp() { parent::setUp(); $this->shared('product', function () { $product = new Product(["product_name" => "iPhone 6", "product_desc" => "iPhone 6", "status" => "available", "options" => [["name" => "颜色", "options" => ["深空灰", "银色", "金色"]], ["name" => "容量", "options" => ["16GB", "64GB", "128GB"]]], "specifications" => [["attr_name" => "高度", "attr_group" => "重量和尺寸", "attr_value" => "138.1 毫米(5.44 英寸)"], ["attr_name" => "宽度", "attr_group" => "重量和尺寸", "attr_value" => "67.0 毫米 (2.64 英寸)"], ["attr_name" => "厚度", "attr_group" => "重量和尺寸", "attr_value" => "6.9 毫米 (0.27 英寸)"], ["attr_name" => "重量", "attr_group" => "重量和尺寸", "attr_value" => "129 克 (4.55 盎司)"]]]); $product->save(); return $product; }); }
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]); } }
/** * 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]); } }
/** * @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]); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(UpdateProductRequest $request, Product $product) { $data = $request->input(); $product->fill($data); $product->save(); $this->savePhoto($product, $request); $product->categories()->detach($product->categories()->lists('id')->toArray()); $product->categories()->attach($data['categories']); return Redirect()->route('home'); }
public function create_submit() { $product = new Product(); $product->name = \Request::get('name'); $product->desc = \Request::get('desc'); $product->quantity = \Request::get('quantity'); $product->user_id = \Auth::user()->id; $product->status = 'SALE'; $product->save(); return \Redirect()->action('ProductController@index'); }
/** * 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]); } }
protected function fakeProduct() { $fakeProduct = new Product(); $fakeProduct->serial_number = "P1284724"; $fakeProduct->primary_name = "Fake Product"; $fakeProduct->product_type_id = $this->fakeProductType()->product_type_id; $fakeProduct->currency_id = $this->fakeCurrency()->currency_id; $fakeProduct->client_id = $this->fakeClient()->client_id; $fakeProduct->supplier_id = $this->fakeSupplier()->supplier_id; $fakeProduct->save(); return $fakeProduct; }
/** * Store a newly created resource in storage. * * @return Response */ public function store(Request $request) { $product = new Product(); $product->name = $request->input('name'); $product->price = $request->input('price'); $product->description = $request->input('description'); $product->save(); for ($i = 0; $i < $request->input('stock'); $i++) { $item = new ProductItem(); $item->code = date('YmdHis') . '.' . $i; $item = $product->item()->save($item); } }
/** * 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]); }
private function createAjax() { $data = Yii::$app->request->post(); $model = new Product(['scenario' => Product::SCENARIO_CREATE]); foreach ($data['Product'] as $key => $value) { $model->{$key} = $value; } if ($model->validate()) { return $model->save() ? true : ErrorHelper::errorsToString($model->errors); } else { return ErrorHelper::errorsToString($model->errors); } }
public function run() { DB::table('products')->truncate(); $faker = Faker\Factory::create(); $lorem = new Faker\Provider\Lorem($faker); $random = new Faker\Provider\Base($faker); for ($i = 0; $i < 500; $i++) { $name = $lorem->word(); $product = new Product(); $product->slug = Str::slug($name); $product->name = ucfirst($name); $product->price = $random->randomNumber(2); $product->save(); } }
/** * 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]); } }
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); }
public function setUp() { parent::setUp(); $this->resetEvents('App\\Models\\Product', 'App\\Models\\ProductStock', 'App\\Models\\ProductPhoto', 'App\\Models\\UploadFile'); $this->shared('product', function () { $product = new Product(["product_name" => "iPhone 6", "product_desc" => "iPhone 6", "status" => "available", "options" => [["name" => "颜色", "options" => ["深空灰", "银色", "金色"]], ["name" => "容量", "options" => ["16GB", "64GB", "128GB"]]], "specifications" => [["attr_name" => "高度", "attr_group" => "重量和尺寸", "attr_value" => "138.1 毫米(5.44 英寸)"], ["attr_name" => "宽度", "attr_group" => "重量和尺寸", "attr_value" => "67.0 毫米 (2.64 英寸)"], ["attr_name" => "厚度", "attr_group" => "重量和尺寸", "attr_value" => "6.9 毫米 (0.27 英寸)"], ["attr_name" => "重量", "attr_group" => "重量和尺寸", "attr_value" => "129 克 (4.55 盎司)"]]]); $product->save(); return $product; }); $this->shared('stock', function () { return $this->product->stocks()->save(new ProductStock(["option" => ["深空灰", "16GB"], "sku" => uniqid(), "stocks" => 100, "price" => 5288])); $stock->save(); return $stock; }); }
/** * @param Request $request * @return \Illuminate\Http\JsonResponse */ public function addProduct(Request $request) { $prod_name = $request->input('name'); $type = $request->input('type'); $dist_id = $request->input('dist_id'); $prod = new Product(); $prod->name = $prod_name; $prod->type = $type; $prod->distributor_id = $dist_id; if ($prod->save()) { $prod->distributor_name = Distributor::where('id', '=', $dist_id)->get(); if ($prod->distributor_name->count()) { $prod->distributor_name = $prod->distributor_name->first()->name; } return response()->json(['added' => true, 'product' => $prod]); } }
/** * Store a newly created resource in storage. * * @return Response */ public function store(Product $product, Request $request) { //$id = $request->route('products'); //dd($id); $validationRules = ['name' => 'required|alpha_spaces_numbers|max:35|unique:products', 'article' => 'required|alpha_spaces_numbers|max:15', 'description' => 'required|alpha_spaces_numbers', 'condition_id' => 'required|integer']; $depos = Stantion::all(); foreach ($depos as $depo) { $validationRules['price' . $depo->id] = 'required|numeric'; $validationRules['amount' . $depo->id] = 'required|numeric'; $validationRules['vat' . $depo->id] = 'required|numeric'; } $v = Validator::make($request->all(), $validationRules); if ($v->fails()) { return redirect()->back()->withErrors($v->errors())->withInput(); } DB::transaction(function () use($product, $request, $depos) { $product->article = $request->article; $product->name = $request->name; $product->description = $request->description; $product->condition_id = $request->condition_id; if (!(int) $request->category_id) { $product->category_id = null; } else { $product->category_id = $request->category_id; } $product->save(); $priceIdArr = []; foreach ($depos as $depo) { $price = new Price(); $priceInputName = 'price' . $depo->id; $priceInputAmount = 'amount' . $depo->id; $priceInputVAT = 'vat' . $depo->id; $price->price = $request->{$priceInputName}; $price->amount = $request->{$priceInputAmount}; $price->nds = $request->{$priceInputVAT}; $price->save(); $depo->price()->attach($price->id); $priceIdArr[] = $price->id; } $product->price()->sync($priceIdArr); }); return redirect('products')->with('alert-success', 'Товар успешно добавлен!'); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $input = $request->all(); $rules = ['product_name' => 'required', 'price' => 'numeric', 'sku' => 'max:30']; $validation = Validator::make($input, $rules); if ($validation->fails()) { return back()->withInput()->withErrors($validation); } $product = new Product(); $product->product_name = $input['product_name']; $product->sku = $input['sku']; $product->price = $input['price']; $product->product_description = $input['product_description']; if ($product->save()) { return back()->with('success', 'Product Created'); } else { return back()->withInput()->with('error', 'Product failed to be created. Please try again.'); } }
/** * Untuk menyimpan data product * * @param Request $request [description] * @return [type] [description] */ public function store(Request $request, Supplierable $supplier) { $this->validate($request, ['code' => 'required', 'name' => 'required', 'description' => 'required', 'price' => 'required', 'category_id' => 'required']); $data = $request->only('code', 'name', 'description', 'price', 'category_id'); if (is_string($request->get('tags'))) { $tags = explode(',', $request->get('tags')); } else { $tags = $request->get('tags', []); } $product = new Product(); $product->fill($data); $product->supplier()->associate($supplier); $product->save(); $this->productRepository->saveTags($product, $tags); if ($product) { return ['status' => 'success', 'message' => 'Product has successfully added.', 'product' => $product]; } else { return ['status' => 'failed', 'message' => 'Product has failed to be added.']; } }
/** * 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]); } }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(ProductRequest $request) { $product = new Product(); $product->title = $request->input('title'); $product->product_type_id = $request->input('product_type_id'); $product->length = $request->input('length'); $product->diameter = $request->input('diameter'); $product->weight = $weight = $request->input('weight'); if (!is_numeric($weight)) { $nmub = explode('/', $weight); $product->weight = $nmub[1] / $nmub[0]; } $product->color = $request->input('color'); $product->wholesale_price = $request->input('wholesale_price'); $product->retail_price = $request->input('retail_price'); $product->status = $request->input('status'); $product->created_at = time(); $product->created_by = Auth::user()->id; $product->save(); Session()->flash('flash_message', 'Data has been Saved'); return redirect('products'); }
/** * Save a product. * * @return Redirect */ public function store(Request $request) { // store $lang = $request->session()->get('language'); $product = new Product(); $product->shop_id = $request->shop_id; $product->slug = $request->slug; $product->sku = $request->sku; $product->categories = $request->categories; $product->price = $request->price; $product->rrp = $request->rrp; $product->salePrice = $request->salePrice; $data = $request->except(['shop_id', 'categories', 'slug', '_token', '_method', 'price', 'rrp', 'salePrice']); $product->{$lang} = $data; if ($lang == config('app.locale')) { $product->default = $data; } $product->save(); // add product id to each category if ($request->has('categories')) { $categories = $request->categories; foreach ($categories as $category) { $c = Category::find($category); $products = $c->products; if (!empty($products)) { array_push($products, $product->id); $c->products = array_unique($products); } else { $c->products = [$product->id]; } $c->save(); } } // redirect $request->session()->flash('success', trans('products.product') . ' ' . trans('crud.created')); return redirect('admin/products/' . $product->id . '/edit'); }
/** * 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]); }
/** * Toggle pin product * * @param int $userId * @param App\Models\Product $product * * return array */ protected function _togglePin($userId, $product) { $pin = $product->pin; $pinned = false; if ($pin === null) { $pin = new Pin(); $pin->product_id = $product->id; $pin->user_id = json_encode([$userId => $userId]); $product->total_pin = (int) $product->total_pin + 1; $pinned = true; } else { $uidArray = json_decode($pin->user_id, true); if (isset($uidArray[$userId])) { unset($uidArray[$userId]); $product->total_pin = ($p = (int) $product->total_pin > 0) ? $p - 1 : $p; } else { $uidArray[$userId] = $userId; $product->total_pin = (int) $product->total_pin + 1; $pinned = true; } $pin->user_id = json_encode($uidArray); } $product->save(); $pin->save(); return ['isPinned' => $pinned, 'totalPin' => $product->total_pin]; }