Completed
Push — master ( fa6ed6...819041 )
by Bukashk0zzz
01:28
created

AbstractOffer::getPurchasePrice()   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
use Bukashk0zzz\YmlGenerator\Model\Delivery;
15
16
/**
17
 * Abstract Class Offer
18
 */
19
abstract class AbstractOffer implements OfferInterface
20
{
21
    /**
22
     * @var string
23
     */
24
    private $id;
25
26
    /**
27
     * @var bool
28
     */
29
    private $available;
30
31
    /**
32
     * @var string
33
     */
34
    private $url;
35
36
    /**
37
     * @var float
38
     */
39
    private $price;
40
41
    /**
42
     * @var float
43
     */
44
    private $oldPrice;
45
46
    /**
47
     * @var float
48
     */
49
    private $purchasePrice;
50
51
    /**
52
     * @var string
53
     */
54
    private $currencyId;
55
56
    /**
57
     * @var int
58
     */
59
    private $categoryId;
60
61
    /**
62
     * @var array
63
     */
64
    private $categoriesId = [];
65
66
    /**
67
     * @var string
68
     */
69
    private $name;
70
71
    /**
72
     * @var string
73
     */
74
    private $marketCategory;
75
76
    /**
77
     * @var bool
78
     */
79
    private $adult;
80
81
    /**
82
     * @var string
83
     */
84
    private $salesNotes;
85
86
    /**
87
     * @var bool
88
     */
89
    private $manufacturerWarranty;
90
91
    /**
92
     * @var bool
93
     */
94
    private $pickup;
95
96
    /**
97
     * @var bool
98
     */
99
    private $downloadable;
100
101
    /**
102
     * @var bool
103
     */
104
    private $delivery;
105
106
    /**
107
     * @var float
108
     */
109
    private $localDeliveryCost;
110
111
    /**
112
     * @var array
113
     */
114
    private $deliveryOptions = [];
115
116
    /**
117
     * @var string
118
     */
119
    private $description;
120
121
    /**
122
     * @var string
123
     */
124
    private $countryOfOrigin;
125
126
    /**
127
     * @var string
128
     */
129
    private $weight;
130
131
    /**
132
     * @var int
133
     */
134
    private $cpa;
135
136
    /**
137
     * @var string[]
138
     */
139
    private $barcodes;
140
141
    /**
142
     * @var array
143
     */
144
    private $pictures = [];
145
146
    /**
147
     * @var array
148
     */
149
    private $params = [];
150
151
    /**
152
     * @var bool
153
     */
154
    private $store;
155
156
    /**
157
     * @var bool
158
     */
159
    private $autoDiscount;
160
161
    /**
162
     * Array of custom elements (element types are keys) of arrays of element values
163
     * There may be multiple elements of the same type
164
     *
165
     * @var array[]
166
     */
167
    private $customElements;
168
169
    /**
170
     * @var OfferCondition
171
     */
172
    private $condition;
173
174
    /**
175
     * @return array
176
     */
177
    public function toArray()
178
    {
179
        return \array_merge($this->getHeaderOptions(), $this->getOptions(), $this->getFooterOptions());
180
    }
181
182
    /**
183
     * @return string
184
     */
185
    public function getId()
186
    {
187
        return $this->id;
188
    }
189
190
    /**
191
     * @param string $id
192
     *
193
     * @return $this
194
     */
195
    public function setId($id)
196
    {
197
        $this->id = $id;
198
199
        return $this;
200
    }
201
202
    /**
203
     * @return bool
204
     */
205
    public function isAvailable()
206
    {
207
        return $this->available;
208
    }
209
210
    /**
211
     * @param bool $available
212
     *
213
     * @return $this
214
     */
215
    public function setAvailable($available)
216
    {
217
        $this->available = $available;
218
219
        return $this;
220
    }
221
222
    /**
223
     * @return string
224
     */
225
    public function getUrl()
226
    {
227
        return $this->url;
228
    }
229
230
    /**
231
     * @param string $url
232
     *
233
     * @return $this
234
     */
235
    public function setUrl($url)
236
    {
237
        $this->url = $url;
238
239
        return $this;
240
    }
241
242
    /**
243
     * @return float
244
     */
245
    public function getPrice()
246
    {
247
        return $this->price;
248
    }
249
250
    /**
251
     * @param float $price
252
     *
253
     * @return $this
254
     */
255
    public function setPrice($price)
256
    {
257
        $this->price = $price;
258
259
        return $this;
260
    }
261
262
    /**
263
     * @return float
264
     */
265
    public function getOldPrice()
266
    {
267
        return $this->oldPrice;
268
    }
269
270
    /**
271
     * @param float $oldPrice
272
     *
273
     * @return $this
274
     */
275
    public function setOldPrice($oldPrice)
276
    {
277
        $this->oldPrice = $oldPrice;
278
279
        return $this;
280
    }
281
282
    /**
283
     * @return float
284
     */
285
    public function getPurchasePrice()
286
    {
287
        return $this->purchasePrice;
288
    }
289
290
    /**
291
     * @param float $purchasePrice
292
     *
293
     * @return $this
294
     */
295
    public function setPurchasePrice($purchasePrice)
296
    {
297
        $this->purchasePrice = $purchasePrice;
298
299
        return $this;
300
    }
301
302
    /**
303
     * @return string
304
     */
305
    public function getCurrencyId()
306
    {
307
        return $this->currencyId;
308
    }
309
310
    /**
311
     * @param string $currencyId
312
     *
313
     * @return $this
314
     */
315
    public function setCurrencyId($currencyId)
316
    {
317
        $this->currencyId = $currencyId;
318
319
        return $this;
320
    }
321
322
    /**
323
     * @return int
324
     */
325
    public function getCategoryId()
326
    {
327
        return $this->categoryId;
328
    }
329
330
    /**
331
     * @param int $categoryId
332
     *
333
     * @return $this
334
     */
335
    public function setCategoryId($categoryId)
336
    {
337
        $this->categoryId = $categoryId;
338
339
        return $this;
340
    }
341
342
    /**
343
     * @return array
344
     */
345
    public function getCategoriesId()
346
    {
347
        return $this->categoriesId;
348
    }
349
350
    /**
351
     * @param array $categoriesId
352
     *
353
     * @return $this
354
     */
355
    public function setCategoriesId(array $categoriesId)
356
    {
357
        $this->categoriesId = $categoriesId;
358
359
        return $this;
360
    }
361
362
    /**
363
     * @return string
364
     */
365
    public function getName()
366
    {
367
        return $this->name;
368
    }
369
370
    /**
371
     * @param string $name
372
     *
373
     * @return $this
374
     */
375
    public function setName($name)
376
    {
377
        $this->name = $name;
378
379
        return $this;
380
    }
381
382
    /**
383
     * @return string
384
     */
385
    public function getMarketCategory()
386
    {
387
        return $this->marketCategory;
388
    }
389
390
    /**
391
     * @param string $marketCategory
392
     *
393
     * @return $this
394
     */
395
    public function setMarketCategory($marketCategory)
396
    {
397
        $this->marketCategory = $marketCategory;
398
399
        return $this;
400
    }
401
402
    /**
403
     * @return bool
404
     */
405
    public function isAdult()
406
    {
407
        return $this->adult;
408
    }
409
410
    /**
411
     * @param bool $adult
412
     *
413
     * @return $this
414
     */
415
    public function setAdult($adult)
416
    {
417
        $this->adult = $adult;
418
419
        return $this;
420
    }
421
422
    /**
423
     * @return string
424
     */
425
    public function getSalesNotes()
426
    {
427
        return $this->salesNotes;
428
    }
429
430
    /**
431
     * @param string $salesNotes
432
     *
433
     * @return $this
434
     */
435
    public function setSalesNotes($salesNotes)
436
    {
437
        $this->salesNotes = $salesNotes;
438
439
        return $this;
440
    }
441
442
    /**
443
     * @return bool
444
     */
445
    public function isManufacturerWarranty()
446
    {
447
        return $this->manufacturerWarranty;
448
    }
449
450
    /**
451
     * @param bool $manufacturerWarranty
452
     *
453
     * @return $this
454
     */
455
    public function setManufacturerWarranty($manufacturerWarranty)
456
    {
457
        $this->manufacturerWarranty = $manufacturerWarranty;
458
459
        return $this;
460
    }
461
462
    /**
463
     * @return bool
464
     */
465
    public function isPickup()
466
    {
467
        return $this->pickup;
468
    }
469
470
    /**
471
     * @param bool $pickup
472
     *
473
     * @return $this
474
     */
475
    public function setPickup($pickup)
476
    {
477
        $this->pickup = $pickup;
478
479
        return $this;
480
    }
481
482
    /**
483
     * @return bool
484
     */
485
    public function isDownloadable()
486
    {
487
        return $this->downloadable;
488
    }
489
490
    /**
491
     * @param bool $downloadable
492
     *
493
     * @return $this
494
     */
495
    public function setDownloadable($downloadable)
496
    {
497
        $this->downloadable = $downloadable;
498
499
        return $this;
500
    }
501
502
    /**
503
     * @return bool
504
     */
505
    public function isDelivery()
506
    {
507
        return $this->delivery;
508
    }
509
510
    /**
511
     * @param bool $delivery
512
     *
513
     * @return $this
514
     */
515
    public function setDelivery($delivery)
516
    {
517
        $this->delivery = $delivery;
518
519
        return $this;
520
    }
521
522
    /**
523
     * @return array
524
     */
525
    public function getDeliveryOptions()
526
    {
527
        return $this->deliveryOptions;
528
    }
529
530
    /**
531
     * @param Delivery $option
532
     *
533
     * @return $this
534
     */
535
    public function addDeliveryOption(Delivery $option)
536
    {
537
        $this->deliveryOptions[] = $option;
538
539
        return $this;
540
    }
541
542
    /**
543
     * @param bool $store
544
     *
545
     * @return $this
546
     */
547
    public function setStore($store)
548
    {
549
        $this->store = $store;
550
551
        return $this;
552
    }
553
554
    /**
555
     * @return bool
556
     */
557
    public function isStore()
558
    {
559
        return $this->store;
560
    }
561
562
    /**
563
     * @return float
564
     */
565
    public function getLocalDeliveryCost()
566
    {
567
        return $this->localDeliveryCost;
568
    }
569
570
    /**
571
     * @param float $localDeliveryCost
572
     *
573
     * @return $this
574
     */
575
    public function setLocalDeliveryCost($localDeliveryCost)
576
    {
577
        $this->localDeliveryCost = $localDeliveryCost;
578
579
        return $this;
580
    }
581
582
    /**
583
     * @return string
584
     */
585
    public function getDescription()
586
    {
587
        return $this->description;
588
    }
589
590
    /**
591
     * @param string $description
592
     *
593
     * @return $this
594
     */
595
    public function setDescription($description)
596
    {
597
        $this->description = $description;
598
599
        return $this;
600
    }
601
602
    /**
603
     * @return string
604
     */
605
    public function getCountryOfOrigin()
606
    {
607
        return $this->countryOfOrigin;
608
    }
609
610
    /**
611
     * @param string $countryOfOrigin
612
     *
613
     * @return $this
614
     */
615
    public function setCountryOfOrigin($countryOfOrigin)
616
    {
617
        $this->countryOfOrigin = $countryOfOrigin;
618
619
        return $this;
620
    }
621
622
    /**
623
     * @return string
624
     */
625
    public function getWeight()
626
    {
627
        return $this->weight;
628
    }
629
630
    /**
631
     * @param string $weight
632
     *
633
     * @return $this
634
     */
635
    public function setWeight($weight)
636
    {
637
        $this->weight = $weight;
638
639
        return $this;
640
    }
641
642
    /**
643
     * @return int
644
     */
645
    public function getCpa()
646
    {
647
        return $this->cpa;
648
    }
649
650
    /**
651
     * @param int $cpa
652
     *
653
     * @return $this
654
     */
655
    public function setCpa($cpa)
656
    {
657
        $this->cpa = $cpa;
658
659
        return $this;
660
    }
661
662
    /**
663
     * @return array
664
     */
665
    public function getParams()
666
    {
667
        return $this->params;
668
    }
669
670
    /**
671
     * @param OfferParam $param
672
     *
673
     * @return $this
674
     */
675
    public function addParam(OfferParam $param)
676
    {
677
        $this->params[] = $param;
678
679
        return $this;
680
    }
681
682
    /**
683
     * Add picture
684
     *
685
     * @param string $url
686
     *
687
     * @return $this
688
     */
689
    public function addPicture($url)
690
    {
691
        if (\count($this->pictures) < 10) {
692
            $this->pictures[] = $url;
693
        }
694
695
        return $this;
696
    }
697
698
    /**
699
     * Set pictures
700
     *
701
     * @param array $pictures
702
     *
703
     * @return $this
704
     */
705
    public function setPictures(array $pictures)
706
    {
707
        $this->pictures = $pictures;
708
709
        return $this;
710
    }
711
712
    /**
713
     * Get picture list
714
     *
715
     * @return array
716
     */
717
    public function getPictures()
718
    {
719
        return $this->pictures;
720
    }
721
722
    /**
723
     * Get list of barcodes of the offer
724
     *
725
     * @return string[]
726
     */
727
    public function getBarcodes()
728
    {
729
        return $this->barcodes;
730
    }
731
732
    /**
733
     * Set list of barcodes for that offer
734
     *
735
     * @param string[] $barcodes
736
     *
737
     * @return $this
738
     */
739
    public function setBarcodes(array $barcodes = [])
740
    {
741
        $this->barcodes = $barcodes;
742
743
        return $this;
744
    }
745
746
    /**
747
     * Add one barcode to the collection of barcodes of this offer
748
     *
749
     * @param string $barcode
750
     *
751
     * @return $this
752
     */
753
    public function addBarcode($barcode)
754
    {
755
        $this->barcodes[] = $barcode;
756
757
        return $this;
758
    }
759
760
    /**
761
     * Sets list of custom elements
762
     *
763
     * @param array $customElements Array (keys are element types) of arrays (element values)
764
     *
765
     * @return $this
766
     */
767
    public function setCustomElements(array $customElements = [])
768
    {
769
        $this->customElements = $customElements;
770
771
        return $this;
772
    }
773
774
    /**
775
     * Add a custom element with given type and value
776
     * Multiple elements of the same type are supported
777
     *
778
     * @param string $elementType
779
     * @param mixed  $value
780
     *
781
     * @return $this
782
     */
783
    public function addCustomElement($elementType, $value)
784
    {
785
        if ($value !== null) {
786
            // Add value to the list of values of the given element type creating array when needed
787
            $this->customElements[$elementType][] = $value;
788
        }
789
790
        return $this;
791
    }
792
793
    /**
794
     * Returns a list of custom elements
795
     * Always returns an array even if no custom elements were added
796
     *
797
     * @return array
798
     */
799
    public function getCustomElements()
800
    {
801
        return $this->customElements ?: [];
802
    }
803
804
    /**
805
     * Returns a list of values for the specified custom element type
806
     * Always returns an array
807
     *
808
     * @param string $elementType
809
     *
810
     * @return array
811
     */
812
    public function getCustomElementByType($elementType)
813
    {
814
        // TODO: Use ?? operator when support for PHP 5.6 is no longer needed
815
        if (isset($this->customElements[$elementType])) {
816
            return $this->customElements[$elementType];
817
        }
818
819
        return [];
820
    }
821
822
    /**
823
     * @return OfferCondition
824
     */
825
    public function getCondition()
826
    {
827
        return $this->condition;
828
    }
829
830
    /**
831
     * @param OfferCondition $condition
832
     *
833
     * @return $this
834
     */
835
    public function addCondition(OfferCondition $condition)
836
    {
837
        $this->condition = $condition;
838
839
        return $this;
840
    }
841
842
    /**
843
     * @return bool
844
     */
845
    public function getAutoDiscount()
846
    {
847
        return $this->autoDiscount;
848
    }
849
850
    /**
851
     * @param bool $autoDiscount
852
     *
853
     * @return $this
854
     */
855
    public function setAutoDiscount($autoDiscount)
856
    {
857
        $this->autoDiscount = $autoDiscount;
858
859
        return $this;
860
    }
861
862
    /**
863
     * @return array
864
     */
865
    abstract protected function getOptions();
866
867
    /**
868
     * @return array
869
     */
870
    private function getHeaderOptions()
871
    {
872
        return [
873
                'url' => $this->getUrl(),
874
                'price' => $this->getPrice(),
875
                'oldprice' => $this->getOldPrice(),
876
                'purchase_price' => $this->getPurchasePrice(),
877
                'currencyId' => $this->getCurrencyId(),
878
                'categoryId' => \array_merge(
879
                    [$this->getCategoryId()],
880
                    $this->getCategoriesId()
881
                ),
882
                'market_category' => $this->getMarketCategory(),
883
                'picture' => $this->getPictures(),
884
                'pickup' => $this->isPickup(),
885
                'store' => $this->isStore(),
886
                'delivery' => $this->isDelivery(),
887
                'local_delivery_cost' => $this->getLocalDeliveryCost(),
888
                'weight' => $this->getWeight(),
889
                'name' => $this->getName(),
890
                'enable_auto_discounts' => $this->getAutoDiscount(),
891
            ] + $this->getCustomElements();
892
    }
893
894
    /**
895
     * @return array
896
     */
897
    private function getFooterOptions()
898
    {
899
        return [
900
            'description' => $this->getDescription(),
901
            'sales_notes' => $this->getSalesNotes(),
902
            'manufacturer_warranty' => $this->isManufacturerWarranty(),
903
            'country_of_origin' => $this->getCountryOfOrigin(),
904
            'downloadable' => $this->isDownloadable(),
905
            'adult' => $this->isAdult(),
906
            'cpa' => $this->getCpa(),
907
            'barcode' => $this->getBarcodes(),
908
        ];
909
    }
910
}
911