Completed
Push — master ( 98c454...6ae4bd )
by Bukashk0zzz
01:34
created

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