4253cbec
root
first commit
|
1
2
3
4
|
<?php
namespace frontend\controllers;
|
dc9ffa3c
Administrator
big commti
|
5
|
|
a95ce595
Administrator
big commti
|
6
|
use common\modules\product\models\Category;
|
4253cbec
root
first commit
|
7
|
use Yii;
|
a1a60fa5
Administrator
big commti
|
8
9
10
11
|
use common\models\LoginForm;
use frontend\models\PasswordResetRequestForm;
use frontend\models\ResetPasswordForm;
use frontend\models\SignupForm;
|
dc9ffa3c
Administrator
big commti
|
12
|
|
a1a60fa5
Administrator
big commti
|
13
|
use yii\base\InvalidParamException;
|
dc9ffa3c
Administrator
big commti
|
14
|
use yii\helpers\ArrayHelper;
|
a1a60fa5
Administrator
big commti
|
15
|
use yii\web\BadRequestHttpException;
|
4253cbec
root
first commit
|
16
|
use yii\web\Controller;
|
dc9ffa3c
Administrator
big commti
|
17
|
|
a1a60fa5
Administrator
big commti
|
18
19
|
use yii\web\Response;
use yii\widgets\ActiveForm;
|
dc9ffa3c
Administrator
big commti
|
20
21
22
23
24
25
26
|
use common\modules\product\models\CategorySearch;
use common\modules\product\models\Product;
use common\modules\product\models\ProductVariant;
|
4253cbec
root
first commit
|
27
28
|
class SiteController extends Controller
{
|
e337d04a
Administrator
liniya first commit
|
29
|
|
4253cbec
root
first commit
|
30
|
|
076b9c96
Administrator
big commti
|
31
|
public function actionMain()
|
4253cbec
root
first commit
|
32
33
|
{
|
4253cbec
root
first commit
|
34
35
|
return $this->render('index', [
|
4253cbec
root
first commit
|
36
37
|
|
4253cbec
root
first commit
|
38
39
40
|
]);
}
|
c93ce871
Administrator
big commti
|
41
42
43
44
45
46
47
48
|
/**
* Logs out the current user.
*
* @return mixed
*/
public function actionLogout()
{
Yii::$app->user->logout();
|
4253cbec
root
first commit
|
49
|
|
c93ce871
Administrator
big commti
|
50
51
|
return $this->goHome();
}
|
a1a60fa5
Administrator
big commti
|
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
|
/**
* 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
|
103
|
public function actionError(){
|
37415bee
Administrator
big commti
|
104
105
|
return $this->render('error', [
'code'=>'404',
|
37415bee
Administrator
big commti
|
106
107
|
]);
}
|
fe0fcefc
Administrator
big commti
|
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
/**
* 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.');
}
}
|
fe0fcefc
Administrator
big commti
|
125
126
127
128
|
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
|
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()
{
|
dc9ffa3c
Administrator
big commti
|
226
|
|
a95ce595
Administrator
big commti
|
227
|
$is_count = Yii::$app->request->get('count', false);
|
dc9ffa3c
Administrator
big commti
|
228
|
|
a95ce595
Administrator
big commti
|
229
|
$categories = Category::find()->all();
|
dc9ffa3c
Administrator
big commti
|
230
|
|
dc9ffa3c
Administrator
big commti
|
231
232
233
234
235
236
237
238
239
240
|
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>";
|
a95ce595
Administrator
big commti
|
241
242
243
244
245
246
|
foreach($categories as $category){
print "<category>";
print "<id>" .$category->category_id . "</id>";
print "<name>" . $category->name. "</name>";
print "</category>";
}
|
dc9ffa3c
Administrator
big commti
|
247
|
print "</categories>";
|
a95ce595
Administrator
big commti
|
248
249
250
251
|
|
dc9ffa3c
Administrator
big commti
|
252
|
print "<items>";
|
a95ce595
Administrator
big commti
|
253
254
255
256
257
258
259
260
261
262
263
264
265
|
foreach($categories as $category){
$products = $category->getProducts()->with(['filters','filters.group'])->joinWith('variant')->where(['product_variant.status'=>0])->all();
if ($is_count) {
print (count($products));
continue;
}
/** @var Product $product */
foreach ($products as $product)
{
|
8229efdc
Alexey Boroda
-Price feed fix
|
266
267
268
269
|
/**
* Fix for emty brands 14.03.2017
*/
if (empty($product->brand)) continue;
|
dc9ffa3c
Administrator
big commti
|
270
271
272
273
274
275
276
277
|
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>";
|
43414a5d
Administrator
big commti
|
278
|
print "<url>http://www.linija-svitla.ua{$product->url}</url>";
|
dc9ffa3c
Administrator
big commti
|
279
280
281
|
print "<image>http://www.linija-svitla.ua{$product->variant->imageUrl}</image>";
print "<priceRUAH>" . $product->variant->price . "</priceRUAH>";
print "<oldprice>" . $product->variant->price_old . "</oldprice>";
|
a6f6464c
Administrator
big commti
|
282
|
|
43414a5d
Administrator
big commti
|
283
|
$type = false;
|
dc9ffa3c
Administrator
big commti
|
284
|
foreach( $product->filters as $filter){
|
c0480183
Administrator
big commti
|
285
286
|
|
43414a5d
Administrator
big commti
|
287
|
|
c0480183
Administrator
big commti
|
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
|
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>";
}
|
43414a5d
Administrator
big commti
|
313
|
|
c0480183
Administrator
big commti
|
314
315
|
|
dc9ffa3c
Administrator
big commti
|
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
|
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>";
}
|
a6f6464c
Administrator
big commti
|
334
|
|
43414a5d
Administrator
big commti
|
335
336
337
|
if(!$type){
print "<param name='Тип'>{$product->category->name}</param>";
}
|
a6f6464c
Administrator
big commti
|
338
339
|
|
dc9ffa3c
Administrator
big commti
|
340
341
342
343
344
345
|
print "<priceRUSD></priceRUSD>";
print "<stock>В наличии</stock>";
print "<guarantee></guarantee>";
print "</item>";
|
a95ce595
Administrator
big commti
|
346
347
|
}
|
dc9ffa3c
Administrator
big commti
|
348
349
350
|
}
|
a95ce595
Administrator
big commti
|
351
352
353
354
355
356
357
358
|
//var_dump($products);die();
|
dc9ffa3c
Administrator
big commti
|
359
360
361
362
363
364
|
print "</items>";
print "</price>";
}
|
4253cbec
root
first commit
|
365
|
}
|