Blame view

frontend/controllers/SiteController.php 9.97 KB
4253cbec   root   first commit
1
2
3
4
  <?php
  
  namespace frontend\controllers;
  
dc9ffa3c   Administrator   big commti
5
  
4253cbec   root   first commit
6
  use Yii;
a1a60fa5   Administrator   big commti
7
8
9
10
  use common\models\LoginForm;
  use frontend\models\PasswordResetRequestForm;
  use frontend\models\ResetPasswordForm;
  use frontend\models\SignupForm;
dc9ffa3c   Administrator   big commti
11
  
a1a60fa5   Administrator   big commti
12
  use yii\base\InvalidParamException;
dc9ffa3c   Administrator   big commti
13
  use yii\helpers\ArrayHelper;
a1a60fa5   Administrator   big commti
14
  use yii\web\BadRequestHttpException;
4253cbec   root   first commit
15
  use yii\web\Controller;
dc9ffa3c   Administrator   big commti
16
  
a1a60fa5   Administrator   big commti
17
18
  use yii\web\Response;
  use yii\widgets\ActiveForm;
dc9ffa3c   Administrator   big commti
19
20
21
22
23
24
25
  
  use common\modules\product\models\CategorySearch;
  use common\modules\product\models\Product;
  use common\modules\product\models\ProductVariant;
  
  
  
4253cbec   root   first commit
26
27
  class SiteController extends Controller
  {
e337d04a   Administrator   liniya first commit
28
  
4253cbec   root   first commit
29
  
076b9c96   Administrator   big commti
30
      public function actionMain()
4253cbec   root   first commit
31
32
      {
  
4253cbec   root   first commit
33
34
  
          return $this->render('index', [
4253cbec   root   first commit
35
36
  
  
4253cbec   root   first commit
37
38
39
          ]);
      }
  
c93ce871   Administrator   big commti
40
41
42
43
44
45
46
47
      /**
       * Logs out the current user.
       *
       * @return mixed
       */
      public function actionLogout()
      {
          Yii::$app->user->logout();
4253cbec   root   first commit
48
  
c93ce871   Administrator   big commti
49
50
          return $this->goHome();
      }
a1a60fa5   Administrator   big commti
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
      /**
       * Logs in a user.
       *
       * @return mixed
       */
      public function actionLogin()
      {
          if (!\Yii::$app->user->isGuest) {
              return $this->goHome();
          }
  
          $model = new LoginForm();
          if ($model->load(Yii::$app->request->post()) && $model->login()) {
              return $this->goBack();
          } else {
              return $this->render('index', [
                  'model' => $model,
              ]);
          }
      }
  
  
      /**
       * Signs user up.
       *
       * @return mixed
       */
      public function actionSignup()
      {
  
          if(Yii::$app->request->post()){
              if (Yii::$app->request->isAjax) {
                  Yii::$app->response->format = Response::FORMAT_JSON;
                  $model = new SignupForm();
                  $model->load(Yii::$app->request->post());
                  return ActiveForm::validate($model);
              } else {
                  $model = new SignupForm();
                  $model->load(Yii::$app->request->post());
                  if ($user = $model->signup()) {
                      if (Yii::$app->getUser()->login($user)) {
                          return $this->goHome();
                      }
                  }
              }
          }
          return $this->render('signup', [
              'model' => $model,
          ]);
      }
  
37415bee   Administrator   big commti
102
      public function actionError(){
37415bee   Administrator   big commti
103
104
          return $this->render('error', [
              'code'=>'404',
37415bee   Administrator   big commti
105
106
          ]);
      }
fe0fcefc   Administrator   big commti
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
      /**
       * Requests password reset.
       *
       * @return mixed
       */
      public function actionRequestPasswordReset()
      {
          $model = new PasswordResetRequestForm();
          if ($model->load(Yii::$app->request->post()) && $model->validate()) {
              if ($model->sendEmail()) {
                  Yii::$app->session->setFlash('success', 'Check your email for further instructions.');
  
                  return $this->goHome();
              } else {
                  Yii::$app->session->setFlash('error', 'Sorry, we are unable to reset password for email provided.');
              }
          }
  
          return $this->render('requestPasswordResetToken', [
              'model' => $model,
          ]);
      }
01cfd880   Administrator   big commti
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
  
  
      /**
       * Resets password.
       *
       * @param string $token
       * @return mixed
       * @throws BadRequestHttpException
       */
      public function actionResetPassword($token)
      {
          try {
              $model = new ResetPasswordForm($token);
          } catch (InvalidParamException $e) {
              throw new BadRequestHttpException($e->getMessage());
          }
  
          if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->resetPassword()) {
              Yii::$app->session->setFlash('success', 'New password was saved.');
  
              return $this->goHome();
          }
  
          return $this->render('resetPassword', [
              'model' => $model,
          ]);
      }
