Completed
Pull Request — master (#19)
by
unknown
01:51
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
    /**
422
     * @param bool $store
423
     *
424
     * @return $this
425
     */
426
    public function setStore($store)
427
    {
428
        $this->store = $store;
429
430
        return $this;
431
    }
432
433
    /**
434
     * @return bool
435
     */
436
    public function isStore()
437
    {
438
        return $this->store;
439
    }
440
441
    /**
442
     * @return float
443
     */
444
    public function getLocalDeliveryCost()
445
    {
446
        return $this->localDeliveryCost;
447
    }
448
449
    /**
450
     * @param float $localDeliveryCost
451
     *
452
     * @return $this
453
     */
454
    public function setLocalDeliveryCost($localDeliveryCost)
455
    {
456
        $this->localDeliveryCost = $localDeliveryCost;
457
458
        return $this;
459
    }
460
461
    /**
462
     * @return string
463
     */
464
    public function getDescription()
465
    {
466
        return $this->description;
467
    }
468
469
    /**
470
     * @param string $description
471
     *
472
     * @return $this
473
     */
474
    public function setDescription($description)
475
    {
476
        $this->description = $description;
477
478
        return $this;
479
    }
480
481
    /**
482
     * @return string
483
     */
484
    public function getCountryOfOrigin()
485
    {
486
        return $this->countryOfOrigin;
487
    }
488
489
    /**
490
     * @param string $countryOfOrigin
491
     *
492
     * @return $this
493
     */
494
    public function setCountryOfOrigin($countryOfOrigin)
495
    {
496
        $this->countryOfOrigin = $countryOfOrigin;
497
498
        return $this;
499
    }
500
501
    /**
502
     * @return int
503
     */
504
    public function getCpa()
505
    {
506
        return $this->cpa;
507
    }
508
509
    /**
510
     * @param int $cpa
511
     *
512
     * @return $this
513
     */
514
    public function setCpa($cpa)
515
    {
516
        $this->cpa = $cpa;
517
518
        return $this;
519
    }
520
521
    /**
522
     * @return array
523
     */
524
    public function getParams()
525
    {
526
        return $this->params;
527
    }
528
529
    /**
530
     * @param OfferParam $param
531
     *
532
     * @return $this
533
     */
534
    public function addParam(OfferParam $param)
535
    {
536
        $this->params[] = $param;
537
538
        return $this;
539
    }
540
541
    /**
542
     * Add picture
543
     *
544
     * @param string $url
545
     *
546
     * @return $this
547
     */
548
    public function addPicture($url)
549
    {
550
        if (\count($this->pictures) < 10) {
551
            $this->pictures[] = $url;
552
        }
553
554
        return $this;
555
    }
556
557
    /**
558
     * Set pictures
559
     *
560
     * @param array $pictures
561
     *
562
     * @return $this
563
     */
564
    public function setPictures(array $pictures)
565
    {
566
        $this->pictures = $pictures;
567
568
        return $this;
569
    }
570
571
    /**
572
     * Get picture list
573
     *
574
     * @return array
575
     */
576
    public function getPictures()
577
    {
578
        return $this->pictures;
579
    }
580
581
    /**
582
     * Get list of barcodes of the offer
583
     *
584
     * @return string[]
585
     */
586
    public function getBarcodes()
587
    {
588
        return $this->barcodes;
589
    }
590
591
    /**
592
     * Set list of barcodes for that offer
593
     *
594
     * @param string[] $barcodes
595
     *
596
     * @return $this
597
     */
598
    public function setBarcodes(array $barcodes = [])
599
    {
600
        $this->barcodes = $barcodes;
601
602
        return $this;
603
    }
604
605
    /**
606
     * Add one barcode to the collection of barcodes of this offer
607
     *
608
     * @param string $barcode
609
     *
610
     * @return AbstractOffer
611
     */
612
    public function addBarcode($barcode)
613
    {
614
        $this->barcodes[] = $barcode;
615
616
        return $this;
617
    }
618
619
    /**
620
     * @return string
621
     */
622
    public function getWeight()
623
    {
624
        return $this->weight;
625
    }
626
627
    /**
628
     * @param string $weight
629
     *
630
     * @return AbstractOffer
631
     */
632
    public function setWeight($weight)
633
    {
634
        $this->weight = $weight;
635
636
        return $this;
637
    }
638
639
    /**
640
     * @return array
641
     */
642
    abstract protected function getOptions();
643
644
    /**
645
     * @return array
646
     */
647
    private function getHeaderOptions()
648
    {
649
        return [
650
            'url' => $this->getUrl(),
651
            'price' => $this->getPrice(),
652
            'oldprice' => $this->getOldPrice(),
653
            'currencyId' => $this->getCurrencyId(),
654
            'categoryId' => $this->getCategoryId(),
655
            'market_category' => $this->getMarketCategory(),
656
            'picture' => $this->getPictures(),
657
            'pickup' => $this->isPickup(),
658
            'store' => $this->isStore(),
659
            'delivery' => $this->isDelivery(),
660
            'weight' => $this->getWeight(),
661
            'local_delivery_cost' => $this->getLocalDeliveryCost(),
662
        ];
663
    }
664
665
    /**
666
     * @return array
667
     */
668
    private function getFooterOptions()
669
    {
670
        return [
671
            'description' => $this->getDescription(),
672
            'sales_notes' => $this->getSalesNotes(),
673
            'manufacturer_warranty' => $this->isManufacturerWarranty(),
674
            'country_of_origin' => $this->getCountryOfOrigin(),
675
            'downloadable' => $this->isDownloadable(),
676
            'adult' => $this->isAdult(),
677
            'cpa' => $this->getCpa(),
678
            'barcode' => $this->getBarcodes(),
679
        ];
680
    }
681
}
682