1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Waredesk\Mappers\Product; |
4
|
|
|
|
5
|
|
|
use DateTime; |
6
|
|
|
use Waredesk\Collections\Products\Variants\Codes; |
7
|
|
|
use Waredesk\Collections\Products\Variants\Options; |
8
|
|
|
use Waredesk\Collections\Products\Variants\Prices; |
9
|
|
|
use Waredesk\Mappers\Product\Variant\CodesMapper; |
10
|
|
|
use Waredesk\Mappers\Product\Variant\OptionsMapper; |
11
|
|
|
use Waredesk\Mappers\Product\Variant\PricesMapper; |
12
|
|
|
use Waredesk\Models\Product\Variant; |
13
|
|
|
|
14
|
|
|
class VariantMapper |
15
|
|
|
{ |
16
|
|
|
public function map(Variant $variant, $data): Variant |
17
|
|
|
{ |
18
|
|
|
foreach ($data as $key => $value) { |
19
|
|
|
switch ($key) { |
20
|
|
|
case 'id': |
21
|
|
|
$variant->setId((int)$value); |
22
|
|
|
break; |
23
|
|
|
case 'images': |
24
|
|
|
$variant->setImages($value); |
25
|
|
|
break; |
26
|
|
|
case 'options': |
27
|
|
|
$variant->setOptions((new OptionsMapper())->map(new Options(), $value)); |
28
|
|
|
break; |
29
|
|
|
case 'codes': |
30
|
|
|
$variant->setCodes((new CodesMapper())->map(new Codes(), $value)); |
31
|
|
|
break; |
32
|
|
|
case 'prices': |
33
|
|
|
$variant->setPrices((new PricesMapper())->map(new Prices(), $value)); |
34
|
|
|
break; |
35
|
|
|
case 'description': |
36
|
|
|
$variant->setDescription($value); |
37
|
|
|
break; |
38
|
|
|
case 'notes': |
39
|
|
|
$variant->setNotes($value); |
40
|
|
|
break; |
41
|
|
|
case 'weight_unit': |
42
|
|
|
$variant->setWeightUnit($value); |
43
|
|
|
break; |
44
|
|
|
case 'length_unit': |
45
|
|
|
$variant->setLengthUnit($value); |
46
|
|
|
break; |
47
|
|
|
case 'weight': |
48
|
|
|
$variant->setWeight((float)$value); |
49
|
|
|
break; |
50
|
|
|
case 'height': |
51
|
|
|
$variant->setHeight((float)$value); |
52
|
|
|
break; |
53
|
|
|
case 'depth': |
54
|
|
|
$variant->setDepth((float)$value); |
55
|
|
|
break; |
56
|
|
|
case 'width': |
57
|
|
|
$variant->setWidth((float)$value); |
58
|
|
|
break; |
59
|
|
|
case 'creation_datetime': |
60
|
|
|
$variant->setCreationDatetime(new DateTime($value)); |
61
|
|
|
break; |
62
|
|
|
case 'modification_datetime': |
63
|
|
|
$variant->setModificationDatetime(new DateTime($value)); |
64
|
|
|
break; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
return $variant; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|