本文整理汇总了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;
}
示例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]);
}
示例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]);
}
示例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]);
}
示例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]);
}
示例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();
}
示例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;
}
示例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);
}
}
示例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);
}
示例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']);
}
示例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;
}
示例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');
}
示例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'));
}
示例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;
}
示例15: run
public function run()
{
// query
$product = Product::find()->orderBy('RAND()')->limit(3)->all();
//render view
return $this->render('random', ['product' => $product]);
}