SiteController.php
11.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
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
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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
<?php
namespace frontend\controllers;
use Yii;
use common\models\LoginForm;
use frontend\models\PasswordResetRequestForm;
use frontend\models\ResetPasswordForm;
use frontend\models\SignupForm;
use yii\base\InvalidParamException;
use yii\helpers\ArrayHelper;
use yii\web\BadRequestHttpException;
use yii\web\Controller;
use yii\web\Response;
use yii\widgets\ActiveForm;
use common\modules\product\models\CategorySearch;
use common\modules\product\models\Product;
use common\modules\product\models\ProductVariant;
class SiteController extends Controller
{
public function actionMain()
{
return $this->render('index', [
]);
}
/**
* Logs out the current user.
*
* @return mixed
*/
public function actionLogout()
{
Yii::$app->user->logout();
return $this->goHome();
}
/**
* 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,
]);
}
public function actionError(){
return $this->render('error', [
'code'=>'404',
]);
}
/**
* 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,
]);
}
/**
* 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,
]);
}
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){
$type = false;
if($filter->group->name == "Тип точечного освещение:"){
$type = true;
print "<param name='Тип'>{$filter->name}</param>";
}
if($filter->group->name == "Тип настенного освещения:"){
$type = true;
print "<param name='Тип'>{$filter->name}</param>";
}
if($filter->group->name == "Тип потолочного освещения:"){
$type = true;
print "<param name='Тип'>{$filter->name}</param>";
}
if($filter->group->name == "Тип уличного освещения:"){
$type = true;
print "<param name='Тип'>{$filter->name}</param>";
}
if($filter->group->name == "Тип лампочки:"){
$type = true;
print "<param name='Тип'>{$filter->name}</param>";
}
if(!$type){
print "<param name='Тип'>{$product->category->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>";
}
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>";
}
}