本文整理汇总了PHP中common\models\Product::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::find方法的具体用法?PHP Product::find怎么用?PHP Product::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common\models\Product
的用法示例。
在下文中一共展示了Product::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: catalogSearch
/**
* Creates data provider instance with search query applied
* @param array $params
* @param $ids
* @return ActiveDataProvider
*/
public function catalogSearch($params, $ids)
{
$query = Product::find()->select(['{{product}}.*', 'IF(round(sum(product_review.rating) / count(product.reviews_count)) IS NULL, 0, rating) as rating'])->withFilerProperties()->with(['brand' => function (ActiveQuery $query) {
$query->productsCount();
}])->joinWith('productReviews')->groupBy('{{product}}.id')->where(['product.category_id' => $ids]);
$cloneQuery = clone $query;
$products = $cloneQuery->all();
$brands = ArrayHelper::map($products, 'brand.id', 'brand.title');
$brandsProductsCount = ArrayHelper::map($products, 'brand.id', 'brand.productCount');
$sort = new Sort(['defaultOrder' => ['rating' => SORT_ASC], 'attributes' => Product::getSortAttributes()]);
$viewSort = new Sort(['sortParam' => 'view', 'attributes' => [Product::VIEW_SORT_LIST, Product::VIEW_SORT_BLOCK]]);
$this->load($params);
$sortParam = Yii::$app->request->getQueryParam('view');
$dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => $sort, 'pagination' => ['pageSize' => $sortParam === Product::VIEW_SORT_BLOCK ? self::PAGINATION_SIZE_BLOCK : self::PAGINATION_SIZE_LIST]]);
Yii::$app->controller->view->params['viewSort'] = $viewSort;
Yii::$app->controller->view->params['sort'] = $sort;
Yii::$app->controller->view->params['searchModel'] = $this;
Yii::$app->controller->view->params['brands'] = $brands;
Yii::$app->controller->view->params['brandsProductCount'] = $brandsProductsCount;
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere(['id' => $this->id, 'active' => $this->active, 'reviews_count' => $this->reviews_count, 'brand_id' => $this->brand_id, 'comment_count' => $this->comment_count, 'category_id' => $this->category_id, 'UI' => $this->ui]);
$query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'full_description', $this->full_description])->andFilterWhere(['like', 'short_description', $this->short_description])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'ui', $this->ui]);
Yii::$app->controller->view->params['propertiesProvider'] = new PropertiesProvider(['query' => clone $query]);
Yii::$app->controller->view->params['dataProvider'] = $dataProvider;
return $dataProvider;
}
示例2: run
public function run()
{
parent::run();
// TODO: Change the autogenerated stub
$nodes = Product::find()->where(['status' => 10])->limit(3)->all();
return $this->render('ProductBottomTopWidget', ['nodes' => $nodes]);
}
示例3: actionCheckout
public function actionCheckout()
{
session_start();
$prod_ids = $_SESSION['cart-item'];
$products = Product::find()->where(['prod_id' => $prod_ids])->all();
return $this->render('checkout', ['products' => $products]);
}
示例4: actionView
public function actionView($id)
{
if ($id <= 0) {
$this->goHome();
}
$allCategory = Category::find()->asArray()->all();
$arrayCategoryIdName = ArrayHelper::map($allCategory, 'id', 'name');
$arrSubCat = Category::getArraySubCatalogId($id, $allCategory);
/****** 价格筛选 ****/
$result = (new Query())->select('min(price) as min, max(price) as max')->from('product')->where(['category_id' => $arrSubCat, 'status' => Status::STATUS_ACTIVE])->one();
$min = $result['min'];
$max = $result['max'];
if ($max > $min && $max > 0) {
// 计算跨度
$priceGrade = 0.0001;
for ($i = -2; $i < log10($max); $i++) {
$priceGrade *= 10;
}
$span = ceil(($max - $min) / 5 / $priceGrade) * $priceGrade;
if ($span == 0) {
$span = $priceGrade;
}
// 计算价格的起点和终点
for ($i = 1; $min > $span * $i; $i++) {
}
for ($j = 1; $min > $span * ($i - 1) + $priceGrade * $j; $j++) {
}
$priceFilter['start'] = $span * ($i - 1) + $priceGrade * ($j - 1);
for (; $max >= $span * $i; $i++) {
}
$priceFilter['end'] = $span * $i + $priceGrade * ($j - 1);
$priceFilter['span'] = $span;
}
/****** 价格筛选 end ****/
/****** 品牌筛选 start ****/
$result = (new Query())->select('distinct(brand_id)')->from('product')->where(['category_id' => $arrSubCat, 'status' => Status::STATUS_ACTIVE])->all();
$ids = ArrayHelper::map($result, 'brand_id', 'brand_id');
$brandFilter = Brand::find()->where(['id' => $ids])->orderBy(['name' => SORT_ASC])->all();
/****** 品牌筛选 end ****/
$query = Product::find()->where(['category_id' => $arrSubCat, 'status' => Status::STATUS_ACTIVE]);
// 如果选择了价格区间
if (Yii::$app->request->get('max')) {
$min = intval(Yii::$app->request->get('min'));
$max = intval(Yii::$app->request->get('max'));
if ($min >= 0 && $max) {
$query->andWhere(['and', ['>', 'price', $min], ['<=', 'price', $max]]);
}
}
// 如果选择了品牌
if (Yii::$app->request->get('brand_id')) {
$brandId = intval(Yii::$app->request->get('brand_id'));
if ($brandId >= 0) {
$query->andWhere(['brand_id' => $brandId]);
}
}
// 侧边热销商品
$sameCategoryProducts = Product::find()->where(['category_id' => $id])->orderBy(['sales' => SORT_DESC])->limit(5)->all();
$dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['defaultPageSize' => Yii::$app->params['defaultPageSizeProduct']], 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]]]);
return $this->render('view', ['model' => $this->findModel($id), 'allCategory' => $allCategory, 'arrayCategoryIdName' => $arrayCategoryIdName, 'products' => $dataProvider->getModels(), 'pagination' => $dataProvider->pagination, 'priceFilter' => isset($priceFilter) ? $priceFilter : null, 'brandFilter' => $brandFilter, 'sameCategoryProducts' => $sameCategoryProducts]);
}
示例5: actionView
public function actionView($slug)
{
$productModel = new Product();
$productData = $productModel->findOne(['slug' => $slug]);
$relatedProduct = $productModel->find()->where(['category_id' => $productData->category_id])->andWhere(['<>', 'id', $productData->id])->limit(9)->orderBy(['id' => SORT_ASC])->all();
return $this->render('view', ['node' => $productData, 'relateNodes' => $relatedProduct]);
}
示例6: actionIndex
public function actionIndex($c_url, $sc_url, $r_url, $product_ui)
{
if (!($product = Product::find()->withProperties()->select(['{{product}}.*', 'IF(round(sum(product_review.rating) / count(product.reviews_count)) IS NULL, 0, rating) as rating'])->joinWith('productReviews')->groupBy('{{product}}.id')->with(['photos', 'videos', 'photos360'])->byUi($product_ui)->one())) {
throw new NotFoundHttpException();
}
Yii::$app->recently->add($product);
return $this->render('index', ['model' => $product]);
}
示例7: actionIndex
/**
* Lists all Image models.
* @param int $id product id
* @return mixed
*
* @throws NotFoundHttpException
*/
public function actionIndex($id)
{
$form = new MultipleUploadForm();
if (!Product::find()->where(['id' => $id])->exists()) {
throw new NotFoundHttpException();
}
$searchModel = new ImageSearch();
$searchModel->product_id = $id;
$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) {
//
// UPLOADING THE IMAGE:
//
$image = new Image();
$image->product_id = $id;
if ($image->save()) {
// Save an original image;
$path = $image->getPath();
$file->saveAs($path);
// Original size:
$size = getimagesize($path);
$height = $size[1];
$width = $size[0];
// IMAGINE
ImagineImage::$driver = [ImagineImage::DRIVER_GD2];
$imagine = new Imagine();
$picture = $imagine->open($path);
//---------------------------
// $size = new Box(self::IMAGE_WIDTH, self::IMAGE_HEIGHT);
// $center = new Center($size);
//---------------------------
// $picture->crop(new Point(0, 0),
// new Box(self::IMAGE_WIDTH, self::IMAGE_HEIGHT))->save($path);
/**
* If the image's height is bigger than needed, it must be cut.
* Otherwise it must be resized.
*/
if ($height >= self::IMAGE_HEIGHT) {
$picture->thumbnail(new Box(self::IMAGE_WIDTH, self::IMAGE_HEIGHT))->save($path, ['quality' => 100]);
// re-save cropped image;
} else {
$picture->resize(new Box(self::IMAGE_WIDTH, self::IMAGE_HEIGHT))->save($path);
}
sleep(1);
// $background = new Color('#FFF');
// $topLeft = new Point(0, 0);
// $canvas = $imagine->create(new Box(450, 450), $background);
// $canvas->paste($picture, $topLeft)->save($path);
}
}
}
}
return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'uploadForm' => $form]);
}
示例8: actionFavorite
public function actionFavorite()
{
$productIds = ArrayHelper::map(Favorite::find()->where(['user_id' => Yii::$app->user->id])->orderBy(['id' => SORT_DESC])->asArray()->all(), 'product_id', 'product_id');
if (count($productIds)) {
$query = Product::find()->where(['id' => $productIds]);
$dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['defaultPageSize' => Yii::$app->params['defaultPageSizeOrder']], 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]]]);
return $this->render('favorite', ['products' => $dataProvider->getModels(), 'pagination' => $dataProvider->pagination]);
}
return $this->render('favorite', ['products' => []]);
}
示例9: actionIndex
/**
* Lists all Product models.
* @return mixed
*/
public function actionIndex()
{
$currUser = Yii::$app->user->getIdentity();
$currMb = MerchantBrand::find()->where(['merchant_brand_id' => $currUser->username])->one();
$mbFk = $currMb->_id;
$query = Product::find()->where(['merchant_brand_fk' => new \MongoId($mbFk)]);
$searchModel = new ProductSearch();
$dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]);
return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
}
示例10: actionSample
public function actionSample()
{
if (Yii::$app->request->isAjax) {
$data = Yii::$app->request->post();
$id = explode(":", $data['id']);
$search = $id[0];
$product = Product::find()->where(['id' => $search])->one();
return $this->renderPartial('_sample', ['product' => $product]);
}
}
示例11: search
public function search($params)
{
$query = Product::find();
$dataProvider = new ActiveDataProvider(['query' => $query]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere(['id' => $this->id, 'price_discount' => $this->price_discount, 'price' => $this->price, 'organization_id' => $this->organization_id, 'type_id' => $this->type_id]);
$query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'keywords', $this->keywords])->andFilterWhere(['like', 'intro', $this->intro])->andFilterWhere(['like', 'body', $this->body])->andFilterWhere(['like', 'icon_image', $this->icon_image])->andFilterWhere(['like', 'main_image', $this->main_image])->andFilterWhere(['like', 'results', $this->results])->andFilterWhere(['like', 'group_services', $this->group_services])->andFilterWhere(['like', 'orientation', $this->orientation])->andFilterWhere(['like', 'tags', $this->tags])->andFilterWhere(['like', 'recommend', $this->recommend])->andFilterWhere(['like', 'prepare', $this->prepare])->andFilterWhere(['like', 'notes', $this->notes]);
return $dataProvider;
}
示例12: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Product::find();
$dataProvider = new ActiveDataProvider(['query' => $query]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere(['id' => $this->id, 'price' => $this->price]);
$query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'short_description', $this->short_description])->andFilterWhere(['like', 'image', $this->image]);
return $dataProvider;
}
示例13: run
public function run()
{
parent::run();
// TODO: Change the autogenerated stub
$category = new Category();
$product = new Product();
$parent_category = $category->findOne(['id' => $this->category_id]);
$categoriesData = $category->findAll(['parent_id' => $this->category_id]);
$category_slug = $parent_category->slug;
$categoryIDs = [];
if ($categoriesData) {
foreach ($categoriesData as $categoryData) {
$categoryIDs[] = $categoryData->id;
}
$products = $product->find()->where(['status' => 10, 'is_featured' => 10])->andWhere(['in', 'category_id', $categoryIDs])->limit($this->limit)->all();
} else {
$products = $product->find()->where(['status' => 10, 'is_front' => 10, 'category_id' => $this->category_id])->limit($this->limit)->all();
}
return $this->render('widget/front_product', ['nodes' => $products, 'category_slug' => $category_slug]);
}
示例14: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Product::find();
$dataProvider = new ActiveDataProvider(['query' => $query]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere(['id' => $this->id, 'category_id' => $this->category_id, 'status' => $this->status]);
$query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'main_image', $this->main_image])->andFilterWhere(['like', 'short_text', $this->short_text])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'brand', $this->brand])->andFilterWhere(['like', 'made_in', $this->made_in])->andFilterWhere(['like', 'slug', $this->slug]);
return $dataProvider;
}
示例15: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Product::find();
$dataProvider = new ActiveDataProvider(['query' => $query]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere(['id' => $this->id, 'category_id' => $this->category_id, 'price' => $this->price]);
$query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description]);
return $dataProvider;
}