當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。