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


PHP Product::find方法代码示例

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


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

示例1: getPrice

 public function getPrice($id)
 {
     foreach (Product::find('price')->where(['id' => $id])->all() as $product) {
         $productPrice = $product['price'];
     }
     return $productPrice;
 }
开发者ID:royutoan,项目名称:pianodanang,代码行数:7,代码来源:Product.php

示例2: actionIndex

 /**
  * Lists all Images models.
  * @return mixed
  */
 public function actionIndex($itemId)
 {
     if (!Product::find()->where(['item_id' => $itemId])->exists()) {
         throw new NotFoundHttpException();
     }
     $form = new MultipleUploadForm();
     $searchModel = new ImagesSearch();
     $searchModel->item_id = $itemId;
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     if (Yii::$app->request->isPost) {
         $form->files = UploadedFile::getInstances($form, 'files');
         if ($form->files && $form->validate()) {
             foreach ($form->files as $file) {
                 $images = new Images();
                 $images->item_id = $itemId;
                 if ($images->save()) {
                     // writes file name to images table
                     $images->big_image = $images->getUrl();
                 }
                 if ($images->save()) {
                     // saves file to folder
                     $file->saveAs($images->getPath());
                 }
             }
         }
     }
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'uploadForm' => $form]);
 }
开发者ID:asopin,项目名称:shop,代码行数:32,代码来源:ImagesController.php

示例3: actionView

 public function actionView($slug = null)
 {
     $model = Product::find()->bySlug($slug)->one();
     $productByCategory = Product::find()->byCategory($model->category_id)->limit(4)->all();
     $productByProduce = Product::find()->byProducer($model->producer_id)->limit(4)->all();
     return $this->render('view', ['model' => $model, 'productByCategory' => $productByCategory ? ['category' => $model->category, 'data' => $productByCategory] : null, 'productByProduce' => $productByProduce ? ['producer' => $model->producer, 'data' => $productByProduce] : null]);
 }
开发者ID:absol3112,项目名称:sonneboutique,代码行数:7,代码来源:SiteController.php

示例4: actionMenu

 public function actionMenu($id)
 {
     $roots = Category::find()->all();
     $categ = Category::find()->where(array('id' => $id))->all();
     $prods = Product::find()->where(array('id_category' => $id))->all();
     return $this->render('menu', ['roots' => $roots, 'prods' => $prods, 'categ' => $categ]);
 }
开发者ID:bokhonok-t,项目名称:yii2_e-shop,代码行数:7,代码来源:SiteController.php

示例5: actionDanhsach

 public function actionDanhsach()
 {
     $query = Product::find();
     $pagination = new Pagination(['defaultPageSize' => 2, 'totalCount' => $query->count()]);
     $products = $query->orderBy('product_name')->offset($pagination->offset)->limit($pagination->limit)->all();
     return $this->render('danhsach', ['product' => $products, 'pagination' => $pagination]);
 }
开发者ID:khuebt,项目名称:gem,代码行数:7,代码来源:SiteController.php

示例6: show

 /**
  * Change the currency.
  *
  * @return Redirect
  */
 public function show(Request $request, string $currency)
 {
     $request->session()->put('currency', $currency);
     $currency = Currency::where('currency', $currency)->first()->toArray();
     $request->session()->put('currency_rate', $currency['rate']);
     // we need to update the basket
     $basket = $request->session()->get('basket');
     foreach ($basket['items'] as $id => $item) {
         if (isset($item['parent_sku'])) {
             // its an option
             $product = Product::where('sku', $item['parent_sku'])->first();
             $price = isset($product->salePrice) && !empty($product->salePrice) ? $product->salePrice : $product->price;
             foreach ($product->option_values as $option) {
                 if ($option['sku'] == $id) {
                     $price = number_format($option['price'] * $request->session()->get('currency_rate'), 2, '.', '');
                 }
             }
         } else {
             $product = Product::find($id);
             $price = isset($product->salePrice) && !empty($product->salePrice) ? $product->salePrice : $product->price;
         }
         $basket['items'][$id]['price'] = $price;
     }
     $request->session()->put('basket', $basket);
     return redirect()->back();
 }
开发者ID:kudosagency,项目名称:kudos-php,代码行数:31,代码来源:CurrenciesController.php

示例7: updateVisibility

 /**
  * Update the visibility of a product
  *
  * @param $id
  * @param $visible
  * @return mixed
  */
 public function updateVisibility($id, $visible)
 {
     $product = Product::find($id);
     $product->visible = $visible;
     $product->save();
     return $product;
 }
开发者ID:FomKiosk,项目名称:API-Laravel,代码行数:14,代码来源:ProductRepository.php

示例8: updateProductStatus

 /**
  * Get Customers who requested for a respective Product
  * AJAX
  *
  * @param  Request  $request
  * @return Array
  */
 public function updateProductStatus(Request $request)
 {
     if ($request->ajax()) {
         $product = Product::find($request->product_id);
         return $this->dashboard->updateStatus($request, $product);
     }
 }
开发者ID:swinecommerceph,项目名称:swinecommerceph,代码行数:14,代码来源:DashboardController.php

示例9: __construct

 public function __construct($attributes = array())
 {
     if (isset($attributes['product_id']) && !Product::find($attributes['product_id'])) {
         throw new Exception("Item not found");
     }
     parent::__construct($attributes);
 }
