aedc35b5
Anastasia
- load scg to logo
|
1
2
3
4
5
6
7
8
9
10
11
|
<?php
/**
* Created by PhpStorm.
* User: stes
* Date: 29.05.18
* Time: 9:51
*/
namespace frontend\controllers;
use common\models\Service;
|
43a24059
Anastasia
- servives
|
12
|
use yii\db\ActiveQuery;
|
2032cb18
Anastasia
- services menu
|
13
|
use yii\db\Query;
|
aedc35b5
Anastasia
- load scg to logo
|
14
15
|
use yii\web\Controller;
use yii\web\NotFoundHttpException;
|
cfb947e6
alex
Микроданные для у...
|
16
|
use frontend\microdata\MicrodataFabric;
|
7f892874
Anastasia
- blog
|
17
|
|
aedc35b5
Anastasia
- load scg to logo
|
18
19
|
class ServiceController extends Controller
{
|
7f892874
Anastasia
- blog
|
20
21
|
public function actionView($id)
{
|
aedc35b5
Anastasia
- load scg to logo
|
22
|
$model = $this->findModel($id);
|
7f892874
Anastasia
- blog
|
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
|
if ($model->parent_id == null) {
$others = Service::find()
->where([ 'parent_id' => $model->id ])
->with(
[
'services.language.alias',
'language.alias',
]
)
->all();
if (empty($others)) {
$others = Service::find()
->where(
[
'parent_id' => null,
'status' => true,
]
)
->with(
[
'services.language.alias',
'language.alias',
]
)
->all();
}
} elseif ($model->level == 1) {
$others = Service::find()
->where([ 'parent_id' => $model->parent_id ])
->with(
[
'services.language.alias',
'language.alias',
]
)
->all();
} else {
$others = Service::find()
->where(
[
'parent_id' => ( new Query() )->select('parent_id')
->from('service')
->where([ 'id' => $model->parent_id ]),
]
)
->with(
[
'services.language.alias',
'language.alias',
]
)
->all();
|
aedc35b5
Anastasia
- load scg to logo
|
75
|
}
|
7f892874
Anastasia
- blog
|
76
|
|
3fafe556
alex
Микроразметка для...
|
77
|
# список цен для микроданных
|
7f892874
Anastasia
- blog
|
78
79
80
81
82
83
|
$prices = [];
foreach ($model->prices as $kry => $price) {
foreach ($price as $key2 => $val2) {
if ($key2 == 'price') {
$prices[] = $price[ $key2 ];
}
|
cfb947e6
alex
Микроданные для у...
|
84
|
}
|
7f892874
Anastasia
- blog
|
85
|
|
cfb947e6
alex
Микроданные для у...
|
86
87
88
89
|
}
$layoutMicrodata=(count($model->prices)>1)?
[
|
d38bb7e7
alex
пагинация в блоге
|
90
91
|
'context' => 'http://schema.org/',
'type' => 'Product',
|
cfb947e6
alex
Микроданные для у...
|
92
93
94
95
|
'name'=> "'{$model->language->attributes['title']}'",
'offers' =>
[
'@type'=> 'AggregateOffer',
|
d4b412e6
alex
починил микродату...
|
96
97
98
|
'lowPrice' => min($prices) . ".00",
'highPrice' => max($prices) . ".00",
'priceCurrency' => "UAH"
|
cfb947e6
alex
Микроданные для у...
|
99
100
101
102
103
|
]
]
:[
'type'=>'Product',
'name'=> "'{$model->language->attributes['title']}'",
|
cfb947e6
alex
Микроданные для у...
|
104
105
106
|
'offers'=> [
'@type'=> 'Offer',
'priceCurrency'=> 'UAH',
|
7507e71e
alex
исправление бага ...
|
107
|
|
cfb947e6
alex
Микроданные для у...
|
108
109
|
]
];
|
7507e71e
alex
исправление бага ...
|
110
|
if (count($model->prices) <= 1 && isset($prices)) {
|
d4b412e6
alex
починил микродату...
|
111
|
if (!empty($prices)) $layoutMicrodata['offers']['Price'] = "'" . max($prices) . ".00'";
|
7507e71e
alex
исправление бага ...
|
112
|
}
|
cfb947e6
alex
Микроданные для у...
|
113
114
115
116
117
118
119
|
$microdata=new MicrodataFabric();
$pageMicrodata=$microdata::createJsonFromProduct($layoutMicrodata)->toJson();
|
43a24059
Anastasia
- servives
|
120
|
$model->body = str_replace('[[prices]]', $this->renderPartial('_prices', ['prices' => $model->prices]), $model->body);
|
dac1c903
Anastasia
add button in admin
|
121
|
$model->body = str_replace('[[button]]', '<span class="btn_ modal-link" data-form="callback">'.\Yii::t('app','Make an appointment').'</span>', $model->body);
|
aedc35b5
Anastasia
- load scg to logo
|
122
123
|
return $this->render('view', [
'model' => $model,
|
cfb947e6
alex
Микроданные для у...
|
124
125
|
'others'=> $others,
'microdata'=>$pageMicrodata
|
aedc35b5
Anastasia
- load scg to logo
|
126
127
128
|
]);
}
|
7f892874
Anastasia
- blog
|
129
130
|
public function findModel($id)
{
|
aedc35b5
Anastasia
- load scg to logo
|
131
|
$model = Service::find()
|
7f892874
Anastasia
- blog
|
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
|
->where(
[
'id' => $id,
'status' => true,
]
)
->with(
[
'language.alias',
'prices' => function (ActiveQuery $query) {
$query->where([ 'status' => true ])
->with('language')
->orderBy('sort');
},
'comments' => function (ActiveQuery $query) {
$query->where([ 'status' => true ]);
},
'questions' => function (ActiveQuery $query) {
$query->where([ 'status' => true ])
->with('doctor');
},
'packages' => function (ActiveQuery $query) {
$query->with(
[
'image',
'language.alias',
]
)
->where([ 'status' => true ]);
},
]
)
->one();
if (empty($model)) {
|
aedc35b5
Anastasia
- load scg to logo
|
166
167
168
169
170
|
throw new NotFoundHttpException('Model not found');
}
return $model;
}
}
|