dc9ffa3c   Administrator   big commti
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
  
      public function actionPriceparam ()
      {
          $category_alias = Yii::$app->request->get('category');
          $is_count = Yii::$app->request->get('count', false);
  
          if ( !($category = CategorySearch::findByAlias($category_alias)))
          {
              throw new HttpException(404, 'Данной страницы не существует!');
          }
  
          $products = $category->products;
  
          if ($is_count) {
              print (count($products));
              exit;
          }
  
          set_time_limit (0);
          header ("Content-Type: text/xml");
          print '<?xml version="1.0" encoding="UTF-8" ?>';
          print "<price>";
          print "<date>" . date ("Y-m-d h:m") . "</date>";
          print "<firmName>www.linija-svitla.ua</firmName>";
          print "<firmId></firmId>";
          print "<rate></rate>";
          print "<categories>";
  
          print "<category>";
          print "<id>" . $category->category_id . "</id>";
          print "<parentId></parentId>";
          print "<name>" . $category->name . "</name>";
          print "</category>";
  
  
          print "</categories>";
          print "<items>";
          /** @var Product $product */
          foreach ($products as $product) {
              /** @var ProductVariant $variant */
              foreach ($product->enabledVariants as $variant) {
  
                  print "<item>";
                  print "<id>" . htmlspecialchars($variant->product_variant_id) . "</id>";
                  print "<categoryId>" . htmlspecialchars($product->category->category_id) . "</categoryId>";
                  print "<vendor>" . $product->brand->name . "</vendor>";
                  print "<code>" . htmlspecialchars($variant->sku) . "</code>";
                  print "<typeprefix>" . htmlspecialchars(substr($category->name, 0, -2)) . " </typeprefix>";
                  print "<name>" . htmlspecialchars($product->name) . "  </name>";
                  print "<param>" . $variant->name . " </param>";
                  print "<description>" . htmlspecialchars($product->description) . "</description>";
                  print "<url>http://www.linija-svitla.ua{$product->url}#{$variant->product_variant_id}</url>";
                  print "<image>http://www.linija-svitla.ua{$variant->imageUrl}</image>";
                  print "<priceRUAH>" . $variant->price . "</priceRUAH>";
                  print "<oldprice>" . $variant->price_old . "</oldprice>";
                  print "<priceRUSD></priceRUSD>";
                  print "<stock>В наличии</stock>";
                  print "<guarantee></guarantee>";
                  print "</item>";
              }
          }
          print "</items>";
  
          print "</price>";
      }
  
      public function actionPrice()
      {
  
  
          $category_alias = Yii::$app->request->get('category');
          $is_count = Yii::$app->request->get('count', false);
  
          if ( !($category = CategorySearch::findByAlias($category_alias)))
          {
              throw new HttpException(404, 'Данной страницы не существует!');
          }
  
          $products = $category->getProducts()->with(['filters','filters.group'])->all();
  
          if ($is_count) {
              print (count($products));
              exit;
          }
  
  
  //var_dump($products);die();
          set_time_limit (0);
          header ("Content-Type: text/xml");
          print '<?xml version="1.0" encoding="UTF-8" ?>';
          print "<price>";
          print "<date>" . date ("Y-m-d h:m") . "</date>";
          print "<firmName>www.linija-svitla.ua</firmName>";
          print "<firmId></firmId>";
          print "<rate></rate>";
          print "<categories>";
  
          print "<category>";
          print "<id>" . $category->category_id . "</id>";
          print "<parentId></parentId>";
          print "<name>" . $category->name . "</name>";
          print "</category>";
  
          print "</categories>";
          print "<items>";
          /** @var Product $product */
          foreach ($products as $product)
          {
  
  
                  print "<item>";
                  print "<id>" . htmlspecialchars($product->variant->product_variant_id) . "</id>";
                  print "<categoryId>" . htmlspecialchars($product->category->category_id) . "</categoryId>";
                  print "<vendor>" . $product->brand->name . "</vendor>";
                  print "<code>" . htmlspecialchars($product->variant->sku) . "</code>";
                  print "<name>" . htmlspecialchars($product->name)." " .htmlspecialchars($product->variant->name). " </name>";
                  print "<description>" . htmlspecialchars($product->description) . "</description>";
                  print "<url>http://www.linija-svitla.ua{$product->url}#{$product->variant->product_variant_id}</url>";
                  print "<image>http://www.linija-svitla.ua{$product->variant->imageUrl}</image>";
                  print "<priceRUAH>" . $product->variant->price . "</priceRUAH>";
                  print "<oldprice>" . $product->variant->price_old . "</oldprice>";
                  print "<param name='Тип'>{$product->category->name}</param>";
                  foreach( $product->filters as $filter){
                      if($filter->group->name == "Назначение:"){
                          print "<param name='Назначение'>{$filter->name}</param>";
                      }
                      if($filter->group->name == "Стиль:"){
                          print "<param name='Стиль'>{$filter->name}</param>";
                      }
                      if($filter->group->name == "Количество лампочек:"){
                          print "<param name='Количество источников света'>{$filter->name}</param>";
                      }
                      if($filter->group->name == "Тип источника света:"){
                          print "<param name='Тип источника освещения'>{$filter->name}</param>";
                      }
                      if($filter->group->name == "Цоколь:"){
                          print "<param name='Тип цоколя'>{$filter->name}</param>";
                      }
                      //print "<param name='Монтаж'>Припотолочная</param>";
  
                  }
  
                  print "<priceRUSD></priceRUSD>";
                  print "<stock>В наличии</stock>";
                  print "<guarantee></guarantee>";
                  print "</item>";
  
  
          }
  
  
          print "</items>";
  
          print "</price>";
  
  
      }
4253cbec   root   first commit
313
  }