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; |
13
|
|
|
|
14
|
|
|
class Param extends \Model |
15
|
|
|
{ |
16
|
|
|
public static $objectName = 'Параметр товара'; |
17
|
|
|
public static $labels = [ |
18
|
|
|
'item_option_id' => 'Параметр', |
19
|
|
|
'item_id' => 'Товар', |
20
|
|
|
'value' => 'Значение', |
21
|
|
|
]; |
22
|
|
|
public static $cols = [ |
23
|
|
|
//Основные параметры |
24
|
|
|
'item_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'item'], |
25
|
|
|
'item_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
|
|
|
{ |
33
|
|
|
return [ |
34
|
|
|
'ecommerce_itemOptionRelation' => [ |
35
|
|
|
'type' => 'INDEX', |
36
|
|
|
'cols' => [ |
37
|
|
|
'item_param_item_id', |
38
|
|
|
'item_param_item_option_id' |
39
|
|
|
] |
40
|
|
|
], |
41
|
|
|
'ecommerce_paramItemIndex' => [ |
42
|
|
|
'type' => 'INDEX', |
43
|
|
|
'cols' => [ |
44
|
|
|
'item_param_item_id', |
45
|
|
|
] |
46
|
|
|
], |
47
|
|
|
'ecommerce_paramOptionIndex' => [ |
48
|
|
|
'type' => 'INDEX', |
49
|
|
|
'cols' => [ |
50
|
|
|
'item_param_item_option_id' |
51
|
|
|
] |
52
|
|
|
], |
53
|
|
|
]; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function realType() |
57
|
|
|
{ |
58
|
|
|
if ($this->option) { |
59
|
|
|
$type = $this->option->type; |
60
|
|
|
|
61
|
|
|
if ($type == 'select') { |
62
|
|
|
return [ |
63
|
|
|
'type' => 'select', |
64
|
|
|
'source' => 'relation', |
65
|
|
|
'relation' => 'option:items', |
66
|
|
|
]; |
67
|
|
|
} |
68
|
|
|
return $type; |
69
|
|
|
} |
70
|
|
|
return 'text'; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public static $dataManagers = [ |
74
|
|
|
|
75
|
|
|
'manager' => [ |
76
|
|
|
'name' => 'Параметры товара', |
77
|
|
|
'cols' => [ |
78
|
|
|
'item_option_id', |
79
|
|
|
'item_id', |
80
|
|
|
'value', |
81
|
|
|
], |
82
|
|
|
], |
83
|
|
|
]; |
84
|
|
|
public static $forms = [ |
85
|
|
|
'manager' => [ |
86
|
|
|
'map' => [ |
87
|
|
|
['item_id', 'item_option_id'], |
88
|
|
|
['value'] |
89
|
|
|
] |
90
|
|
|
]]; |
91
|
|
|
|
92
|
|
|
function name() |
|
|
|
|
93
|
|
|
{ |
94
|
|
|
return $this->value; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function value($default = '') |
98
|
|
|
{ |
99
|
|
|
if ($this->option->type != 'select') { |
100
|
|
|
return $this->value; |
101
|
|
|
} elseif ($this->optionItem) { |
102
|
|
|
return $this->optionItem->value; |
103
|
|
|
} |
104
|
|
|
return $default; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public static function relations() |
108
|
|
|
{ |
109
|
|
|
return [ |
110
|
|
|
'file' => [ |
111
|
|
|
'model' => 'Files\File', |
112
|
|
|
'col' => 'value' |
113
|
|
|
], |
114
|
|
|
'option' => [ |
115
|
|
|
'model' => 'Ecommerce\Item\Option', |
116
|
|
|
'col' => 'item_option_id' |
117
|
|
|
], |
118
|
|
|
'item' => [ |
119
|
|
|
'model' => 'Ecommerce\Item', |
120
|
|
|
'col' => 'item_id' |
121
|
|
|
], |
122
|
|
|
'optionItem' => [ |
123
|
|
|
'model' => 'Ecommerce\Item\Option\Item', |
124
|
|
|
'col' => 'value' |
125
|
|
|
] |
126
|
|
|
]; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
} |
130
|
|
|
|
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.