当前位置: 首页>>代码示例>>PHP>>正文


PHP Product::findOne方法代码示例

本文整理汇总了PHP中app\models\Product::findOne方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::findOne方法的具体用法?PHP Product::findOne怎么用?PHP Product::findOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\models\Product的用法示例。


在下文中一共展示了Product::findOne方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getProduct

 /**
  * @return Product
  */
 public function getProduct()
 {
     if (is_null($this->_product)) {
         $this->_product = Product::findOne($this->product_id);
     }
     return $this->_product;
 }
开发者ID:rcjusto,项目名称:simplestore,代码行数:10,代码来源:ShoppingCart.php

示例2: actionList

 /**
  * @param $node
  * @return string
  * @throws NotFoundHttpException
  */
 public function actionList($node)
 {
     /** @var Order $order */
     $order = Order::findOne($node);
     if (!$order) {
         throw new NotFoundHttpException();
     }
     $newProduct = new AddProductForm();
     if ($newProduct->load(\Yii::$app->request->post()) && $newProduct->validate()) {
         /** @var OrderData $existingLine */
         $existingLine = OrderData::find()->where(['product_id' => $newProduct->product_id, 'order_id' => $order->id])->one();
         if ($existingLine) {
             $existingLine->quantity += $newProduct->quantity;
             $existingLine->save();
         } else {
             /** @var Product $product */
             $product = Product::findOne($newProduct->product_id);
             if ($product) {
                 $line = new OrderData(['product_id' => $product->id, 'quantity' => $newProduct->quantity, 'price' => $product->price]);
                 $order->link('orderLines', $line);
             }
         }
     }
     return $this->render('list', ['order' => $order, 'newProduct' => $newProduct]);
 }
开发者ID:vetoni,项目名称:toko,代码行数:30,代码来源:OrderItemsController.php

示例3: process

 public function process()
 {
     if ($this->validate()) {
         if (!is_null($this->importFile)) {
             $imported = 0;
             $errors = 0;
             if (($handle = fopen($this->importFile->tempName, "r")) !== FALSE) {
                 $keys = fgetcsv($handle);
                 while (($row = fgetcsv($handle)) !== FALSE) {
                     $data = [];
                     for ($c = 0; $c < count($row); $c++) {
                         $data[$keys[$c]] = $row[$c];
                     }
                     /** @var Product $product */
                     $product = array_key_exists('id', $data) && $data['id'] ? Product::findOne($data['id']) : new Product();
                     if ($product->from_array($data)) {
                         $imported++;
                     } else {
                         $errors++;
                     }
                 }
                 fclose($handle);
             }
             return "Imported: {$imported}, Errors: {$errors}";
         } else {
             return "File not found";
         }
     } else {
         return "Invalid File";
     }
 }
开发者ID:rcjusto,项目名称:simplestore,代码行数:31,代码来源:ProductImportForm.php

示例4: actionAjaxAdd

 public function actionAjaxAdd()
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     $request = Yii::$app->request;
     $id = $request->get('id');
     $color = $request->get('color');
     $size = $request->get('size');
     $number = $request->get('num');
     $model = Product::findOne($id);
     if (!Yii::$app->session->isActive) {
         Yii::$app->session->open();
     }
     $cart = new Cart();
     $cart->session_id = Yii::$app->session->id;
     $cart->user_id = Yii::$app->user->isGuest ? 0 : Yii::$app->user->id;
     $cart->product_id = $id;
     $cart->name = $model->name;
     $cart->color = $color;
     $cart->size = $size;
     $cart->number = $number;
     $cart->price = $model->price;
     if ($cart->save()) {
         return ['status' => 1, 'productId' => $id, 'size' => $size, 'color' => $color];
     } else {
         return ['status' => -2, 'productId' => $id, 'size' => $size, 'color' => $color];
     }
 }
开发者ID:irying,项目名称:artist,代码行数:27,代码来源:CartController.php

