本文整理汇总了PHP中Product::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::save方法的具体用法?PHP Product::save怎么用?PHP Product::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Product
的用法示例。
在下文中一共展示了Product::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
public function setUp()
{
parent::setUp();
$this->product = Product::getNewInstance($this->rootCategory, 'test');
$this->product->save();
$this->group = ProductFileGroup::getNewInstance($this->product);
$this->group->save();
// create temporary file
file_put_contents($this->tmpFilePath, $this->fileBody);
}
示例2: setUp
public function setUp()
{
parent::setUp();
// Create some product
$this->product = Product::getNewInstance($this->rootCategory, 'test');
$this->product->save();
return;
// create new group
$dump = ProductRelationshipGroup::getNewInstance($this->product);
$dump->save();
}
示例3: setUp
public function setUp()
{
parent::setUp();
$this->specField = SpecField::getNewInstance($this->rootCategory, SpecField::DATATYPE_TEXT, SpecField::TYPE_TEXT_SELECTOR);
$this->specField->save();
$this->specFieldAutoIncrementNumber = $this->specField->getID();
$specFieldValue = SpecFieldValue::getNewInstance($this->specField);
$specFieldValue->save();
$this->specFieldValueAutoIncrementNumber = $specFieldValue->getID();
$this->product = Product::getNewInstance($this->rootCategory, 'test');
$this->product->save();
$this->productAutoIncrementNumber = $this->product->getID();
}
示例4: getAdminInterface
public function getAdminInterface()
{
$st = "select ecomm_product.id as product_id, ecomm_product.name as product_name,\n\t\t\t\tecomm_product.supplier as supplier_id, ecomm_supplier.name as supplier_name, ecomm_product.price as product_price\n\t\t\t\tfrom ecomm_product left join ecomm_supplier on ecomm_product.supplier = ecomm_supplier.id\n\t\t\t\torder by ecomm_supplier.name,ecomm_product.name";
$products = Database::singleton()->query_fetch_all($st);
$formPath = "/admin/EComm§ion=Plugins&page=ChangeProductPrice";
$form = new Form('change_product_prices', 'post', $formPath);
if ($form->validate() && isset($_REQUEST['submit'])) {
foreach ($products as $product) {
$ECommProduct = new Product($product['product_id']);
$ECommProduct->setPrice($_REQUEST['product_' . $product['product_id']]);
$ECommProduct->save();
}
return "Your products' prices have been changed successfully<br/><a href='{$formPath}'>Go back</a>";
}
$oldSupplier = 0;
$currentSupplier = 0;
$defaultValue = array();
foreach ($products as $product) {
$currentSupplier = $product['supplier_id'];
if ($oldSupplier != $currentSupplier) {
$form->addElement('html', '<br/><br/><hr/><h3>Supplier: ' . $product['supplier_name'] . '</h3>');
}
$form->addElement('text', 'product_' . $product['product_id'], $product['product_name']);
$defaultValue['product_' . $product['product_id']] = $product['product_price'];
$oldSupplier = $product['supplier_id'];
}
$form->addElement('submit', 'submit', 'Submit');
$form->setDefaults($defaultValue);
return $form->display();
}
示例5: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
//
// create the validation rules ------------------------
$rules = array('name' => 'required', 'descrption' => 'required');
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
// get the error messages from the validator
$messages = $validator->messages();
// redirect our user back to the form with the errors from the validator
return Redirect::route('product.create')->withErrors($validator);
} else {
if (Input::hasFile('image')) {
foreach (Input::file('image') as $image) {
$imagename = time() . $image->getClientOriginalName();
$uploadflag = $image->move('uploads', $imagename);
if ($uploadflag) {
$uploadedimages[] = $imagename;
}
}
$name = Input::get('name');
$description = Input::get('descrption');
$product = new Product();
$product->name = $name;
$product->productdes = $description;
$product->images = json_encode($uploadedimages);
$product->save();
return Redirect::route('product.index');
} else {
return Redirect::route('product.create')->withErrors('product image needed');
}
}
//end else
}
示例6: postCreate
public function postCreate()
{
$validator = Validator::make(Input::all(), Product::$rules);
if ($validator->passes()) {
$product = new Product();
$product->category_id = Input::get('category_id');
$product->title = Input::get('title');
$product->description = Input::get('description');
$product->price = Input::get('price');
// $image = Input::file('image');
// // $filename = date('Y-m-d-H:i:s')."-". $image->getClientOriginalName();
// $filename = time() . '.' . $image->getClientOriginalExtension();
// $product->image = 'img/products/'. $filename;
// // $path = public_path('img/products/' . $filename);
// $product->save();
// Image::make($image->getRealPath())->resize(468, 249)->save('/img/products/'. $filename);
$file = Input::file('image');
$orig_name = str_random(6) . $file->getClientOriginalName();
$dest_path = public_path() . "/img/products/";
$upload = $file->move($dest_path, $orig_name);
$product->image = "/img/products/" . $orig_name;
$product->save();
return Redirect::to('admin/products/index')->with('message', 'Product Created');
}
return Redirect::to('admin/products/index')->with('message', 'Something went wrong')->withErrors($validator)->withInput();
}
示例7: addProduct
/**
* Add product
*/
public function addProduct()
{
if (Auth::check()) {
$validator = Validator::make(Input::all(), array('name' => 'required', 'price' => 'required', 'description' => 'required', 'condition' => 'required', 'quantity' => 'required', 'brand' => 'required', 'image' => 'required|image|mimes:jpg,jpeg,png|max:6000', 'point' => 'required', 'product_code' => 'required|unique:products'));
if ($validator->fails()) {
return Redirect::route('add-product-page')->withErrors($validator)->withInput();
} else {
$file = Input::file('image');
$file_name = date('d-m-Y-h-i-s-') . $file->getClientOriginalName();
$destination = $destination = "assets/images/shop/";
$file->move($destination, $file_name);
$product = new Product();
$product->name = Input::get('name');
$product->slug = Str::slug(Input::get('name'));
$product->price = Input::get('price');
$product->description = Input::get('description');
$product->catagory_id = Input::get('catagory');
$product->subcatagory_id = Input::get('subcatagory');
$product->quantity = Input::get('quantity');
$product->product_condition = Input::get('condition');
$product->brand = Input::get('brand');
$product->image = $file_name;
$product->point = Input::get('point');
$product->product_code = Input::get('product_code');
$product->code = uniqid(str_random(9));
if ($product->save()) {
return Redirect::back()->with("event", '<p class="alert alert-success"><span class="glyphicon glyphicon-ok"></span> Product saved successfully.</p>');
}
return Redirect::back()->with("event", '<p class="alert alert-danger"><span class="glyphicon glyphicon-exclamation-sign"></span> Error occured. Please try after sometime</p>');
}
} else {
return Redirect::route('admin-login')->with('event', '<p class="alert alert-danger"><span class="glyphicon glyphicon-remove"></span> You are not loged in!</p>');
}
}
示例8: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
// se define la validacion de los campos
$rules = array('category_id' => 'array', 'name' => 'required|max:60', 'value' => 'numeric|required', 'cost' => 'numeric|required', 'enable' => 'in:SI,NO');
// Se validan los datos ingresados segun las reglas definidas
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return Redirect::back()->withInput()->withErrors($validator);
}
$product = new Product();
if (Input::get('category_id')) {
$product->category_id = Input::get('category_id');
}
if (Input::get('name')) {
$product->name = Input::get('name');
}
if (Input::get('description')) {
$product->description = Input::get('description');
}
if (Input::get('value')) {
$product->value = Input::get('value');
}
if (Input::get('cost')) {
$product->cost = Input::get('cost');
}
if (Input::get('enable')) {
$product->enable = Input::get('enable');
}
$product->save();
return Redirect::to('admin/product')->with('success_message', 'El registro ha sido ingresado correctamente.')->withInput();
}
示例9: saveProduct
public function saveProduct()
{
$data = Input::all();
if (!Auth::guest()) {
$validator = Validator::make($data, Product::$rules);
if ($validator->passes()) {
$user = Auth::user();
$product = new Product();
$product->user_id = $user->id;
$product->product_name = $data['product_name'];
$product->description = $data['description'];
$product->start_price = $data['start_price'];
$product->save();
if (isset($data['categories']) && !empty($data['categories'])) {
$product->categories()->attach($data['categories']);
}
if (Session::has('files')) {
$files = Session::get('files');
// get session files
foreach ($files as $key => $file) {
$directory_file = public_path() . '/product_images/' . $file;
if (File::exists($directory_file)) {
File::move($directory_file, public_path() . '/product_images/product_' . $product->id . '_' . $key . '.jpg');
}
}
Session::forget('files');
}
return Response::json(array('success' => true, 'product' => $product));
}
return Response::json(array('success' => false, 'type' => 'form_error', 'errors' => $validator->messages()));
}
return Response::json(array('success' => false, 'type' => 'log_error', 'error' => 'In order to save your product, please, log in!'));
}
示例10: postCreate
public function postCreate()
{
$validator = Validator::make(Input::all(), Product::$rules);
if ($validator->passes()) {
$product = new Product();
$product->title = Input::get('title');
$product->description = Input::get('description');
$id = Input::get('product_id');
$skuAsset = sprintf("%06s", $id);
$product->sku = 'INDE' . $skuAsset;
$product->category_id = Input::get('category_id');
$product->subcategory_id = Input::get('subcategory_id');
$product->price = Input::get('price');
$product->weight = Input::get('weight');
$product->supplier_id = Auth::user()->id;
$product->image = 'images/products/INDE' . $skuAsset;
$product->save();
$details = new Detail();
$details->details = Input::get('details');
$details->model = Input::get('model');
$details->brand = Input::get('brand');
$details->moredescription = Input::get('moredescription');
$details->product_id = Input::get('product_id');
$details->save();
return Response::json('success', 200);
} else {
return $validator->errors;
}
}
示例11: store
public function store()
{
$rules = array('code' => 'required', 'name' => 'required', 'mark' => 'required', 'price' => array('required', 'regex:/^\\d*(\\.\\d{2})?$/'), 'categories' => 'required', 'product_image' => 'mimes:jpeg,bmp,png');
$validator = Validator::make(Input::all(), $rules);
// process the login
if ($validator->fails()) {
return Redirect::to('admin/product/create')->withErrors($validator)->withInput();
} else {
// store
$filename = "";
if (Input::hasFile('product_image')) {
if (Input::file('product_image')->isValid()) {
Input::file('product_image')->move(ProductController::imagePath());
$filename = Input::file('product_image')->getClientOriginalName();
}
}
$product = new Product();
$product->code = Input::get('code');
$product->mark = Input::get('mark');
$product->name = Input::get('name');
if ($filename !== "") {
$product->image = ProductController::imagePath() . $filename;
}
$product->price = Input::get('price');
$product->save();
foreach (Input::get('categories') as $catId) {
DB::table('products_category')->insert(array('product_id' => Input::get('code'), 'category_id' => $catId));
}
// redirect
Session::flash('message', 'Successfully created product!');
return Redirect::to('admin/product');
}
}
示例12: add
/**
* Validates data submitted in the add form. If the validation fails,
* displays the add page. Otherwise, creates a new product, saves it and
* its ingredients to the database and redirects to the add page.
*/
public static function add()
{
$params = $_POST;
$attributes = array('product_name' => $params['product_name'], 'price' => $params['price'], 'category' => $params['category'], 'description' => $params['description']);
if (isset($params['customizable'])) {
$attributes['customizable'] = 'TRUE';
} else {
$attributes['customizable'] = 'FALSE';
}
if (isset($params['ingredients'])) {
$attributes['ingredients'] = $params['ingredients'];
}
$validator = self::product_validator($attributes);
if ($validator->validate()) {
$product = new Product($attributes);
$product->save();
if (isset($params['ingredients'])) {
self::set_product_ingredients($product, $params['ingredients']);
}
Redirect::to($params['redirect'], array('message' => 'Tuote lisätty!'));
} else {
$ingredients = Ingredient::findByCategory($attributes['category']);
View::make('product/add.html', array('ingredients' => $ingredients, 'errors' => $validator->errors(), 'product' => $attributes));
}
}
示例13: setUp
protected function setUp()
{
$firstProduct = new Product();
$firstProduct->name = "wooden chair 2x";
$firstProduct->description = "a wooden chair made of wood";
$firstProduct->quantity = 50;
$firstProduct->price = 3000;
$firstProduct->sku = uniqid();
if (!$firstProduct->save()) {
throw new Exception(CHtml::errorSummary($firstProduct));
} else {
$this->productModels[] = $firstProduct;
}
$secondProduct = new Product();
$secondProduct->name = "wooden chair 3x";
$secondProduct->description = "a wooden chair made of wood but with color";
$secondProduct->quantity = 60;
$secondProduct->price = 4000;
$secondProduct->sku = uniqid();
if (!$secondProduct->save()) {
throw new Exception(CHtml::errorSummary($secondProduct));
} else {
$this->productModels[] = $secondProduct;
}
/*create product model*/
parent::setUp();
}
开发者ID:kevindaus,项目名称:Order-Billing-Inventory-System-Marcials-Furniture,代码行数:27,代码来源:InvoiceDataPersistorTest.php
示例14: actionUpload_product
public function actionUpload_product()
{
if (Yii::$app->request->isAjax) {
$model = new ProductCategory();
$Product = new Product();
$ProductImageRel = new ProductImageRel();
$ProductCategoryRel = new ProductCategoryRel();
$model_cat_title = UploadedFile::getInstance($model, 'cat_title');
$time = time();
$model_cat_title->saveAs('product_uploads/' . $time . $model_cat_title->baseName . '.' . $model_cat_title->extension);
if ($model_cat_title) {
$response = [];
$Product->title = $_POST['title'];
$Product->desc = $_POST['desc'];
$Product->status = 1;
if ($Product->save()) {
$ProductCategoryRel->category_id = $_POST['id'];
$ProductCategoryRel->product_id = $Product->id;
$ProductImageRel->product_id = $Product->id;
$ProductImageRel->image = $time . $model_cat_title->baseName . '.' . $model_cat_title->extension;
if ($ProductCategoryRel->save() && $ProductImageRel->save()) {
$response['files'][] = ['name' => $time . $model_cat_title->name, 'type' => $model_cat_title->type, 'size' => $model_cat_title->size, 'url' => Url::base() . '/product_uploads/' . $time . $model_cat_title->baseName . '.' . $model_cat_title->extension, 'deleteUrl' => Url::to(['delete_uploaded_file', 'file' => $model_cat_title->baseName . '.' . $model_cat_title->extension]), 'deleteType' => 'DELETE'];
$response['base'] = $time . $model_cat_title->baseName;
$response['view'] = $this->renderAjax('uploaded_product', ['url' => Url::base() . '/product_uploads/' . $time . $model_cat_title->baseName . '.' . $model_cat_title->extension, 'basename' => $time . $model_cat_title->baseName, 'id' => $ProductImageRel->id, 'model' => $Product]);
}
} else {
$response['errors'] = $product->getErrors();
}
return json_encode($response);
}
}
}
示例15: post
public function post()
{
$post = Input::all();
$validator = Product::validate($post);
$productId = $post['id'];
if ($validator->fails()) {
return Redirect::to('productos/' . $productId)->withErrors($validator)->withInput();
} else {
$product = self::__checkExistence($productId);
$isNew = false;
if (!$productId) {
$product = new Product();
$isNew = true;
}
$product->name = $post['name'];
$product->description = $post['description'];
$product->code = $post['code'];
$product->minimum_stock = $post['minimum_stock'];
$product->cost = str_replace(',', '.', $post['cost']);
$product->save();
if ($isNew) {
Globals::triggerAlerts(4, array('productId' => $product->id));
}
if ($post['status'] == 'inactive') {
$product->delete();
} else {
if ($product->trashed()) {
$product->restore();
}
}
Session::flash('success', 'Producto guardado correctamente.');
return Redirect::to('productos');
}
}