Completed
Pull Request — master (#21)
by
unknown
01:13
created

AbstractOffer::setPictures()   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 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 string
106
     */
107
    private $weight;
108
109
    /**
110
     * @var int
111
     */
112
    private $cpa;
113
114
    /** @var string[] */
115
    private $barcodes;
116
117
    /**
118
     * @var array
119
     */
120
    private $pictures = [];
121
122
    /**
123
     * @var array
124
     */
125
    private $params = [];
126
127
    /**
128
     * @var bool
129
     */
130
    private $store;
131
132
    /**
133
     * @var int
134
     */
135
    private $stockQuantity;
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 string
287
     */
288
    public function getMarketCategory()
289
    {
290
        return $this->marketCategory;
291
    }
292
293
    /**
294
     * @param string $marketCategory
295
     *
296
     * @return $this
297
     */
298
    public function setMarketCategory($marketCategory)
299
    {
300
        $this->marketCategory = $marketCategory;
301
302
        return $this;
303
    }
304
305
    /**
306
     * @return bool
307
     */
308
    public function isAdult()
309
    {
310
        return $this->adult;
311
    }
312
313
    /**
314
     * @param bool $adult
315
     *
316
     * @return $this
317
     */
318
    public function setAdult($adult)
319
    {
320
        $this->adult = $adult;
321
322
        return $this;
323
    }
324
325
    /**
326
     * @return string
327
     */
328
    public function getSalesNotes()
329
    {
330
        return $this->salesNotes;
331
    }
332
333
    /**
334
     * @param string $salesNotes
335
     *
336
     * @return $this
337
     */
338
    public function setSalesNotes($salesNotes)
339
    {
340
        $this->salesNotes = $salesNotes;
341
342
        return $this;
343
    }
344
345
    /**
346
     * @return bool
347
     */
348
    public function isManufacturerWarranty()
349
    {
350
        return $this->manufacturerWarranty;
351
    }
352
353
    /**
354
     * @param bool $manufacturerWarranty
355
     *
356
     * @return $this
357
     */
358
    public function setManufacturerWarranty($manufacturerWarranty)
359
    {
360
        $this->manufacturerWarranty = $manufacturerWarranty;
361
362
        return $this;
363
    }
364
365
    /**
366
     * @return bool
367
     */
368
    public function isPickup()
369
    {
370
        return $this->pickup;
371
    }
372
373
    /**
374
     * @param bool $pickup
375
     *
376
     * @return $this
377
     */
378
    public function setPickup($pickup)
379
    {
380
        $this->pickup = $pickup;
381
382
        return $this;
383
    }
384
385
    /**
386
     * @return bool
387
     */
388
    public function isDownloadable()
389
    {
390
        return $this->downloadable;
391
    }
392
393
    /**
394
     * @param bool $downloadable
395
     *
396
     * @return $this
397
     */
398
    public function setDownloadable($downloadable)
399
    {
400
        $this->downloadable = $downloadable;
401
402
        return $this;
403
    }
404
405
    /**
406
     * @return bool
407
     */
408
    public function isDelivery()
409
    {
410
        return $this->delivery;
411
    }
412
413
    /**
414
     * @param bool $delivery
415
     *
416
     * @return $this
417
     */
418
    public function setDelivery($delivery)
419
    {
420
        $this->delivery = $delivery;
421
422
        return $this;
423
    }
424
425
    /**
426
     * @param bool $store
427
     *
428
     * @return $this
429
     */
430
    public function setStore($store)
431
    {
432
        $this->store = $store;
433
434
        return $this;
435
    }
436
437
    /**
438
     * @return bool
439
     */
440
    public function isStore()
441
    {
442
        return $this->store;
443
    }
444
445
    /**
446
     *
447
     * @param int $stockQuantity
448
     *
449
     * @return $this
450
     */
451
    public function setStockQuantity($stockQuantity)
452
    {
453
        $this->stockQuantity = $stockQuantity;
454
455
        return $this;
456
    }
457
458
    /**
459
     * @return int
460
     */
461
    public function getStockQuantity()
462
    {
463
        return $this->stockQuantity;
464
    }
465
466
    /**
467
     * @return float
468
     */
469
    public function getLocalDeliveryCost()
470
    {
471
        return $this->localDeliveryCost;
472
    }
473
474
    /**
475
     * @param float $localDeliveryCost
476
     *
477
     * @return $this
478
     */
479
    public function setLocalDeliveryCost($localDeliveryCost)
480
    {
481
        $this->localDeliveryCost = $localDeliveryCost;
482
483
        return $this;
484
    }
485
486
    /**
487
     * @return string
488
     */
489
    public function getDescription()
490
    {
491
        return $this->description;
492
    }
493
494
    /**
495
     * @param string $description
496
     *
497
     * @return $this
498
     */
499
    public function setDescription($description)
500
    {
501
        $this->description = $description;
502
503
        return $this;
504
    }
505
506
    /**
507
     * @return string
508
     */
509
    public function getCountryOfOrigin()
510
    {
511
        return $this->countryOfOrigin;
512
    }
513
514
    /**
515
     * @param string $countryOfOrigin
516
     *
517
     * @return $this
518
     */
519
    public function setCountryOfOrigin($countryOfOrigin)
520
    {
521
        $this->countryOfOrigin = $countryOfOrigin;
522
523
        return $this;
524
    }
525
526
    /**
527
     * @return string
528
     */
529
    public function getWeight()
530
    {
531
        return $this->weight;
532
    }
533
534
    /**
535
     * @param string $weight
536
     *
537
     * @return $this
538
     */
539
    public function setWeight($weight)
540
    {
541
        $this->weight = $weight;
542
543
        return $this;
544
    }
545
546
    /**
547
     * @return int
548
     */
549
    public function getCpa()
550
    {
551
        return $this->cpa;
552
    }
553
554
    /**
555
     * @param int $cpa
556
     *
557
     * @return $this
558
     */
559
    public function setCpa($cpa)
560
    {
561
        $this->cpa = $cpa;
562
563
        return $this;
564
    }
565
566
    /**
567
     * @return array
568
     */
569
    public function getParams()
570
    {
571
        return $this->params;
572
    }
573
574
    /**
575
     * @param OfferParam $param
576
     *
577
     * @return $this
578
     */
579
    public function addParam(OfferParam $param)
580
    {
581
        $this->params[] = $param;
582
583
        return $this;
584
    }
585
586
    /**
587
     * Add picture
588
     *
589
     * @param string $url
590
     *
591
     * @return $this
592
     */
593
    public function addPicture($url)
594
    {
595
        if (\count($this->pictures) < 10) {
596
            $this->pictures[] = $url;
597
        }
598
599
        return $this;
600
    }
601
602
    /**
603
     * Set pictures
604
     *
605
     * @param array $pictures
606
     *
607
     * @return $this
608
     */
609
    public function setPictures(array $pictures)
610
    {
611
        $this->pictures = $pictures;
612
613
        return $this;
614
    }
615
616
    /**
617
     * Get picture list
618
     *
619
     * @return array
620
     */
621
    public function getPictures()
622
    {
623
        return $this->pictures;
624
    }
625
626
    /**
627
     * Get list of barcodes of the offer
628
     *
629
     * @return string[]
630
     */
631
    public function getBarcodes()
632
    {
633
        return $this->barcodes;
634
    }
635
636
    /**
637
     * Set list of barcodes for that offer
638
     *
639
     * @param string[] $barcodes
640
     *
641
     * @return $this
642
     */
643
    public function setBarcodes(array $barcodes = [])
644
    {
645
        $this->barcodes = $barcodes;
646
647
        return $this;
648
    }
649
650
    /**
651
     * Add one barcode to the collection of barcodes of this offer
652
     *
653
     * @param string $barcode
654
     *
655
     * @return AbstractOffer
656
     */
657
    public function addBarcode($barcode)
658
    {
659
        $this->barcodes[] = $barcode;
660
661
        return $this;
662
    }
663
664
    /**
665
     * @return array
666
     */
667
    abstract protected function getOptions();
668
669
    /**
670
     * @return array
671
     */
672
    private function getHeaderOptions()
673
    {
674
        return [
675
            'url' => $this->getUrl(),
676
            'price' => $this->getPrice(),
677
            'oldprice' => $this->getOldPrice(),
678
            'currencyId' => $this->getCurrencyId(),
679
            'categoryId' => $this->getCategoryId(),
680
            'market_category' => $this->getMarketCategory(),
681
            'picture' => $this->getPictures(),
682
            'pickup' => $this->isPickup(),
683
            'store' => $this->isStore(),
684
            'stock_quantity' => $this->getStockQuantity(),
685
            'delivery' => $this->isDelivery(),
686
            'weight' => $this->getWeight(),
687
            'local_delivery_cost' => $this->getLocalDeliveryCost(),
688
        ];
689
    }
690
691
    /**
692
     * @return array
693
     */
694
    private function getFooterOptions()
695
    {
696
        return [
697
            'description' => $this->getDescription(),
698
            'sales_notes' => $this->getSalesNotes(),
699
            'manufacturer_warranty' => $this->isManufacturerWarranty(),
700
            'country_of_origin' => $this->getCountryOfOrigin(),
701
            'downloadable' => $this->isDownloadable(),
702
            'adult' => $this->isAdult(),
703
            'cpa' => $this->getCpa(),
704
            'barcode' => $this->getBarcodes(),
705
        ];
706
    }
707
}
708