示例#1
0
 /**
  * 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;
 }
 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
0
 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
0
 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]);
 }
 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]);
 }
 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
0
 /**
  * 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
0
 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
0
 /**
  * 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
0
 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]);
     }
 }
 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;
 }
 /**
  * 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;
 }
 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
0
 /**
  * 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
0
 /**
  * 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;
 }
 public function actionOrder($id)
 {
     $order = Order::findOne($id);
     $product_ids = [];
     if (!empty($order)) {
         foreach ($order->carts as $cart) {
             $product_ids[] = $cart->product_id;
         }
     }
     $cart_items = Product::find()->where(['in', 'id', $product_ids])->all();
     return $this->render('/site/cart', ['cart_items' => $cart_items, 'order' => $order]);
 }
示例#17
0
 /**
  * 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, 'pagination' => ['pageSize' => 10]]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->joinWith('category');
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'product.title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'category.title', $this->category_id])->andFilterWhere(['<=', 'price', $this->price]);
     return $dataProvider;
 }
示例#18
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Product::find();
     $query->orderBy(['created_at' => SORT_DESC]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if ($this->load($params) && !$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'category_id' => $this->category_id, 'stock' => $this->stock, 'weight' => $this->weight, 'market_price' => $this->market_price, 'price' => $this->price, 'type' => $this->type, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'sku', $this->sku])->andFilterWhere(['like', 'brief', $this->brief])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'thumb', $this->thumb])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'origin', $this->origin])->andFilterWhere(['like', 'keywords', $this->keywords])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
示例#19
0
 public function getUrls()
 {
     $urls = [];
     $urls[] = Url::to(['site/index'], true);
     $urls[] = Url::to(['catalog/index'], true);
     foreach (Product::find()->all() as $item) {
         $urls[] = Url::to(['catalog/view', 'slug' => $item->slug, 'category' => $item->category->slug], true);
     }
     foreach (Category::find()->all() as $item) {
         $urls[] = Url::to(['catalog/category', 'category' => $item->slug], true);
     }
     return $urls;
 }
示例#20
0
 public function actionList($id = null)
 {
     /** @var Category $category */
     $category = null;
     $categories = Category::find()->indexBy('id')->orderBy('id')->all();
     $productsQuery = Product::find();
     if ($id !== null && isset($categories[$id])) {
         $category = $categories[$id];
         $productsQuery->where(['category_id' => $this->getCategoryIds($categories, $id)]);
     }
     $productsDataProvider = new ActiveDataProvider(['query' => $productsQuery, 'pagination' => ['pageSize' => 10]]);
     return $this->render('list', ['category' => $category, 'menuItems' => $this->getMenuItems($categories, isset($category->id) ? $category->id : null), 'productsDataProvider' => $productsDataProvider]);
 }
