Completed
Pull Request — master (#20)
by
unknown
01:19
created

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