Commit 886cf4d7694cfbd09eeeba8dfe2c2ff30a9c862f

Authored by Alexey Boroda
1 parent 0e1d5865

-Sitemap started and event products removed

console/controllers/SiteMapController.php
... ... @@ -48,7 +48,6 @@
48 48 {
49 49 return [
50 50 'https://www.linija-svitla.ua',
51   - 'https://www.linija-svitla.ua/catalog',
52 51 ];
53 52 }
54 53  
... ... @@ -191,7 +190,7 @@
191 190 true
192 191 );
193 192  
194   - $this->createRow($url, 1, $content);
  193 + $this->createRow($url, 0.7, $content);
195 194 }
196 195 $this->stdout('Add categories' . "\n", Console::FG_BLUE);
197 196  
... ... @@ -204,7 +203,7 @@
204 203 ],
205 204 true
206 205 );
207   - $this->createRow($url, 1, $content);
  206 + $this->createRow($url, 0.9, $content);
208 207 }
209 208  
210 209 $this->stdout('Add products' . "\n", Console::FG_BLUE);
... ... @@ -218,7 +217,7 @@
218 217 ],
219 218 true
220 219 );
221   - $this->createRow($url, 0.9, $content);
  220 + $this->createRow($url, 0.7, $content);
222 221 }
223 222  
224 223 $this->stdout('Add articles' . "\n", Console::FG_BLUE);
... ... @@ -232,7 +231,7 @@
232 231 ],
233 232 true
234 233 );
235   - $this->createRow($url, 0.8, $content);
  234 + $this->createRow($url, 0.7, $content);
