|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace app\modules\shop\controllers; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use app\backend\components\BackendController; |
|
7
|
|
|
use app\backgroundtasks\helpers\BackgroundTasks; |
|
8
|
|
|
use app\components\Helper; |
|
9
|
|
|
use app\modules\shop\models\GoogleFeed; |
|
10
|
|
|
use Yii; |
|
11
|
|
|
|
|
12
|
|
|
class BackendGoogleFeedController extends BackendController |
|
13
|
|
|
{ |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
public $defaultAction = 'settings'; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @return string|\yii\web\Response |
|
20
|
|
|
* @throws \yii\web\ServerErrorHttpException |
|
21
|
|
|
*/ |
|
22
|
|
View Code Duplication |
public function actionSettings() |
|
23
|
|
|
{ |
|
24
|
|
|
if (\Yii::$app->request->isPost) { |
|
25
|
|
|
$model = new GoogleFeed(); |
|
26
|
|
|
if (Yii::$app->request->isPost && $model->load(Yii::$app->request->post()) && $model->validate()) { |
|
27
|
|
|
$model->saveConfig(); |
|
28
|
|
|
} elseif ($model->hasErrors()) { |
|
29
|
|
|
Yii::$app->session->setFlash('error', Helper::formatModelErrors($model, '<br />')); |
|
30
|
|
|
} |
|
31
|
|
|
return $this->refresh(); |
|
32
|
|
|
} |
|
33
|
|
|
$model = new GoogleFeed(); |
|
34
|
|
|
$model->loadConfig(); |
|
35
|
|
|
return $this->render( |
|
36
|
|
|
'settings', |
|
37
|
|
|
[ |
|
38
|
|
|
'model' => $model |
|
39
|
|
|
] |
|
40
|
|
|
); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @return \yii\web\Response |
|
45
|
|
|
*/ |
|
46
|
|
View Code Duplication |
public function actionCreate() |
|
47
|
|
|
{ |
|
48
|
|
|
BackgroundTasks::addTask( |
|
49
|
|
|
[ |
|
50
|
|
|
'name' => 'google_merchants_generate', |
|
51
|
|
|
'description' => 'Creating YML file', |
|
52
|
|
|
'action' => 'shop/google-merchants/generate', |
|
53
|
|
|
'params' => '', |
|
54
|
|
|
'init_event' => 'shop/google_merchants', |
|
55
|
|
|
], |
|
56
|
|
|
[ |
|
57
|
|
|
'create_notification' => true, |
|
58
|
|
|
] |
|
59
|
|
|
); |
|
60
|
|
|
|
|
61
|
|
|
Yii::$app->session->setFlash('success', 'Task has been created.'); |
|
62
|
|
|
return $this->redirect(['settings']); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
} |