Completed
Pull Request — master (#20)
by
unknown
07:39
created

AbstractOffer::setOldPrice()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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 array
56
     */
57
    private $categoriesId = [];
58
59
    /**
60
     * @var string
61
     */
62
    private $marketCategory;
63
64
    /**
65
     * @var bool
66
     */
67
    private $adult;
68
69
    /**
70
     * @var string
71
     */
72
    private $salesNotes;
73
74
    /**
75
     * @var bool
76
     */
77
    private $manufacturerWarranty;
78
79
    /**
80
     * @var bool
81
     */
82
    private $pickup;
83
84
    /**
85
     * @var bool
86
     */
87
    private $downloadable;
88
89
    /**
90
     * @var bool
91
     */
92
    private $delivery;
93
94
    /**
95
     * @var float
96
     */
97
    private $localDeliveryCost;
98
99
    /**
100
     * @var string
101
     */
102
    private $description;
103
104
    /**
105
     * @var string
106
     */
107
    private $countryOfOrigin;
108
109
    /**
110
     * @var string
111
     */
112
    private $weight;
113
114
    /**
115
     * @var int
116
     */
117
    private $cpa;
118
119
    /** @var string[] */
120
    private $barcodes;
121
122
    /**
123
     * @var array
124
     */
125
    private $pictures = [];
126
127
    /**
128
     * @var array
129
     */
130
    private $params = [];
131
132
    /**
133
     * @var bool
134
     */
135
    private $store;
136
137
    /**
138
     * @return array
139
     */
140
    public function toArray()
141
    {
142
        return \array_merge($this->getHeaderOptions(), $this->getOptions(), $this->getFooterOptions());
143
    }
144
145
    /**
146
     * @return string
147
     */
148
    public function getId()
149
    {
150
        return $this->id;
151
    }
152
153
    /**
154
     * @param string $id
155
     *
156
     * @return $this
157
     */
158
    public function setId($id)
159
    {
160
        $this->id = $id;
161
162
        return $this;
163
    }
164
165
    /**
166
     * @return bool
167
     */
168
    public function isAvailable()
169
    {
170
        return $this->available;
171
    }
172
173
    /**
174
     * @param bool $available
175
     *
176
     * @return $this
177
     */
178
    public function setAvailable($available)
179
    {
180
        $this->available = $available;
181
182
        return $this;
183
    }
184
185
    /**
186
     * @return string
187
     */
188
    public function getUrl()
189
    {
190
        return $this->url;
191
    }
192
193
    /**
194
     * @param string $url
195
     *
196
     * @return $this
197
     */
198
    public function setUrl($url)
199
    {
200
        $this->url = $url;
201
202
        return $this;
203
    }
204
205
    /**
206
     * @return float
207
     */
208
    public function getPrice()
209
    {
210
        return $this->price;
211
    }
212
213
    /**
214
     * @param float $price
215
     *
216
     * @return $this
217
     */
218
    public function setPrice($price)
219
    {
220
        $this->price = $price;
221
222
        return $this;
223
    }
224
225
    /**
226
     * @return float
227
     */
228
    public function getOldPrice()
229
    {
230
        return $this->oldPrice;
231
    }
232
233
    /**
234
     * @param float $oldPrice
235
     *
236
     * @return $this
237
     */
238
    public function setOldPrice($oldPrice)
239
    {
240
        $this->oldPrice = $oldPrice;
241
242
        return $this;
243
    }
244
245
    /**
246
     * @return string
247
     */
248
    public function getCurrencyId()
249
    {
250
        return $this->currencyId;
251
    }
252
253
    /**
254
     * @param string $currencyId
255
     *
256
     * @return $this
257
     */
258
    public function setCurrencyId($currencyId)
259
    {
260
        $this->currencyId = $currencyId;
261
262
        return $this;
263
    }
264
265
    /**
266
     * @return int
267
     */
268
    public function getCategoryId()
269
    {
270
        return $this->categoryId;
271
    }
272
273
    /**
274
     * @param int $categoryId
275
     *
276
     * @return $this
277
     */
278
    public function setCategoryId($categoryId)
279
    {
280
        $this->categoryId = $categoryId;
281
282
        return $this;
283
    }
284
285
    /**
286
     * @return array
287
     */
288
    public function getCategoriesId()
289
    {
290
        return $this->categoriesId;
291
    }
292
293
    /**
294
     * @param array $categoriesId
295
     *
296
     * @return $this
297
     */
298
    public function setCategoriesId(array $categoriesId)
299
    {
300
        $this->categoriesId = $categoriesId;
301
302
        return $this;
303
    }
304
305
    /**
306
     * @return string
307
     */
308
    public function getMarketCategory()
309
    {
310
        return $this->marketCategory;
311
    }
312
313
    /**
314
     * @param string $marketCategory
315
     *
316
     * @return $this
317
     */
318
    public function setMarketCategory($marketCategory)
319
    {
320
        $this->marketCategory = $marketCategory;
321
322
        return $this;
323
    }
324
325
    /**
326
     * @return bool
327
     */
328
    public function isAdult()
329
    {
330
        return $this->adult;
331
    }
332
333
    /**
334
     * @param bool $adult
335
     *
336
     * @return $this
337
     */
338
    public function setAdult($adult)
339
    {
340
        $this->adult = $adult;
341
342
        return $this;
343
    }
344
345
    /**
346
     * @return string
347
     */
348
    public function getSalesNotes()
349
    {
350
        return $this->salesNotes;
351
    }
352
353
    /**
354
     * @param string $salesNotes
355
     *
356
     * @return $this
357
     */
358
    public function setSalesNotes($salesNotes)
359
    {
360
        $this->salesNotes = $salesNotes;
361
362
        return $this;
363
    }
364
365
    /**
366
     * @return bool
367
     */
368
    public function isManufacturerWarranty()
369
    {
370
        return $this->manufacturerWarranty;
371
    }
372
373
    /**
374
     * @param bool $manufacturerWarranty
375
     *
376
     * @return $this
377
     */
378
    public function setManufacturerWarranty($manufacturerWarranty)
379
    {
380
        $this->manufacturerWarranty = $manufacturerWarranty;
381
382
        return $this;
383
    }
384
385
    /**
386
     * @return bool
387
     */
388
    public function isPickup()
389
    {
390
        return $this->pickup;
391
    }
392
393
    /**
394
     * @param bool $pickup
395
     *
396
     * @return $this
397
     */
398
    public function setPickup($pickup)
399
    {
400
        $this->pickup = $pickup;
401
402
        return $this;
403
    }
404
405
    /**
406
     * @return bool
407
     */
408
    public function isDownloadable()
409
    {
410
        return $this->downloadable;
411
    }
412
413
    /**
414
     * @param bool $downloadable
415
     *
416
     * @return $this
417
     */
418
    public function setDownloadable($downloadable)
419
    {
420
        $this->downloadable = $downloadable;
421
422
        return $this;
423
    }
424
425
    /**
426
     * @return bool
427
     */
428
    public function isDelivery()
429
    {
430
        return $this->delivery;
431
    }
432
433
    /**
434
     * @param bool $delivery
435
     *
436
     * @return $this
437
     */
438
    public function setDelivery($delivery)
439
    {
440
        $this->delivery = $delivery;
441
442
        return $this;
443
    }
444
445
446
    /**
447
     * @param bool $store
448
     *
449
     * @return $this
450
     */
451
    public function setStore($store)
452
    {
453
        $this->store = $store;
454
455
        return $this;
456
    }
457
458
    /**
459
     * @return bool
460
     */
461
    public function isStore()
462
    {
463
        return $this->store;
464
    }
465
466
    /**
467
     * @param bool $store
468
     *
469
     * @return $this
470
     */
471
    public function setStore($store)
472
    {
473
        $this->store = $store;
474
475
        return $this;
476
    }
477
478
    /**
479
     * @return bool
480
     */
481
    public function isStore()
482
    {
483
        return $this->store;
484
    }
485
486
    /**
487
     * @return float
488
     */
489
    public function getLocalDeliveryCost()
490
    {
491
        return $this->localDeliveryCost;
492
    }
493
494
    /**
495
     * @param float $localDeliveryCost
496
     *
497
     * @return $this
498
     */
499
    public function setLocalDeliveryCost($localDeliveryCost)
500
    {
501
        $this->localDeliveryCost = $localDeliveryCost;
502
503
        return $this;
504
    }
505
506
    /**
507
     * @return string
508
     */
509
    public function getDescription()
510
    {
511
        return $this->description;
512
    }
513
514
    /**
515
     * @param string $description
516
     *
517
     * @return $this
518
     */
519
    public function setDescription($description)
520
    {
521
        $this->description = $description;
522
523
        return $this;
524
    }
525
526
    /**
527
     * @return string
528
     */
529
    public function getCountryOfOrigin()
530
    {
531
        return $this->countryOfOrigin;
532
    }
533
534
    /**
535
     * @param string $countryOfOrigin
536
     *
537
     * @return $this
538
     */
539
    public function setCountryOfOrigin($countryOfOrigin)
540
    {
541
        $this->countryOfOrigin = $countryOfOrigin;
542
543
        return $this;
544
    }
545
546
    /**
547
     * @return string
548
     */
549
    public function getWeight()
550
    {
551
        return $this->weight;
552
    }
553
554
    /**
555
     * @param string $weight
556
     *
557
     * @return $this
558
     */
559
    public function setWeight($weight)
560
    {
561
        $this->weight = $weight;
562
563
        return $this;
564
    }
565
566
    /**
567
     * @return int
568
     */
569
    public function getCpa()
570
    {
571
        return $this->cpa;
572
    }
573
574
    /**
575
     * @param int $cpa
576
     *
577
     * @return $this
578
     */
579
    public function setCpa($cpa)
580
    {
581
        $this->cpa = $cpa;
582
583
        return $this;
584
    }
585
586
    /**
587
     * @return array
588
     */
589
    public function getParams()
590
    {
591
        return $this->params;
592
    }
593
594
    /**
595
     * @param OfferParam $param
596
     *
597
     * @return $this
598
     */
599
    public function addParam(OfferParam $param)
600
    {
601
        $this->params[] = $param;
602
603
        return $this;
604
    }
605
606
    /**
607
     * Add picture
608
     *
609
     * @param string $url
610
     *
611
     * @return $this
612
     */
613
    public function addPicture($url)
614
    {
615
        if (\count($this->pictures) < 10) {
616
            $this->pictures[] = $url;
617
        }
618
619
        return $this;
620
    }
621
622
    /**
623
     * Set pictures
624
     *
625
     * @param array $pictures
626
     *
627
     * @return $this
628
     */
629
    public function setPictures(array $pictures)
630
    {
631
        $this->pictures = $pictures;
632
633
        return $this;
634
    }
635
636
    /**
637
     * Get picture list
638
     *
639
     * @return array
640
     */
641
    public function getPictures()
642
    {
643
        return $this->pictures;
644
    }
645
646
    /**
647
     * Get list of barcodes of the offer
648
     *
649
     * @return string[]
650
     */
651
    public function getBarcodes()
652
    {
653
        return $this->barcodes;
654
    }
655
656
    /**
657
     * Set list of barcodes for that offer
658
     *
659
     * @param string[] $barcodes
660
     *
661
     * @return $this
662
     */
663
    public function setBarcodes(array $barcodes = [])
664
    {
665
        $this->barcodes = $barcodes;
666
667
        return $this;
668
    }
669
670
    /**
671
     * Add one barcode to the collection of barcodes of this offer
672
     *
673
     * @param string $barcode
674
     *
675
     * @return AbstractOffer
676
     */
677
    public function addBarcode($barcode)
678
    {
679
        $this->barcodes[] = $barcode;
680
681
        return $this;
682
    }
683
684
    /**
685
     * @return array
686
     */
687
    abstract protected function getOptions();
688
689
    /**
690
     * @return array
691
     */
692
    private function getHeaderOptions()
693
    {
694
        return [
695
            'url' => $this->getUrl(),
696
            'price' => $this->getPrice(),
697
            'oldprice' => $this->getOldPrice(),
698
            'currencyId' => $this->getCurrencyId(),
699
            'categoryId' => array_merge(
700
                [$this->getCategoryId()],
701
                $this->getCategoriesId()
702
            ),
703
            'market_category' => $this->getMarketCategory(),
704
            'picture' => $this->getPictures(),
705
            'pickup' => $this->isPickup(),
706
            'store' => $this->isStore(),
707
            'delivery' => $this->isDelivery(),
708
            'weight' => $this->getWeight(),
709
            'local_delivery_cost' => $this->getLocalDeliveryCost(),
710
        ];
711
    }
712
713
    /**
714
     * @return array
715
     */
716
    private function getFooterOptions()
717
    {
718
        return [
719
            'description' => $this->getDescription(),
720
            'sales_notes' => $this->getSalesNotes(),
721
            'manufacturer_warranty' => $this->isManufacturerWarranty(),
722
            'country_of_origin' => $this->getCountryOfOrigin(),
723
            'downloadable' => $this->isDownloadable(),
724
            'adult' => $this->isAdult(),
725
            'cpa' => $this->getCpa(),
726
            'barcode' => $this->getBarcodes()
727
        ];
728
    }
729
}
730