1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Bukashk0zzzYmlGenerator |
5
|
|
|
* |
6
|
|
|
* (c) Denis Golubovskiy <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Bukashk0zzz\YmlGenerator\Model\Offer; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Abstract Class Offer |
16
|
|
|
*/ |
17
|
|
|
abstract class AbstractOffer implements OfferInterface |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
private $id; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var bool |
26
|
|
|
*/ |
27
|
|
|
private $available; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
private $url; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var float |
36
|
|
|
*/ |
37
|
|
|
private $price; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var float |
41
|
|
|
*/ |
42
|
|
|
private $oldPrice; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var string |
46
|
|
|
*/ |
47
|
|
|
private $currencyId; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var int |
51
|
|
|
*/ |
52
|
|
|
private $categoryId; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var string |
56
|
|
|
*/ |
57
|
|
|
private $marketCategory; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var bool |
61
|
|
|
*/ |
62
|
|
|
private $adult; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @var string |
66
|
|
|
*/ |
67
|
|
|
private $salesNotes; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @var bool |
71
|
|
|
*/ |
72
|
|
|
private $manufacturerWarranty; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @var bool |
76
|
|
|
*/ |
77
|
|
|
private $pickup; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @var bool |
81
|
|
|
*/ |
82
|
|
|
private $downloadable; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @var bool |
86
|
|
|
*/ |
87
|
|
|
private $delivery; |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @var float |
91
|
|
|
*/ |
92
|
|
|
private $localDeliveryCost; |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @var string |
96
|
|
|
*/ |
97
|
|
|
private $description; |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @var string |
101
|
|
|
*/ |
102
|
|
|
private $countryOfOrigin; |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @var int |
106
|
|
|
*/ |
107
|
|
|
private $cpa; |
108
|
|
|
|
109
|
|
|
/** @var string[] */ |
110
|
|
|
private $barcodes; |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @var array |
114
|
|
|
*/ |
115
|
|
|
private $pictures = []; |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @var array |
119
|
|
|
*/ |
120
|
|
|
private $params = []; |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @return array |
124
|
|
|
*/ |
125
|
|
|
public function toArray() |
126
|
|
|
{ |
127
|
|
|
return \array_merge($this->getHeaderOptions(), $this->getOptions(), $this->getFooterOptions()); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @return string |
132
|
|
|
*/ |
133
|
|
|
public function getId() |
134
|
|
|
{ |
135
|
|
|
return $this->id; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @param string $id |
140
|
|
|
* |
141
|
|
|
* @return $this |
142
|
|
|
*/ |
143
|
|
|
public function setId($id) |
144
|
|
|
{ |
145
|
|
|
$this->id = $id; |
146
|
|
|
|
147
|
|
|
return $this; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @return bool |
152
|
|
|
*/ |
153
|
|
|
public function isAvailable() |
154
|
|
|
{ |
155
|
|
|
return $this->available; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @param bool $available |
160
|
|
|
* |
161
|
|
|
* @return $this |
162
|
|
|
*/ |
163
|
|
|
public function setAvailable($available) |
164
|
|
|
{ |
165
|
|
|
$this->available = $available; |
166
|
|
|
|
167
|
|
|
return $this; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @return string |
172
|
|
|
*/ |
173
|
|
|
public function getUrl() |
174
|
|
|
{ |
175
|
|
|
return $this->url; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @param string $url |
180
|
|
|
* |
181
|
|
|
* @return $this |
182
|
|
|
*/ |
183
|
|
|
public function setUrl($url) |
184
|
|
|
{ |
185
|
|
|
$this->url = $url; |
186
|
|
|
|
187
|
|
|
return $this; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @return float |
192
|
|
|
*/ |
193
|
|
|
public function getPrice() |
194
|
|
|
{ |
195
|
|
|
return $this->price; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @param float $price |
200
|
|
|
* |
201
|
|
|
* @return $this |
202
|
|
|
*/ |
203
|
|
|
public function setPrice($price) |
204
|
|
|
{ |
205
|
|
|
$this->price = $price; |
206
|
|
|
|
207
|
|
|
return $this; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* @return float |
212
|
|
|
*/ |
213
|
|
|
public function getOldPrice() |
214
|
|
|
{ |
215
|
|
|
return $this->oldPrice; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* @param float $oldPrice |
220
|
|
|
* |
221
|
|
|
* @return $this |
222
|
|
|
*/ |
223
|
|
|
public function setOldPrice($oldPrice) |
224
|
|
|
{ |
225
|
|
|
$this->oldPrice = $oldPrice; |
226
|
|
|
|
227
|
|
|
return $this; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* @return string |
232
|
|
|
*/ |
233
|
|
|
public function getCurrencyId() |
234
|
|
|
{ |
235
|
|
|
return $this->currencyId; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @param string $currencyId |
240
|
|
|
* |
241
|
|
|
* @return $this |
242
|
|
|
*/ |
243
|
|
|
public function setCurrencyId($currencyId) |
244
|
|
|
{ |
245
|
|
|
$this->currencyId = $currencyId; |
246
|
|
|
|
247
|
|
|
return $this; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* @return int |
252
|
|
|
*/ |
253
|
|
|
public function getCategoryId() |
254
|
|
|
{ |
255
|
|
|
return $this->categoryId; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* @param int $categoryId |
260
|
|
|
* |
261
|
|
|
* @return $this |
262
|
|
|
*/ |
263
|
|
|
public function setCategoryId($categoryId) |
264
|
|
|
{ |
265
|
|
|
$this->categoryId = $categoryId; |
266
|
|
|
|
267
|
|
|
return $this; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* @return string |
272
|
|
|
*/ |
273
|
|
|
public function getMarketCategory() |
274
|
|
|
{ |
275
|
|
|
return $this->marketCategory; |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* @param string $marketCategory |
280
|
|
|
* |
281
|
|
|
* @return $this |
282
|
|
|
*/ |
283
|
|
|
public function setMarketCategory($marketCategory) |
284
|
|
|
{ |
285
|
|
|
$this->marketCategory = $marketCategory; |
286
|
|
|
|
287
|
|
|
return $this; |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* @return bool |
292
|
|
|
*/ |
293
|
|
|
public function isAdult() |
294
|
|
|
{ |
295
|
|
|
return $this->adult; |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* @param bool $adult |
300
|
|
|
* |
301
|
|
|
* @return $this |
302
|
|
|
*/ |
303
|
|
|
public function setAdult($adult) |
304
|
|
|
{ |
305
|
|
|
$this->adult = $adult; |
306
|
|
|
|
307
|
|
|
return $this; |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* @return string |
312
|
|
|
*/ |
313
|
|
|
public function getSalesNotes() |
314
|
|
|
{ |
315
|
|
|
return $this->salesNotes; |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
/** |
319
|
|
|
* @param string $salesNotes |
320
|
|
|
* |
321
|
|
|
* @return $this |
322
|
|
|
*/ |
323
|
|
|
public function setSalesNotes($salesNotes) |
324
|
|
|
{ |
325
|
|
|
$this->salesNotes = $salesNotes; |
326
|
|
|
|
327
|
|
|
return $this; |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
/** |
331
|
|
|
* @return bool |
332
|
|
|
*/ |
333
|
|
|
public function isManufacturerWarranty() |
334
|
|
|
{ |
335
|
|
|
return $this->manufacturerWarranty; |
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
/** |
339
|
|
|
* @param bool $manufacturerWarranty |
340
|
|
|
* |
341
|
|
|
* @return $this |
342
|
|
|
*/ |
343
|
|
|
public function setManufacturerWarranty($manufacturerWarranty) |
344
|
|
|
{ |
345
|
|
|
$this->manufacturerWarranty = $manufacturerWarranty; |
346
|
|
|
|
347
|
|
|
return $this; |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
/** |
351
|
|
|
* @return bool |
352
|
|
|
*/ |
353
|
|
|
public function isPickup() |
354
|
|
|
{ |
355
|
|
|
return $this->pickup; |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
/** |
359
|
|
|
* @param bool $pickup |
360
|
|
|
* |
361
|
|
|
* @return $this |
362
|
|
|
*/ |
363
|
|
|
public function setPickup($pickup) |
364
|
|
|
{ |
365
|
|
|
$this->pickup = $pickup; |
366
|
|
|
|
367
|
|
|
return $this; |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
/** |
371
|
|
|
* @return bool |
372
|
|
|
*/ |
373
|
|
|
public function isDownloadable() |
374
|
|
|
{ |
375
|
|
|
return $this->downloadable; |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
/** |
379
|
|
|
* @param bool $downloadable |
380
|
|
|
* |
381
|
|
|
* @return $this |
382
|
|
|
*/ |
383
|
|
|
public function setDownloadable($downloadable) |
384
|
|
|
{ |
385
|
|
|
$this->downloadable = $downloadable; |
386
|
|
|
|
387
|
|
|
return $this; |
388
|
|
|
} |
389
|
|
|
|
390
|
|
|
/** |
391
|
|
|
* @return bool |
392
|
|
|
*/ |
393
|
|
|
public function isDelivery() |
394
|
|
|
{ |
395
|
|
|
return $this->delivery; |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
/** |
399
|
|
|
* @param bool $delivery |
400
|
|
|
* |
401
|
|
|
* @return $this |
402
|
|
|
*/ |
403
|
|
|
public function setDelivery($delivery) |
404
|
|
|
{ |
405
|
|
|
$this->delivery = $delivery; |
406
|
|
|
|
407
|
|
|
return $this; |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
/** |
411
|
|
|
* @return float |
412
|
|
|
*/ |
413
|
|
|
public function getLocalDeliveryCost() |
414
|
|
|
{ |
415
|
|
|
return $this->localDeliveryCost; |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
/** |
419
|
|
|
* @param float $localDeliveryCost |
420
|
|
|
* |
421
|
|
|
* @return $this |
422
|
|
|
*/ |
423
|
|
|
public function setLocalDeliveryCost($localDeliveryCost) |
424
|
|
|
{ |
425
|
|
|
$this->localDeliveryCost = $localDeliveryCost; |
426
|
|
|
|
427
|
|
|
return $this; |
428
|
|
|
} |
429
|
|
|
|
430
|
|
|
/** |
431
|
|
|
* @return string |
432
|
|
|
*/ |
433
|
|
|
public function getDescription() |
434
|
|
|
{ |
435
|
|
|
return $this->description; |
436
|
|
|
} |
437
|
|
|
|
438
|
|
|
/** |
439
|
|
|
* @param string $description |
440
|
|
|
* |
441
|
|
|
* @return $this |
442
|
|
|
*/ |
443
|
|
|
public function setDescription($description) |
444
|
|
|
{ |
445
|
|
|
$this->description = $description; |
446
|
|
|
|
447
|
|
|
return $this; |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
/** |
451
|
|
|
* @return string |
452
|
|
|
*/ |
453
|
|
|
public function getCountryOfOrigin() |
454
|
|
|
{ |
455
|
|
|
return $this->countryOfOrigin; |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
/** |
459
|
|
|
* @param string $countryOfOrigin |
460
|
|
|
* |
461
|
|
|
* @return $this |
462
|
|
|
*/ |
463
|
|
|
public function setCountryOfOrigin($countryOfOrigin) |
464
|
|
|
{ |
465
|
|
|
$this->countryOfOrigin = $countryOfOrigin; |
466
|
|
|
|
467
|
|
|
return $this; |
468
|
|
|
} |
469
|
|
|
|
470
|
|
|
/** |
471
|
|
|
* @return int |
472
|
|
|
*/ |
473
|
|
|
public function getCpa() |
474
|
|
|
{ |
475
|
|
|
return $this->cpa; |
476
|
|
|
} |
477
|
|
|
|
478
|
|
|
/** |
479
|
|
|
* @param int $cpa |
480
|
|
|
* |
481
|
|
|
* @return $this |
482
|
|
|
*/ |
483
|
|
|
public function setCpa($cpa) |
484
|
|
|
{ |
485
|
|
|
$this->cpa = $cpa; |
486
|
|
|
|
487
|
|
|
return $this; |
488
|
|
|
} |
489
|
|
|
|
490
|
|
|
/** |
491
|
|
|
* @return array |
492
|
|
|
*/ |
493
|
|
|
public function getParams() |
494
|
|
|
{ |
495
|
|
|
return $this->params; |
496
|
|
|
} |
497
|
|
|
|
498
|
|
|
/** |
499
|
|
|
* @param OfferParam $param |
500
|
|
|
* |
501
|
|
|
* @return $this |
502
|
|
|
*/ |
503
|
|
|
public function addParam(OfferParam $param) |
504
|
|
|
{ |
505
|
|
|
$this->params[] = $param; |
506
|
|
|
|
507
|
|
|
return $this; |
508
|
|
|
} |
509
|
|
|
|
510
|
|
|
/** |
511
|
|
|
* Add picture |
512
|
|
|
* |
513
|
|
|
* @param string $url |
514
|
|
|
* |
515
|
|
|
* @return $this |
516
|
|
|
*/ |
517
|
|
|
public function addPicture($url) |
518
|
|
|
{ |
519
|
|
|
if (\count($this->pictures) < 10) { |
520
|
|
|
$this->pictures[] = $url; |
521
|
|
|
} |
522
|
|
|
|
523
|
|
|
return $this; |
524
|
|
|
} |
525
|
|
|
|
526
|
|
|
/** |
527
|
|
|
* Set pictures |
528
|
|
|
* |
529
|
|
|
* @param array $pictures |
530
|
|
|
* |
531
|
|
|
* @return $this |
532
|
|
|
*/ |
533
|
|
|
public function setPictures(array $pictures) |
534
|
|
|
{ |
535
|
|
|
$this->pictures = $pictures; |
536
|
|
|
|
537
|
|
|
return $this; |
538
|
|
|
} |
539
|
|
|
|
540
|
|
|
/** |
541
|
|
|
* Get picture list |
542
|
|
|
* |
543
|
|
|
* @return array |
544
|
|
|
*/ |
545
|
|
|
public function getPictures() |
546
|
|
|
{ |
547
|
|
|
return $this->pictures; |
548
|
|
|
} |
549
|
|
|
|
550
|
|
|
/** |
551
|
|
|
* Get list of barcodes of the offer |
552
|
|
|
* |
553
|
|
|
* @return string[] |
554
|
|
|
*/ |
555
|
|
|
public function getBarcodes() |
556
|
|
|
{ |
557
|
|
|
return $this->barcodes; |
558
|
|
|
} |
559
|
|
|
|
560
|
|
|
/** |
561
|
|
|
* Set list of barcodes for that offer |
562
|
|
|
* |
563
|
|
|
* @param string[] $barcodes |
564
|
|
|
* |
565
|
|
|
* @return $this |
566
|
|
|
*/ |
567
|
|
|
public function setBarcodes(array $barcodes = []) |
568
|
|
|
{ |
569
|
|
|
$this->barcodes = $barcodes; |
570
|
|
|
|
571
|
|
|
return $this; |
572
|
|
|
} |
573
|
|
|
|
574
|
|
|
/** |
575
|
|
|
* Add one barcode to the collection of barcodes of this offer |
576
|
|
|
* |
577
|
|
|
* @param string $barcode |
578
|
|
|
* |
579
|
|
|
* @return AbstractOffer |
580
|
|
|
*/ |
581
|
|
|
public function addBarcode($barcode) |
582
|
|
|
{ |
583
|
|
|
$this->barcodes[] = $barcode; |
584
|
|
|
|
585
|
|
|
return $this; |
586
|
|
|
} |
587
|
|
|
|
588
|
|
|
/** |
589
|
|
|
* @return array |
590
|
|
|
*/ |
591
|
|
|
abstract protected function getOptions(); |
592
|
|
|
|
593
|
|
|
/** |
594
|
|
|
* @return array |
595
|
|
|
*/ |
596
|
|
|
private function getHeaderOptions() |
597
|
|
|
{ |
598
|
|
|
return [ |
599
|
|
|
'url' => $this->getUrl(), |
600
|
|
|
'price' => $this->getPrice(), |
601
|
|
|
'oldprice' => $this->getOldPrice(), |
602
|
|
|
'currencyId' => $this->getCurrencyId(), |
603
|
|
|
'categoryId' => $this->getCategoryId(), |
604
|
|
|
'market_category' => $this->getMarketCategory(), |
605
|
|
|
'picture' => $this->getPictures(), |
606
|
|
|
'pickup' => $this->isPickup(), |
607
|
|
|
'delivery' => $this->isDelivery(), |
608
|
|
|
'local_delivery_cost' => $this->getLocalDeliveryCost(), |
609
|
|
|
]; |
610
|
|
|
} |
611
|
|
|
|
612
|
|
|
/** |
613
|
|
|
* @return array |
614
|
|
|
*/ |
615
|
|
|
private function getFooterOptions() |
616
|
|
|
{ |
617
|
|
|
return [ |
618
|
|
|
'description' => $this->getDescription(), |
619
|
|
|
'sales_notes' => $this->getSalesNotes(), |
620
|
|
|
'manufacturer_warranty' => $this->isManufacturerWarranty(), |
621
|
|
|
'country_of_origin' => $this->getCountryOfOrigin(), |
622
|
|
|
'downloadable' => $this->isDownloadable(), |
623
|
|
|
'adult' => $this->isAdult(), |
624
|
|
|
'cpa' => $this->getCpa(), |
625
|
|
|
'barcode' => $this->getBarcodes(), |
626
|
|
|
]; |
627
|
|
|
} |
628
|
|
|
} |
629
|
|
|
|