1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Item param |
5
|
|
|
* |
6
|
|
|
* @author Alexey Krupskiy <[email protected]> |
7
|
|
|
* @link http://inji.ru/ |
8
|
|
|
* @copyright 2015 Alexey Krupskiy |
9
|
|
|
* @license https://github.com/injitools/cms-Inji/blob/master/LICENSE |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Ecommerce\Item\Offer; |
13
|
|
|
|
14
|
|
View Code Duplication |
class Param extends \Model { |
15
|
|
|
|
16
|
|
|
public static $objectName = 'Параметр товара'; |
17
|
|
|
public static $labels = [ |
18
|
|
|
'item_offer_option_id' => 'Параметр предложения', |
19
|
|
|
'item_offer_id' => 'Предложение', |
20
|
|
|
'value' => 'Значение', |
21
|
|
|
]; |
22
|
|
|
public static $cols = [ |
23
|
|
|
//Основные параметры |
24
|
|
|
'item_offer_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'offer'], |
25
|
|
|
'item_offer_option_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'option', 'onChange' => 'reloadForm'], |
26
|
|
|
'value' => ['type' => 'dynamicType', 'typeSource' => 'selfMethod', 'selfMethod' => 'realType'], |
27
|
|
|
//Системные |
28
|
|
|
'date_create' => ['type' => 'dateTime'] |
29
|
|
|
]; |
30
|
|
|
|
31
|
|
|
public static function indexes() { |
32
|
|
|
return [ |
33
|
|
|
'ecommerce_itemOfferOptionRelation' => [ |
34
|
|
|
'type' => 'INDEX', |
35
|
|
|
'cols' => [ |
36
|
|
|
'item_offer_param_item_offer_id', |
37
|
|
|
'item_offer_param_item_offer_option_id' |
38
|
|
|
] |
39
|
|
|
], |
40
|
|
|
'ecommerce_paramItemOfferIndex' => [ |
41
|
|
|
'type' => 'INDEX', |
42
|
|
|
'cols' => [ |
43
|
|
|
'item_offer_param_item_offer_id', |
44
|
|
|
] |
45
|
|
|
], |
46
|
|
|
'ecommerce_paramOfferOptionIndex' => [ |
47
|
|
|
'type' => 'INDEX', |
48
|
|
|
'cols' => [ |
49
|
|
|
'item_offer_param_item_offer_option_id' |
50
|
|
|
] |
51
|
|
|
], |
52
|
|
|
]; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function realType() { |
56
|
|
|
if ($this->option && $this->option->type) { |
57
|
|
|
$type = $this->option->type; |
58
|
|
|
|
59
|
|
|
if ($type == 'select') { |
60
|
|
|
return [ |
61
|
|
|
'type' => 'select', |
62
|
|
|
'source' => 'relation', |
63
|
|
|
'relation' => 'option:items', |
64
|
|
|
]; |
65
|
|
|
} |
66
|
|
|
return $type; |
67
|
|
|
} |
68
|
|
|
return 'text'; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public static $dataManagers = [ |
72
|
|
|
|
73
|
|
|
'manager' => [ |
74
|
|
|
'name' => 'Параметры предложения', |
75
|
|
|
'cols' => [ |
76
|
|
|
'item_offer_option_id', |
77
|
|
|
'item_offer_id', |
78
|
|
|
'value', |
79
|
|
|
], |
80
|
|
|
], |
81
|
|
|
]; |
82
|
|
|
public static $forms = [ |
83
|
|
|
'manager' => [ |
84
|
|
|
'map' => [ |
85
|
|
|
['item_offer_id', 'item_offer_option_id'], |
86
|
|
|
['value'] |
87
|
|
|
] |
88
|
|
|
]]; |
89
|
|
|
|
90
|
|
|
function name() { |
|
|
|
|
91
|
|
|
return $this->value; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function value($default = '') { |
95
|
|
|
if ($this->option->type != 'select') { |
96
|
|
|
return $this->value; |
97
|
|
|
} elseif ($this->optionItem) { |
98
|
|
|
return $this->optionItem->value; |
99
|
|
|
} |
100
|
|
|
return $default; |
|
|
|
|
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public static function relations() { |
104
|
|
|
return [ |
105
|
|
|
'file' => [ |
106
|
|
|
'model' => 'Files\File', |
107
|
|
|
'col' => 'value' |
108
|
|
|
], |
109
|
|
|
'option' => [ |
110
|
|
|
'model' => 'Ecommerce\Item\Offer\Option', |
111
|
|
|
'col' => 'item_offer_option_id' |
112
|
|
|
], |
113
|
|
|
'offer' => [ |
114
|
|
|
'model' => 'Ecommerce\Item\Offer', |
115
|
|
|
'col' => 'item_offer_id' |
116
|
|
|
], |
117
|
|
|
'optionItem' => [ |
118
|
|
|
'model' => 'Ecommerce\Item\Offer\Option\Item', |
119
|
|
|
'col' => 'value' |
120
|
|
|
] |
121
|
|
|
]; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
} |
125
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.