1
|
|
|
<?php |
2
|
|
|
namespace pastuhov\ymlcatalog\models; |
3
|
|
|
|
4
|
|
|
class SimpleOffer extends BaseModel |
5
|
|
|
{ |
6
|
|
|
/** |
7
|
|
|
* @inheritdoc |
8
|
|
|
*/ |
9
|
|
|
public static $tag = 'offer'; |
10
|
|
|
/** |
11
|
|
|
* @inheritdoc |
12
|
|
|
*/ |
13
|
|
|
public static $tagProperties = [ |
14
|
|
|
'id', |
15
|
|
|
'bid', |
16
|
|
|
'cbid', |
17
|
|
|
'available' |
18
|
|
|
]; |
19
|
|
|
|
20
|
|
|
public $id; |
21
|
|
|
public $bid; |
22
|
|
|
public $cbid; |
23
|
|
|
public $available; |
24
|
|
|
|
25
|
|
|
public $url; |
26
|
|
|
public $price; |
27
|
|
|
public $oldprice; |
28
|
|
|
public $currencyId; |
29
|
|
|
public $categoryId; |
30
|
|
|
public $market_Category; |
31
|
|
|
public $store; |
32
|
|
|
public $pickup; |
33
|
|
|
public $delivery; |
34
|
|
|
public $local_Delivery_Cost; |
35
|
|
|
public $name; |
36
|
|
|
public $vendor; |
37
|
|
|
public $vendorCode; |
38
|
|
|
public $description; |
39
|
|
|
public $sales_notes; |
40
|
|
|
public $manufacturer_Warranty; |
41
|
|
|
public $country_Of_Origin; |
42
|
|
|
public $adult; |
43
|
|
|
public $age; |
44
|
|
|
public $barcode; |
45
|
|
|
public $cpa; |
46
|
|
|
public $params = []; |
47
|
|
|
public $pictures = []; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @inheritdoc |
51
|
|
|
*/ |
52
|
6 |
|
public function getYmlAttributes() |
53
|
|
|
{ |
54
|
|
|
return [ |
55
|
6 |
|
'url', |
56
|
4 |
|
'price', |
57
|
4 |
|
'oldprice', |
58
|
4 |
|
'currencyId', |
59
|
4 |
|
'categoryId', |
60
|
4 |
|
'market_Category', |
61
|
4 |
|
'store', |
62
|
4 |
|
'pickup', |
63
|
4 |
|
'delivery', |
64
|
4 |
|
'local_Delivery_Cost', |
65
|
4 |
|
'name', |
66
|
4 |
|
'vendor', |
67
|
4 |
|
'vendorCode', |
68
|
4 |
|
'description', |
69
|
4 |
|
'sales_notes', |
70
|
4 |
|
'manufacturer_Warranty', |
71
|
4 |
|
'country_Of_Origin', |
72
|
4 |
|
'adult', |
73
|
4 |
|
'age', |
74
|
4 |
|
'barcode', |
75
|
4 |
|
'cpa', |
76
|
4 |
|
]; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @inheritdoc |
81
|
|
|
*/ |
82
|
6 |
|
public function rules() |
83
|
|
|
{ |
84
|
|
|
return [ |
85
|
|
|
[ |
86
|
4 |
|
['id', 'price', 'currencyId', 'categoryId', 'name', 'available'], |
87
|
4 |
|
'required', |
88
|
6 |
|
], |
89
|
|
|
[ |
90
|
4 |
|
['sales_notes'], |
91
|
4 |
|
'string', |
92
|
4 |
|
'max' => 50, |
93
|
4 |
|
], |
94
|
|
|
[ |
95
|
4 |
|
['name', 'vendor'], |
96
|
4 |
|
'string', |
97
|
4 |
|
'max' => 120, |
98
|
4 |
|
], |
99
|
|
|
[ |
100
|
4 |
|
['delivery'], |
101
|
4 |
|
'string', |
102
|
4 |
|
'max' => 4, |
103
|
4 |
|
], |
104
|
|
|
[ |
105
|
4 |
|
['id', 'categoryId', 'bid', 'cbid'], |
106
|
4 |
|
'integer', |
107
|
4 |
|
], |
108
|
|
|
[ |
109
|
4 |
|
['name', 'market_Category'], |
110
|
4 |
|
'string', |
111
|
4 |
|
], |
112
|
|
|
[ |
113
|
4 |
|
['url'], |
114
|
4 |
|
'url', |
115
|
4 |
|
], |
116
|
|
|
[ |
117
|
4 |
|
['price', 'oldprice'], |
118
|
4 |
|
'double', |
119
|
4 |
|
], |
120
|
|
|
[ |
121
|
|
|
[ |
122
|
4 |
|
'currencyId', |
123
|
4 |
|
], |
124
|
4 |
|
'in', |
125
|
|
|
'range' => [ |
126
|
4 |
|
'RUR', |
127
|
4 |
|
'UAH', |
128
|
4 |
|
'BYR', |
129
|
4 |
|
'KZT', |
130
|
4 |
|
'USD', |
131
|
|
|
'EUR' |
132
|
4 |
|
], |
133
|
4 |
|
], |
134
|
|
|
[ |
135
|
4 |
|
['description'], |
136
|
4 |
|
'string', |
137
|
4 |
|
], |
138
|
|
|
[ |
139
|
4 |
|
['pictures'], |
140
|
6 |
|
function ($attribute, $params) { |
|
|
|
|
141
|
6 |
|
if (count($this->pictures) > 10) { |
142
|
|
|
$this->addError('pictures', 'maximum 10 pictures'); |
143
|
|
|
} |
144
|
6 |
|
} |
145
|
4 |
|
], |
146
|
|
|
[ |
147
|
4 |
|
['params'], |
148
|
4 |
|
'each', |
149
|
4 |
|
'rule' => ['string'] |
150
|
4 |
|
], |
151
|
|
|
[ |
152
|
4 |
|
['pictures'], |
153
|
4 |
|
'each', |
154
|
4 |
|
'rule' => ['url'] |
155
|
4 |
|
] |
156
|
4 |
|
]; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @param array $params |
161
|
|
|
*/ |
162
|
6 |
|
public function setParams(array $params) |
163
|
|
|
{ |
164
|
6 |
|
$this->params = $params; |
165
|
6 |
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @param array $pictures |
169
|
|
|
*/ |
170
|
6 |
|
public function setPictures(array $pictures) |
171
|
|
|
{ |
172
|
6 |
|
$this->pictures = $pictures; |
173
|
6 |
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @inheritdoc |
177
|
|
|
*/ |
178
|
6 |
|
protected function getYmlBody() |
179
|
|
|
{ |
180
|
6 |
|
$string = ''; |
181
|
|
|
|
182
|
6 |
|
foreach ($this->getYmlAttributes() as $attribute) { |
183
|
6 |
|
$string .= $this->getYmlAttribute($attribute); |
184
|
4 |
|
} |
185
|
|
|
|
186
|
6 |
|
foreach ($this->params as $name => $value) { |
187
|
|
|
$string .= $this->getYmlParamTag($name, $value); |
188
|
4 |
|
} |
189
|
|
|
|
190
|
6 |
|
foreach ($this->pictures as $picture) { |
191
|
6 |
|
$string .= $this->getYmlPictureTag($picture); |
192
|
4 |
|
} |
193
|
|
|
|
194
|
6 |
|
return $string; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @param string $attribute |
200
|
|
|
* @param string $value |
201
|
|
|
* @return string |
202
|
|
|
*/ |
203
|
|
View Code Duplication |
protected function getYmlParamTag($attribute, $value) |
|
|
|
|
204
|
|
|
{ |
205
|
|
|
if ($value === null) { |
206
|
|
|
return ''; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
$string = '<param name="' . $attribute . '">' . $value . '</param>' . PHP_EOL; |
210
|
|
|
|
211
|
|
|
return $string; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @param string $value |
216
|
|
|
* @return string |
217
|
|
|
*/ |
218
|
6 |
View Code Duplication |
protected function getYmlPictureTag($value) |
|
|
|
|
219
|
|
|
{ |
220
|
6 |
|
if ($value === null) { |
221
|
|
|
return ''; |
222
|
|
|
} |
223
|
|
|
|
224
|
6 |
|
$string = '<picture>' . $value . '</picture>' . PHP_EOL; |
225
|
|
|
|
226
|
6 |
|
return $string; |
227
|
|
|
} |
228
|
|
|
} |
229
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.