236 235  
237 236 }
238 237  
... ...
frontend/models/ProductFrontendSearch.php
1 1 <?php
2   -
3   -namespace frontend\models;
4   -
5   -use common\modules\product\helpers\FilterHelper;
6   -use common\modules\product\helpers\ProductHelper;
7   -use common\modules\product\models\Category;
8   -use Yii;
9   -use yii\base\Model;
10   -use yii\data\ActiveDataProvider;
11   -use yii\data\ArrayDataProvider;
12   -use yii\db\ActiveQuery;
13   -
14   -use common\modules\product\models\Product;
15   -use common\modules\product\models\ProductVariant;
16   -use yii\helpers\ArrayHelper;
17   -
18   -class ProductFrontendSearch extends Product {
19   -
20   -
21   - public $price_interval;
22   - public $brands;
23   -
24   -
25   - /**
26   - * @inheritdoc
27   - */
28   - public function rules()
  2 +
  3 + namespace frontend\models;
  4 +
  5 + use common\modules\product\helpers\FilterHelper;
  6 + use common\modules\product\helpers\ProductHelper;
  7 + use common\modules\product\models\Category;
  8 + use Yii;
  9 + use yii\base\Model;
  10 + use yii\data\ActiveDataProvider;
  11 + use yii\data\ArrayDataProvider;
  12 + use yii\db\ActiveQuery;
  13 +
  14 + use common\modules\product\models\Product;
  15 + use common\modules\product\models\ProductVariant;
  16 + use yii\db\Query;
  17 + use yii\helpers\ArrayHelper;
  18 +
  19 + class ProductFrontendSearch extends Product
29 20 {
30   - return [
31   - [['price_interval', 'brands'], 'safe'],
32   - ];
33   - }
34   -
35   - /**
36   - * @inheritdoc
37   - */
38   - public function scenarios()
39   - {
40   - // bypass scenarios() implementation in the parent class
41   - return Model::scenarios();
42   - }
43   -
44   - /**
45   - * Creates data provider instance with search query applied for frontend
46   - *
47   - * @param array $params
48   - *
49   - * @return ActiveDataProvider
50   - */
51   - public function search($category = null, $params = [], $in_stock = true) {
52   -
53   -
54   - $dataProvider = new ArrayDataProvider([
55   - 'allModels' => $this->getSearchQuery($category, $params, $in_stock)->with([
56   - 'images',
57   - 'events',
58   - 'variant',
59   - 'variant.image',
60   - 'comments',
61   - 'averageRating',
62   - ])->all(),
63   - 'pagination' => [
64   - 'pageSize' => 15,
65   - ],
66   - 'sort' => [
67   - 'attributes' => [
68   - 'name' => [
69   - 'asc' => ['name' => SORT_ASC],
70   - 'desc' => ['name' => SORT_DESC],
71   - 'default' => SORT_DESC,
72   - 'label' => 'ะธะผะตะฝะธ',
73   - ],
74   - 'price' => [
75   - 'asc' => ['price' => SORT_ASC],
76   - 'desc' => ['price' => SORT_DESC],
77   - 'default' => SORT_DESC,
78   - 'label' => 'ะฟะพ ั†ะตะฝะต',
  21 +
  22 + public $price_interval;
  23 + public $brands;
  24 +
  25 + /**
  26 + * @inheritdoc
  27 + */
  28 + public function rules()
  29 + {
  30 + return [
  31 + [
  32 + [
  33 + 'price_interval',
  34 + 'brands',
79 35 ],
  36 + 'safe',
80 37 ],
81   - ]
82   - ]);
83   -
84   - return $dataProvider;
85   - }
86   -
87   - public function getSearchQuery($category = null, $params = [], $in_stock = true) {
88   -
89   - if (!empty($category)) {
90   - /** @var ActiveQuery $query */
91   - /**@var Category $category **/
92   - $query = $category->getProducts();
93   -
94   - } else {
95   - $query = Product::find();
  38 + ];
96 39 }
97   -
98   - $query->select(['product.*']);
99   - $query->joinWith(['enabledVariants','brand','options', 'category']);
100   -
101   -// $query->groupBy(['product.product_id', 'product_variant.price', 'product_variant.stock']);
102   - $query->orderBy(['product_variant.stock' => SORT_DESC]);
103   - ProductHelper::_setQueryParams($query, $params);
104   - if($in_stock){
105   - $query->andWhere(['!=', ProductVariant::tableName() .'.status', 1]);
  40 +
  41 + /**
  42 + * @inheritdoc
  43 + */
  44 + public function scenarios()
  45 + {
  46 + // bypass scenarios() implementation in the parent class
  47 + return Model::scenarios();
  48 + }
  49 +
  50 + /**
  51 + * Creates data provider instance with search query applied for frontend
  52 + *
  53 + * @param array $params
  54 + *
  55 + * @return ActiveDataProvider
  56 + */
  57 + public function search($category = null, $params = [], $in_stock = true)
  58 + {
  59 +
  60 + $dataProvider = new ArrayDataProvider(
  61 + [
  62 + 'allModels' => $this->getSearchQuery($category, $params, $in_stock)
  63 + ->with(
  64 + [
  65 + 'images',
  66 + 'events',
  67 + 'variant',
  68 + 'variant.image',
  69 + 'comments',
  70 + 'averageRating',
  71 + ]
  72 + )
  73 + ->all(),
  74 + 'pagination' => [
  75 + 'pageSize' => 15,
  76 + ],
  77 + 'sort' => [
  78 + 'attributes' => [
  79 + 'name' => [
  80 + 'asc' => [ 'name' => SORT_ASC ],
  81 + 'desc' => [ 'name' => SORT_DESC ],
  82 + 'default' => SORT_DESC,
  83 + 'label' => 'ะธะผะตะฝะธ',
  84 + ],
  85 + 'price' => [
  86 + 'asc' => [ 'price' => SORT_ASC ],
  87 + 'desc' => [ 'price' => SORT_DESC ],
  88 + 'default' => SORT_DESC,
  89 + 'label' => 'ะฟะพ ั†ะตะฝะต',
  90 + ],
  91 + ],
  92 + ],
  93 + ]
  94 + );
  95 +
  96 + return $dataProvider;
  97 + }
  98 +
  99 + public function getSearchQuery($category = null, $params = [], $in_stock = true)
  100 + {
  101 +
  102 + if (!empty($category)) {
  103 + /** @var ActiveQuery $query */
  104 + /**@var Category $category * */
  105 + $query = $category->getProducts();
  106 +
  107 + } else {
  108 + $query = Product::find();
  109 + }
  110 +
  111 + $query->select([ 'product.*' ]);
  112 + $query->joinWith(
  113 + [
  114 + 'enabledVariants',
  115 + 'brand',
  116 + 'options',
  117 + 'category',
  118 + ]
  119 + );
  120 +
  121 + // $query->groupBy(['product.product_id', 'product_variant.price', 'product_variant.stock']);
  122 + $query->orderBy([ 'product_variant.stock' => SORT_DESC ]);
  123 + ProductHelper::_setQueryParams($query, $params);
  124 + if ($in_stock) {
  125 + $query->andWhere(
  126 + [
  127 + '!=',
  128 + ProductVariant::tableName() . '.status',
  129 + 1,
  130 + ]
  131 + );
  132 + }
  133 +
  134 + /**
  135 + * Removing products that currently in events
  136 + */
  137 + $query->andWhere(
  138 + [
  139 + 'not',
  140 + [
  141 + 'product.product_id' => ( new Query() )->select('events_to_products.product_id')
  142 + ->from('events_to_products')
  143 + ->innerJoin(
  144 + 'event',
  145 + 'event.event_id=events_to_products.event_id'
  146 + )->where(['event.is_event' => true]),
  147 + ],
  148 + ]
  149 + );
  150 +
  151 + return $query;
106 152 }
107   -
108   -
109   - return $query;
110   - }
111   -
112   -
113   - /**
114   - * @param Category|null $category
115   - * @return array
116   - */
117   -
118   - public function priceLimits($category = null, $params = []) {
119   - if (!empty($category)) {
120   - /** @var ActiveQuery $query */
121   -// $query = $category->getRelations('product_categories');
122   - $query = $category->getProducts();
123   - } else {
124   - $query = Product::find();
  153 +
  154 + /**
  155 + * @param Category|null $category
  156 + *
  157 + * @return array
  158 + */
  159 +
  160 + public function priceLimits($category = null, $params = [])
  161 + {
  162 + if (!empty($category)) {
  163 + /** @var ActiveQuery $query */
  164 + // $query = $category->getRelations('product_categories');
  165 + $query = $category->getProducts();
  166 + } else {
  167 + $query = Product::find();
  168 + }
  169 + $query->joinWith('variant');
  170 +
  171 + // Price filter fix
  172 + unset($params[ 'prices' ]);
  173 +
  174 + ProductHelper::_setQueryParams($query, $params);
  175 + $query->andWhere(
  176 + [
  177 + '>=',
  178 + ProductVariant::tableName() . '.stock',
  179 + 1,
  180 + ]
  181 + );
  182 + return [
  183 + 'min' => $query->min(ProductVariant::tableName() . '.price'),
  184 + 'max' => $query->max(ProductVariant::tableName() . '.price'),
  185 + ];
125 186 }
126   - $query->joinWith('variant');
127   -
128   - // Price filter fix
129   - unset($params['prices']);
130   -
131   - ProductHelper::_setQueryParams($query, $params);
132   - $query->andWhere(
133   - [
134   - '>=',
135   - ProductVariant::tableName() . '.stock',
136   - 1,
137   - ]
138   - );
139   - return [
140   - 'min' => $query->min(ProductVariant::tableName() .'.price'),
141   - 'max' => $query->max(ProductVariant::tableName() .'.price'),
142   - ];
143   - }
144   -}
145 187 \ No newline at end of file
  188 + }
146 189 \ No newline at end of file
... ...