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
|
4 |
|
public function getYmlAttributes() |
53
|
|
|
{ |
54
|
|
|
return [ |
55
|
4 |
|
'url', |
56
|
2 |
|
'price', |
57
|
2 |
|
'oldprice', |
58
|
2 |
|
'currencyId', |
59
|
2 |
|
'categoryId', |
60
|
2 |
|
'market_Category', |
61
|
2 |
|
'store', |
62
|
2 |
|
'pickup', |
63
|
2 |
|
'delivery', |
64
|
2 |
|
'local_Delivery_Cost', |
65
|
2 |
|
'name', |
66
|
2 |
|
'vendor', |
67
|
2 |
|
'vendorCode', |
68
|
2 |
|
'description', |
69
|
2 |
|
'sales_Notes', |
70
|
2 |
|
'manufacturer_Warranty', |
71
|
2 |
|
'country_Of_Origin', |
72
|
2 |
|
'adult', |
73
|
2 |
|
'age', |
74
|
2 |
|
'barcode', |
75
|
2 |
|
'cpa', |
76
|
2 |
|
]; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @inheritdoc |
81
|
|
|
*/ |
82
|
6 |
|
public function rules() |
83
|
|
|
{ |
84
|
|
|
return [ |
85
|
|
|
[ |
86
|
2 |
|
['id', 'price', 'currencyId', 'categoryId', 'name', 'available'], |
87
|
2 |
|
'required', |
88
|
4 |
|
], |
89
|
|
|
[ |
90
|
2 |
|
['sales_Notes'], |
91
|
2 |
|
'string', |
92
|
2 |
|
'max' => 50, |
93
|
2 |
|
], |
94
|
|
|
[ |
95
|
2 |
|
['name', 'vendor'], |
96
|
2 |
|
'string', |
97
|
2 |
|
'max' => 120, |
98
|
2 |
|
], |
99
|
|
|
[ |
100
|
2 |
|
['delivery'], |
101
|
2 |
|
'string', |
102
|
2 |
|
'max' => 4, |
103
|
2 |
|
], |
104
|
|
|
[ |
105
|
2 |
|
['id', 'categoryId', 'bid', 'cbid'], |
106
|
2 |
|
'integer', |
107
|
2 |
|
], |
108
|
|
|
[ |
109
|
2 |
|
['url'], |
110
|
2 |
|
'url', |
111
|
2 |
|
], |
112
|
|
|
[ |
113
|
2 |
|
['price', 'oldprice'], |
114
|
2 |
|
'double', |
115
|
2 |
|
], |
116
|
|
|
[ |
117
|
|
|
[ |
118
|
2 |
|
'currencyId', |
119
|
2 |
|
], |
120
|
2 |
|
'in', |
121
|
|
|
'range' => [ |
122
|
2 |
|
'RUR', |
123
|
2 |
|
'UAH', |
124
|
2 |
|
'BYR', |
125
|
2 |
|
'KZT', |
126
|
2 |
|
'USD', |
127
|
|
|
'EUR' |
128
|
2 |
|
], |
129
|
2 |
|
], |
130
|
|
|
[ |
131
|
2 |
|
['description'], |
132
|
2 |
|
'string', |
133
|
2 |
|
'max' => 175, |
134
|
2 |
|
], |
135
|
4 |
|
]; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @param array $params |
140
|
|
|
*/ |
141
|
4 |
|
public function setParams(array $params) |
142
|
|
|
{ |
143
|
4 |
|
$this->params = $params; |
144
|
4 |
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @param array $pictures |
148
|
|
|
*/ |
149
|
4 |
|
public function setPictures(array $pictures) |
150
|
|
|
{ |
151
|
4 |
|
$this->pictures = $pictures; |
152
|
4 |
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @inheritdoc |
156
|
|
|
*/ |
157
|
4 |
|
protected function getYmlBody() |
158
|
|
|
{ |
159
|
4 |
|
$string = ''; |
160
|
|
|
|
161
|
4 |
|
foreach ($this->getYmlAttributes() as $attribute) { |
162
|
4 |
|
$string .= $this->getYmlAttribute($attribute); |
163
|
2 |
|
} |
164
|
|
|
|
165
|
4 |
|
foreach ($this->params as $name => $value) { |
166
|
|
|
$string .= $this->getYmlParamTag($name, $value); |
167
|
2 |
|
} |
168
|
|
|
|
169
|
4 |
|
foreach ($this->pictures as $picture) { |
170
|
4 |
|
$string .= $this->getYmlPictureTag($picture); |
171
|
2 |
|
} |
172
|
|
|
|
173
|
4 |
|
return $string; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @param string $attribute |
179
|
|
|
* @param string $value |
180
|
|
|
* @return string |
181
|
|
|
*/ |
182
|
|
View Code Duplication |
protected function getYmlParamTag($attribute, $value) |
|
|
|
|
183
|
|
|
{ |
184
|
|
|
if ($value === null) { |
185
|
|
|
return ''; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
$string = '<param name="' . $attribute . '">' . $value . '</param>' . PHP_EOL; |
189
|
|
|
|
190
|
|
|
return $string; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @param string $value |
195
|
|
|
* @return string |
196
|
|
|
*/ |
197
|
4 |
View Code Duplication |
protected function getYmlPictureTag($value) |
|
|
|
|
198
|
|
|
{ |
199
|
4 |
|
if ($value === null) { |
200
|
|
|
return ''; |
201
|
|
|
} |
202
|
|
|
|
203
|
4 |
|
$string = '<picture>' . $value . '</picture>' . PHP_EOL; |
204
|
|
|
|
205
|
4 |
|
return $string; |
206
|
|
|
} |
207
|
|
|
} |
208
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.