Completed
Push — master ( 62bf70...faca3e )
by Bukashk0zzz
01:54
created

AbstractOffer::isStore()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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