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
|
|
ceb083b9
Timur Kastemirov
price.xml PriceCo...
|
18
|
use yii\web\HttpException;
|
a1a60fa5
Administrator
big commti
|
19
20
|
use yii\web\Response;
use yii\widgets\ActiveForm;
|
dc9ffa3c
Administrator
big commti
|
21
22
23
24
25
26
27
|
use common\modules\product\models\CategorySearch;
use common\modules\product\models\Product;
use common\modules\product\models\ProductVariant;
|
4253cbec
root
first commit
|
28
29
|
class SiteController extends Controller
{
|
e337d04a
Administrator
liniya first commit
|
30
|
|
4253cbec
root
first commit
|
31
|
|
076b9c96
Administrator
big commti
|
32
|
public function actionMain()
|
4253cbec
root
first commit
|
33
34
|
{
|
4253cbec
root
first commit
|
35
36
|
return $this->render('index', [
|
4253cbec
root
first commit
|
37
38
|
|
4253cbec
root
first commit
|
39
40
41
|
]);
}
|
c93ce871
Administrator
big commti
|
42
43
44
45
46
47
48
49
|
/**
* Logs out the current user.
*
* @return mixed
*/
public function actionLogout()
{
Yii::$app->user->logout();
|
4253cbec
root
first commit
|
50
|
|
c93ce871
Administrator
big commti
|
51
52
|
return $this->goHome();
}
|
a1a60fa5
Administrator
big commti
|
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
|
/**
* 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
|
104
|
public function actionError(){
|
37415bee
Administrator
big commti
|
105
106
|
return $this->render('error', [
'code'=>'404',
|
37415bee
Administrator
big commti
|
107
108
|
]);
}
|
fe0fcefc
Administrator
big commti
|
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
/**
* 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
|
126
127
128
129
|
return $this->render('requestPasswordResetToken', [
'model' => $model,
]);
}
|
01cfd880
Administrator
big commti
|
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
|
/**
* 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
|
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
|
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>";
}
|
ceb083b9
Timur Kastemirov
price.xml PriceCo...
|
222
|
|
4253cbec
root
first commit
|
223
|
}
|