Skip to content

Commit d9fccc2

Browse files
authored
Merge pull request #54 from freerkminnema/master
Add Media mapping to Promotion object
2 parents c79ea41 + 7397fc4 commit d9fccc2

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

src/Mappers/Vouchers/PromotionMapper.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Piggy\Api\Mappers\Vouchers;
44

5+
use Piggy\Api\Mappers\Loyalty\MediaMapper;
56
use Piggy\Api\Models\Vouchers\Promotion;
67
use stdClass;
78

@@ -13,6 +14,10 @@ public function map(stdClass $data): Promotion
1314
$attributes = get_object_vars($data->attributes);
1415
}
1516

17+
if (isset($data->media)) {
18+
$media = (new MediaMapper)->map($data->media);
19+
}
20+
1621
return new Promotion(
1722
$data->uuid,
1823
$data->name,
@@ -22,7 +27,8 @@ public function map(stdClass $data): Promotion
2227
$data->expiration_duration ?? null,
2328
$attributes ?? [],
2429
$data->type,
25-
$data->redemptions_per_voucher
30+
$data->redemptions_per_voucher,
31+
$media ?? null
2632
);
2733
}
2834
}

src/Models/Vouchers/Promotion.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Piggy\Api\ApiClient;
77
use Piggy\Api\Exceptions\MaintenanceModeException;
88
use Piggy\Api\Exceptions\PiggyRequestException;
9+
use Piggy\Api\Models\Loyalty\Media;
910
use Piggy\Api\StaticMappers\Vouchers\PromotionMapper;
1011
use Piggy\Api\StaticMappers\Vouchers\PromotionsMapper;
1112

@@ -56,6 +57,11 @@ class Promotion
5657
*/
5758
protected $attributes;
5859

60+
/**
61+
* @var Media|null
62+
*/
63+
protected $media;
64+
5965
/**
6066
* @var string
6167
*/
@@ -73,7 +79,8 @@ public function __construct(
7379
?int $expiration_duration = null,
7480
array $attributes = [],
7581
?string $type = null,
76-
?int $redemptions_per_voucher = null
82+
?int $redemptions_per_voucher = null,
83+
?Media $media = null
7784
) {
7885
$this->uuid = $uuid;
7986
$this->name = $name;
@@ -84,6 +91,7 @@ public function __construct(
8491
$this->attributes = $attributes;
8592
$this->type = $type;
8693
$this->redemptions_per_voucher = $redemptions_per_voucher;
94+
$this->media = $media;
8795
}
8896

8997
public function getName(): string
@@ -134,6 +142,11 @@ public function getAttributes(): array
134142
return $this->attributes;
135143
}
136144

145+
public function getMedia(): ?Media
146+
{
147+
return $this->media;
148+
}
149+
137150
/**
138151
* @param mixed[] $body
139152
*

src/StaticMappers/Vouchers/PromotionMapper.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Piggy\Api\StaticMappers\Vouchers;
44

5+
use Piggy\Api\Mappers\Loyalty\MediaMapper;
56
use Piggy\Api\Models\Vouchers\Promotion;
67

78
class PromotionMapper
@@ -14,6 +15,10 @@ public static function map($data): Promotion
1415
$attributes = get_object_vars($data->attributes);
1516
}
1617

18+
if (isset($data->media)) {
19+
$media = (new MediaMapper)->map($data->media);
20+
}
21+
1722
return new Promotion(
1823
$data->uuid,
1924
$data->name,
@@ -23,7 +28,8 @@ public static function map($data): Promotion
2328
$data->expiration_duration ?? null,
2429
isset($data->attributes) ? $attributes : [],
2530
$data->type,
26-
$data->redemptions_per_voucher
31+
$data->redemptions_per_voucher,
32+
$media ?? null
2733
);
2834
}
2935
}

0 commit comments

Comments
 (0)