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;
|
aedc35b5
Anastasia
- load scg to logo
|
17
18
19
|
class ServiceController extends Controller
{
|
aedc35b5
Anastasia
- load scg to logo
|
20
21
22
|
public function actionView($id){
$model = $this->findModel($id);
if ($model->parent_id == null){
|
74783874
Anastasia
- debug
|
23
|
$others = Service::find()->where(['parent_id' => $model->id])->with(['services.language.alias', 'language.alias'])->all();
|
a4320bd1
Anastasia
- bug fix
|
24
|
if (empty($others)){
|
74783874
Anastasia
- debug
|
25
|
$others = Service::find()->where(['parent_id' => null, 'status' => true])->with(['services.language.alias', 'language.alias'])->all();
|
a4320bd1
Anastasia
- bug fix
|
26
|
}
|
2032cb18
Anastasia
- services menu
|
27
|
}elseif ($model->level == 1){
|
74783874
Anastasia
- debug
|
28
|
$others = Service::find()->where(['parent_id' => $model->parent_id])->with(['services.language.alias', 'language.alias'])->all();
|
aedc35b5
Anastasia
- load scg to logo
|
29
|
}else{
|
74783874
Anastasia
- debug
|
30
|
$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
|
31
|
}
|
cfb947e6
alex
Микроданные для у...
|
32
33
|
|
3fafe556
alex
Микроразметка для...
|
34
|
# список цен для микроданных
|
cfb947e6
alex
Микроданные для у...
|
35
36
37
38
39
40
41
42
43
44
45
|
$prices=[];
foreach ($model->prices as $kry=>$price)
{
foreach ($price as $key2=>$val2){
if($key2=='price')$prices[]=$price[$key2];
}
}
$layoutMicrodata=(count($model->prices)>1)?
[
|
d38bb7e7
alex
пагинация в блоге
|
46
47
|
'context' => 'http://schema.org/',
'type' => 'Product',
|
cfb947e6
alex
Микроданные для у...
|
48
49
50
51
|
'name'=> "'{$model->language->attributes['title']}'",
'offers' =>
[
'@type'=> 'AggregateOffer',
|
d4b412e6
alex
починил микродату...
|
52
53
54
|
'lowPrice' => min($prices) . ".00",
'highPrice' => max($prices) . ".00",
'priceCurrency' => "UAH"
|
cfb947e6
alex
Микроданные для у...
|
55
56
57
58
59
|
]
]
:[
'type'=>'Product',
'name'=> "'{$model->language->attributes['title']}'",
|
cfb947e6
alex
Микроданные для у...
|
60
61
62
|
'offers'=> [
'@type'=> 'Offer',
'priceCurrency'=> 'UAH',
|
7507e71e
alex
исправление бага ...
|
63
|
|
cfb947e6
alex
Микроданные для у...
|
64
65
|
]
];
|
7507e71e
alex
исправление бага ...
|
66
|
if (count($model->prices) <= 1 && isset($prices)) {
|
d4b412e6
alex
починил микродату...
|
67
|
if (!empty($prices)) $layoutMicrodata['offers']['Price'] = "'" . max($prices) . ".00'";
|
7507e71e
alex
исправление бага ...
|
68
|
}
|
cfb947e6
alex
Микроданные для у...
|
69
70
71
72
73
74
75
|
$microdata=new MicrodataFabric();
$pageMicrodata=$microdata::createJsonFromProduct($layoutMicrodata)->toJson();
|
43a24059
Anastasia
- servives
|
76
|
$model->body = str_replace('[[prices]]', $this->renderPartial('_prices', ['prices' => $model->prices]), $model->body);
|
aedc35b5
Anastasia
- load scg to logo
|
77
78
|
return $this->render('view', [
'model' => $model,
|
cfb947e6
alex
Микроданные для у...
|
79
80
|
'others'=> $others,
'microdata'=>$pageMicrodata
|
aedc35b5
Anastasia
- load scg to logo
|
81
82
83
84
85
86
|
]);
}
public function findModel($id){
$model = Service::find()
->where(['id' => $id, 'status' => true])
|
727d4d0e
Anastasia
- debug
|
87
|
->with(['language.alias', 'prices' => function (ActiveQuery $query){
|
74783874
Anastasia
- debug
|
88
|
$query->where(['status' => true])->with('language')->orderBy('sort');
|
43a24059
Anastasia
- servives
|
89
90
|
}, 'comments' => function (ActiveQuery $query){
$query->where(['status' => true]);
|
b8459872
Anastasia
- forms1
|
91
|
}, 'questions' => function (ActiveQuery $query){
|
727d4d0e
Anastasia
- debug
|
92
|
$query->where(['status' => true])->with('doctor');
|
a4320bd1
Anastasia
- bug fix
|
93
|
},'packages' => function (ActiveQuery $query){
|
74783874
Anastasia
- debug
|
94
|
$query->with(['image', 'language.alias'])->where(['status' => true]);
|
43a24059
Anastasia
- servives
|
95
|
}])->one();
|
aedc35b5
Anastasia
- load scg to logo
|
96
97
98
99
100
101
|
if (empty($model)){
throw new NotFoundHttpException('Model not found');
}
return $model;
}
}
|