开发者ID:hogggy,项目名称:infinite-wonder,代码行数:7,代码来源:CartItem.php

示例10: handle

 /**
  * Execute the command.
  *
  * @return void
  */
 public function handle()
 {
     $user = User::find($this->userId)->first();
     $product = Product::find($this->productId);
     //        dd($user, $product);
     $user->products()->save($product, ['mod' => '1']);
 }
开发者ID:jclyons52,项目名称:mycourse-rocks,代码行数:12,代码来源:AddModCommand.php

示例11: search

 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $this->scenario = '';
     $query = Product::find()->where(['active' => 1]);
     $this->scenario = 'default';
     $this->load($params, '');
     $order_arr = !empty($this->order_by) ? explode(':', $this->order_by) : ['id', 'desc'];
     $orderField = count($order_arr) > 0 ? $order_arr[0] : 'id';
     $orderSort = count($order_arr) > 1 && $order_arr[1] == 'desc' ? SORT_DESC : SORT_ASC;
     $this->order_by = $orderField . ':' . ($orderSort == SORT_DESC ? 'desc' : 'asc');
     /** @var Category $category */
     if (isset($params['code']) && !empty($params['code'])) {
         $this->_category = Category::find()->where(['url_code' => $params['code']])->one();
     }
     if (is_null($this->_category) && isset($params['id']) && !empty($params['id'])) {
         $this->_category = Category::findOne($params['id']);
     }
     if (!is_null($this->_category)) {
         $arr_cats = $this->_category->fillSubCategoryArray();
         $query->andFilterWhere(['in', 'category_id', $arr_cats]);
     }
     $per_page = isset($params['per-page']) ? $params['per-page'] : 12;
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $per_page], 'sort' => ['defaultOrder' => ['new' => SORT_DESC], 'attributes' => ['new' => ['desc' => ['id' => SORT_DESC], 'asc' => false, 'default' => SORT_DESC, 'label' => Yii::t('app', 'Newest Arrivals')], 'featured' => ['asc' => false, 'desc' => ['featured' => SORT_DESC], 'default' => SORT_DESC, 'label' => Yii::t('app', 'Featured')], 'price_asc' => ['desc' => false, 'asc' => ['price_custom' => SORT_ASC], 'default' => SORT_ASC, 'label' => Yii::t('app', 'Price: Low to High')], 'price_desc' => ['asc' => false, 'desc' => ['price_custom' => SORT_DESC], 'default' => SORT_DESC, 'label' => Yii::t('app', 'Price: High to Low')]]]]);
     return $dataProvider;
 }
开发者ID:rcjusto,项目名称:simplestore,代码行数:32,代码来源:ItemCategorySearch.php

示例12: postAddtocart

 public function postAddtocart()
 {
     $product = Product::find(Input::get('id'));
     $quantity = Input::get('quantity');
     Cart::insert(['id' => $product->id, 'name' => $product->title, 'price' => $product->price, 'quantity' => $quantity, 'image' => $product->image]);
     return Redirect::to('store/cart');
 }
开发者ID:rossli,项目名称:lam-laravel5-shop,代码行数:7,代码来源:StoreController.php

示例13: product_view

 public function product_view($id)
 {
     $product = Product::find($id);
     $product->images = json_decode($product->images);
     $data = ['product' => $product];
     return view('order.product_view', compact('data'));
 }
开发者ID:comsi02,项目名称:ordermart,代码行数:7,代码来源:OrderController.php

示例14: save

 function save(array $params)
 {
     $response = new ResponseEntity();
     DB::transaction(function () use(&$response, $params) {
         $user = User::find(Auth::user()->id);
         $product = Product::find($params['product_id']);
         $cust = new Customer();
         $cust->first_name = $params['customer']['first_name'];
         $cust->last_name = $params['customer']['last_name'];
         $cust->phone_number = $params['customer']['phone_number'];
         $custCreated = $cust->save();
         if ($custCreated && $product && $user) {
             $sale = new Sale();
             $sale->user_id = $user->id;
             $sale->sale_status_id = Config::get('constants.sale_status.sale');
             $sale->product_id = $product->id;
             $sale->customer_id = $cust->id;
             $sale->date_sold = Carbon::createFromFormat('m/d/Y', $params['date_sold'])->toDateString();
             $sale->remarks = isset($params['remarks']) ? $params['remarks'] : '';
             $sale->order_number = $params['order_number'];
             $sale->ninety_days = isset($params['ninety_days']) ?: 0;
             $ok = $sale->save();
             if ($ok) {
                 $ok = $this->setIncentive($sale->user_id, $sale->date_sold);
                 $response->setMessages($ok ? ['Sale successfully created!'] : ['Failed to create sale!']);
                 $response->setSuccess($ok);
             } else {
                 $response->setMessages(['Failed to create sale!']);
             }
         } else {
             $response->setMessages(['Entities not found']);
         }
     });
     return $response;
 }
开发者ID:arjayads,项目名称:green-tracker,代码行数:35,代码来源:SaleService.php

示例15: run

 public function run()
 {
     // query
     $product = Product::find()->orderBy('RAND()')->limit(3)->all();
     //render view
     return $this->render('random', ['product' => $product]);
 }
开发者ID:highestgoodlikewater,项目名称:diplom,代码行数:7,代码来源:RandomWidget.php


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