|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Waredesk\Mappers\Product; |
|
4
|
|
|
|
|
5
|
|
|
use DateTime; |
|
6
|
|
|
use Waredesk\Collections\Products\Variants\Items\Attributes as ItemsAttributes; |
|
7
|
|
|
use Waredesk\Collections\Products\Variants\Attributes; |
|
8
|
|
|
use Waredesk\Collections\Products\Variants\Codes; |
|
9
|
|
|
use Waredesk\Collections\Products\Variants\Prices; |
|
10
|
|
|
use Waredesk\Mapper; |
|
11
|
|
|
use Waredesk\Mappers\Product\Variant\Item\AttributesMapper as ItemAttributesMapper; |
|
12
|
|
|
use Waredesk\Mappers\Product\Variant\AttributesMapper; |
|
13
|
|
|
use Waredesk\Mappers\Product\Variant\CodesMapper; |
|
14
|
|
|
use Waredesk\Mappers\Product\Variant\PricesMapper; |
|
15
|
|
|
use Waredesk\Models\Product\Variant; |
|
16
|
|
|
|
|
17
|
|
|
class VariantMapper extends Mapper |
|
18
|
|
|
{ |
|
19
|
6 |
|
public function map(Variant $variant, $data): Variant |
|
20
|
|
|
{ |
|
21
|
6 |
|
$finalData = []; |
|
22
|
6 |
|
foreach ($data as $key => $value) { |
|
23
|
|
|
switch ($key) { |
|
24
|
6 |
|
case 'attributes': |
|
25
|
6 |
|
$finalData['attributes'] = (new AttributesMapper())->map(new Attributes(), $value); |
|
26
|
6 |
|
break; |
|
27
|
6 |
|
case 'codes': |
|
28
|
6 |
|
$finalData['codes'] = (new CodesMapper())->map(new Codes(), $value); |
|
29
|
6 |
|
break; |
|
30
|
6 |
|
case 'prices': |
|
31
|
6 |
|
$finalData['prices'] = (new PricesMapper())->map(new Prices(), $value); |
|
32
|
6 |
|
break; |
|
33
|
6 |
|
case 'items_attributes': |
|
34
|
6 |
|
$finalData['items_attributes'] = (new ItemAttributesMapper())->map(new ItemsAttributes(), $value); |
|
35
|
6 |
|
break; |
|
36
|
6 |
|
case 'weight': |
|
37
|
6 |
|
$finalData['weight'] = null === $value ? null : (float)$value; |
|
38
|
6 |
|
break; |
|
39
|
6 |
|
case 'height': |
|
40
|
6 |
|
$finalData['height'] = null === $value ? null : (float)$value; |
|
41
|
6 |
|
break; |
|
42
|
6 |
|
case 'depth': |
|
43
|
6 |
|
$finalData['depth'] = null === $value ? null : (float)$value; |
|
44
|
6 |
|
break; |
|
45
|
6 |
|
case 'width': |
|
46
|
6 |
|
$finalData['width'] = null === $value ? null : (float)$value; |
|
47
|
6 |
|
break; |
|
48
|
6 |
|
case 'creation': |
|
49
|
6 |
|
$finalData['creation'] = new DateTime($value); |
|
50
|
6 |
|
break; |
|
51
|
6 |
|
case 'modification': |
|
52
|
6 |
|
$finalData['modification'] = new DateTime($value); |
|
53
|
6 |
|
break; |
|
54
|
|
|
default: |
|
55
|
6 |
|
$finalData[$key] = $value; |
|
56
|
6 |
|
break; |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
6 |
|
$variant->reset($finalData); |
|
60
|
6 |
|
return $variant; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|