示例#21
0
 /**
  * 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]);
     $this->load($params);
     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(['like', '_id', $this->_id])->andFilterWhere(['like', 'product_id', $this->product_id])->andFilterWhere(['like', 'product_name', $this->product_name])->andFilterWhere(['like', 'product_model_number', $this->product_model_number])->andFilterWhere(['like', 'product_price', $this->product_price])->andFilterWhere(['like', 'product_unit_weight', $this->product_unit_weight])->andFilterWhere(['like', 'product_unit', $this->product_unit])->andFilterWhere(['like', 'product_origin', $this->product_origin])->andFilterWhere(['like', 'product_manufacturer', $this->product_manufacturer])->andFilterWhere(['like', 'product_available_date', $this->product_available_date])->andFilterWhere(['like', 'product_quantity', $this->product_quantity])->andFilterWhere(['like', 'product_ordered', $this->product_ordered])->andFilterWhere(['like', 'product_create_date', $this->product_create_date])->andFilterWhere(['like', 'product_create_user_id', $this->product_create_user_id])->andFilterWhere(['like', 'product_last_update_date', $this->product_last_update_date])->andFilterWhere(['like', 'product_last_update_user_id', $this->product_last_update_user_id])->andFilterWhere(['like', 'product_status', $this->product_status])->andFilterWhere(['like', 'product_category_fk', $this->product_category_fk])->andFilterWhere(['like', 'product_specification_fk', $this->product_specification_fk])->andFilterWhere(['like', 'merchant_brand_fk', $this->merchant_brand_fk]);
     return $dataProvider;
 }
示例#22
0
 /**
  * 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]);
     $this->load($params);
     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, 'qty' => $this->qty, 'product' => $this->product, 'code' => $this->code]);
     return $dataProvider;
 }
示例#23
0
 /**
  * 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]);
     $this->load($params);
     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(['product_id' => $this->product_id, 'product_price' => $this->product_price, 'product_category' => $this->product_category, 'product_created_date' => $this->product_created_date, 'admin_id' => $this->admin_id]);
     $query->andFilterWhere(['like', 'product_name', $this->product_name])->andFilterWhere(['like', 'product_description', $this->product_description])->andFilterWhere(['like', 'product_slug', $this->product_slug]);
     return $dataProvider;
 }
示例#24
0
 /**
  * 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]);
     $this->load($params);
     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, 'category_id' => $this->category_id, 'inventory' => $this->inventory, 'our_price' => $this->our_price, 'market_price' => $this->market_price, 'promotion_price' => $this->promotion_price, 'promotion_start_time' => $this->promotion_start_time, 'promotion_end_time' => $this->promotion_end_time, 'is_new' => $this->is_new, 'is_hot' => $this->is_hot, 'is_best' => $this->is_best, 'display_order' => $this->display_order, 'score' => $this->score, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'logo', $this->logo]);
     return $dataProvider;
 }
 private static function getProduct($categoryID)
 {
     $categoryModel = Category::findOne(['id' => $categoryID])->children()->all();
     $categories = array();
     $categories[] = $categoryID;
     foreach ($categoryModel as $category) {
         $categories[] = $category->id;
     }
     $productModel = Product::find()->where(['in', 'category_id', $categories]);
     $count = $productModel->count();
     $pagination = new Pagination(['totalCount' => $count]);
     $nodes = $productModel->offset($pagination->offset)->limit(18)->orderBy(['id' => SORT_DESC])->all();
     return ['nodes' => $nodes, 'pagination' => $pagination];
 }
 /**
  * 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, 'pagination' => ['pageSize' => $this->itemsLimit, 'pageParam' => 'page', 'validatePage' => false]]);
     $this->load($params);
     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, 'price' => $this->price]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
示例#27
0
 /**
  * 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]);
     $this->load($params);
     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, 'category_id' => $this->category_id, 'price' => $this->price, 'status' => $this->status, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'sku', $this->sku])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'summary', $this->summary])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'meta_title', $this->meta_title])->andFilterWhere(['like', 'meta_keywords', $this->meta_keywords])->andFilterWhere(['like', 'meta_description', $this->meta_description]);
     return $dataProvider;
 }
示例#28
0
 /**
  * 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]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'reference', $this->reference])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
示例#29
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function searchFish($params, $pageSize = 10)
 {
     $query = Product::find()->joinWith('category')->where(['category_id' => 1]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_ASC]], 'pagination' => ['pageSize' => $pageSize]]);
     $this->load($params);
     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, 'images_num' => $this->images_num, 'price' => $this->price, 'rate' => $this->rate, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'category_id' => $this->category_id, 'unit_id' => $this->unit_id, 'user_id' => $this->user_id]);
     $query->andFilterWhere(['like', 'images_label', $this->images_label])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'desc', $this->desc])->andFilterWhere(['like', 'category_id', $this->category_id]);
     return $dataProvider;
 }
 /**
  * Displays a single Order model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     $order = Order::findOne($id);
     if (empty($order)) {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
     $product_ids = [];
     if (!empty($order)) {
         foreach ($order->carts as $cart) {
             $product_ids[] = $cart->product_id;
         }
     }
     $cart_items = Product::find()->where(['in', 'id', $product_ids])->all();
     return $this->render('view', ['model' => $order, 'cart_items' => $cart_items]);
 }