Exemplo n.º 1
0
 /**
  * Finds the Product model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Product the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Product::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 2
0
 /**
  * Finds the Product model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $alias
  * @return Product the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($alias)
 {
     if (($model = Product::findOne(['alias' => $alias, 'active' => 1])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 3
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, 'image_id' => $this->image_id, 'brand_id' => $this->brand_id, 'mark_id' => $this->mark_id, 'typebeer_id' => $this->typebeer_id, 'size_id' => $this->size_id, 'shop_id' => $this->shop_id, 'price' => $this->price, 'date' => $this->date, 'created' => $this->created]);
     return $dataProvider;
 }
Exemplo n.º 4
0
 public function actionShowOrder($id = null)
 {
     $model = new Order();
     $model = $model::findOne(['id' => $id]);
     //var_dump($model->product_id);die();
     $products = Product::find()->asArray()->all();
     $listProducts = ArrayHelper::map($products, 'id', 'name');
     $categories = Category::find()->asArray()->all();
     $listCategories = ArrayHelper::map($categories, 'id', 'name');
     $subCategories = SubCategory::find()->asArray()->all();
     $listSubCategories = ArrayHelper::map($subCategories, 'id', 'name');
     return $this->render('showOrder', ['model' => $model, 'listProducts' => $listProducts, 'listCategories' => $listCategories, 'listSubCategories' => $listSubCategories]);
 }
Exemplo n.º 5
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, 'cost' => $this->cost, 'number' => $this->number]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'code', $this->code]);
     return $dataProvider;
 }
Exemplo n.º 6
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     // ленивая загрузка. каждая категория выбирается отдельным запросом
     //$query = Product::find();
     //жадная загрузка. все категории выбираются одним запросом
     $query = Product::find()->with('category');
     $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, 'price' => $this->price, 'created' => $this->created, 'updated' => $this->updated, 'active' => $this->active, 'category_id' => $this->category_id]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'keywords', $this->keywords])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'screen_size', $this->screen_size])->andFilterWhere(['like', 'os', $this->os])->andFilterWhere(['like', 'standart', $this->standart]);
     return $dataProvider;
 }
Exemplo n.º 7
0
 /**
  * Displays a single Category model.
  * @param string $alias
  * @return mixed
  */
 public function actionView($alias)
 {
     $model = $this->findModel($alias);
     $menu_items_product = Product::getItemsProductMenu($model->id);
     $menu_items_category = Category::getItemsCategoryMenu($model->parent_category_id);
     $sort = new Sort(['attributes' => ['price' => ['asc' => ['price' => SORT_ASC], 'desc' => ['price' => SORT_DESC], 'default' => SORT_DESC]]]);
     $query = Product::find()->where(['active' => 1, 'category_id' => $model->id]);
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count(), 'defaultPageSize' => Yii::$app->params['PageSize']]);
     $items_product = $query->offset($pages->offset)->limit($pages->limit)->orderBy($sort->orders)->all();
     // тут вытягиваем все главные картинки одним запросом
     $arItems = [];
     foreach ($items_product as $value) {
         $arItems[] = $value->id;
     }
     $images = $model->getImagesMain($arItems, 'Product');
     return $this->render('view', ['model' => $model, 'menu_items_product' => $menu_items_product, 'menu_items_category' => $menu_items_category, 'items_product' => $items_product, 'pages' => $pages, 'sort' => $sort, 'images' => $images]);
 }
Exemplo n.º 8
0
 public function getProduct()
 {
     return $this->hasOne(Product::className(), ['product_id' => 'product_id']);
 }
Exemplo n.º 9
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProducts()
 {
     return $this->hasMany(Product::className(), ['image_id' => 'id']);
 }
Exemplo n.º 10
0
 public function getName()
 {
     return $this->hasOne(Product::className(), ['id' => 'product_id'])->one()->name;
 }