示例5: findModel

 /**
  * Finds the Product model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Product the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Product::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('Продукт с номером ID ' . $id . ' не обнаружен.');
     }
 }
开发者ID:GalkinDmitriy,项目名称:evalotta,代码行数:15,代码来源:ProductController.php

示例6: findModel

 /**
  * Finds the Product model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Product the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Product::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
开发者ID:frankpaul142,项目名称:chaide,代码行数:15,代码来源:ProductController.php

示例7: actionUpdate

 public function actionUpdate($itemId, $quantity)
 {
     $product = Product::findOne($itemId);
     if ($product) {
         \Yii::$app->cart->update($product, $quantity);
         $this->redirect(['cart/list']);
     }
 }
开发者ID:asopin,项目名称:shop,代码行数:8,代码来源:CartController.php

示例8: actionUpdate

 public function actionUpdate($id, $quantity)
 {
     $product = Product::findOne($id);
     if ($product) {
         $this->_cart->update($product, $quantity);
         $this->redirect(['cart/list']);
     }
 }
开发者ID:absol3112,项目名称:sonneboutique,代码行数:8,代码来源:CartController.php

示例9: actionDelete

 /**
  * @param $id
  * @return \yii\web\Response
  * @throws NotFoundHttpException
  * @throws \Exception
  */
 public function actionDelete($id)
 {
     /** @var Product $model */
     $model = Product::findOne($id);
     if (!$model) {
         throw new NotFoundHttpException();
     }
     $model->delete();
     return $this->redirect(['list', 'node' => $model->category_id]);
 }
开发者ID:vetoni,项目名称:toko,代码行数:16,代码来源:ProductController.php

示例10: actionEditProduct

 /**
  * Ajaxified version of ProductController actionEdit
  * @return partial
  */
 public function actionEditProduct($id)
 {
     $model = Product::findOne($id);
     if (Yii::$app->request->isAjax || Yii::$app->request->isPjax) {
         if ($model->load(Yii::$app->request->post()) && $model->save()) {
             $model = new Product();
         }
         return $this->renderPartial('_product_edit', ['model' => $model]);
     }
 }
开发者ID:secondsano,项目名称:mebel,代码行数:14,代码来源:AdminController.php

示例11: findModel

 public function findModel($id)
 {
     $search = new Product();
     $search->scenario = Product::SCENARIO_READ;
     if (($model = $search->findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
开发者ID:vodas,项目名称:praktykigda,代码行数:10,代码来源:ProductCRUDContainer.php

示例12: actionAddToCart

 public function actionAddToCart($id)
 {
     $cart = new ShoppingCart();
     $model = Product::findOne($id);
     if ($model) {
         $cart->put($model, 1);
         return $this->redirect(['cart-view']);
     }
     throw new NotFoundHttpException();
 }
开发者ID:bokhonok-t,项目名称:yii2_e-shop,代码行数:10,代码来源:SiteController.php

示例13: actionProduct

 public function actionProduct()
 {
     $request = Yii::$app->request;
     $product = null;
     if ($code = $request->get('code')) {
         $product = Product::find()->where(['url_code' => $code])->one();
     }
     if (is_null($product) && ($id = $request->get('id'))) {
         $product = Product::findOne($id);
     }
     if (!is_null($product)) {
         return $this->render('product', ['model' => $product]);
     } else {
         return $this->goHome();
     }
 }
开发者ID:rcjusto,项目名称:simplestore,代码行数:16,代码来源:CatalogController.php

示例14: exportRestaurantMenuToCsv

 public function exportRestaurantMenuToCsv($id)
 {
     $restaurantName = Restaurant::findOne(['restaurant_id' => $id])->name;
     Yii::$app->params['uploadPath'] = Yii::$app->basePath . '/web/upload/';
     $string = "name, description, price \n";
     $product = null;
     foreach (Warehouse::find()->where(['restaurant_id' => $id])->batch(1) as $warehouse) {
         try {
             $product = Product::findOne(['product_id' => $warehouse[0]->product_id]);
             $string .= '"' . $product->name . '","' . $product->description . '","' . $warehouse[0]->price . '"';
             $string .= "\n";
         } catch (Exception $e) {
         }
     }
     $path = $this->saveStringToCsvFile($string, $restaurantName);
     $this->giveUserFile($path);
 }
开发者ID:vodas,项目名称:praktykigda,代码行数:17,代码来源:FileDownload.php

示例15: validateProduct

 /**
  * Validates product
  */
 public function validateProduct()
 {
     if (!Product::findOne($this->product_id)) {
         $this->addError('product_id', \Yii::t('app', 'Product does not exist.'));
     }
 }
开发者ID:vetoni,项目名称:toko,代码行数:9,代码来源:AddProductForm.php


注:本文中的app\models\Product::findOne方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。