diff --git a/src/Mappers/Vouchers/PromotionMapper.php b/src/Mappers/Vouchers/PromotionMapper.php index 83f3f9b3..4e18d312 100644 --- a/src/Mappers/Vouchers/PromotionMapper.php +++ b/src/Mappers/Vouchers/PromotionMapper.php @@ -2,6 +2,7 @@ namespace Piggy\Api\Mappers\Vouchers; +use Piggy\Api\Mappers\Loyalty\MediaMapper; use Piggy\Api\Models\Vouchers\Promotion; use stdClass; @@ -13,6 +14,10 @@ public function map(stdClass $data): Promotion $attributes = get_object_vars($data->attributes); } + if (isset($data->media)) { + $media = (new MediaMapper)->map($data->media); + } + return new Promotion( $data->uuid, $data->name, @@ -22,7 +27,8 @@ public function map(stdClass $data): Promotion $data->expiration_duration ?? null, $attributes ?? [], $data->type, - $data->redemptions_per_voucher + $data->redemptions_per_voucher, + $media ?? null ); } } diff --git a/src/Models/Vouchers/Promotion.php b/src/Models/Vouchers/Promotion.php index dbe08236..a6be03f0 100644 --- a/src/Models/Vouchers/Promotion.php +++ b/src/Models/Vouchers/Promotion.php @@ -6,6 +6,7 @@ use Piggy\Api\ApiClient; use Piggy\Api\Exceptions\MaintenanceModeException; use Piggy\Api\Exceptions\PiggyRequestException; +use Piggy\Api\Models\Loyalty\Media; use Piggy\Api\StaticMappers\Vouchers\PromotionMapper; use Piggy\Api\StaticMappers\Vouchers\PromotionsMapper; @@ -56,6 +57,11 @@ class Promotion */ protected $attributes; + /** + * @var Media|null + */ + protected $media; + /** * @var string */ @@ -73,7 +79,8 @@ public function __construct( ?int $expiration_duration = null, array $attributes = [], ?string $type = null, - ?int $redemptions_per_voucher = null + ?int $redemptions_per_voucher = null, + ?Media $media = null ) { $this->uuid = $uuid; $this->name = $name; @@ -84,6 +91,7 @@ public function __construct( $this->attributes = $attributes; $this->type = $type; $this->redemptions_per_voucher = $redemptions_per_voucher; + $this->media = $media; } public function getName(): string @@ -134,6 +142,11 @@ public function getAttributes(): array return $this->attributes; } + public function getMedia(): ?Media + { + return $this->media; + } + /** * @param mixed[] $body * diff --git a/src/StaticMappers/Vouchers/PromotionMapper.php b/src/StaticMappers/Vouchers/PromotionMapper.php index 27de6750..b5cfc54d 100644 --- a/src/StaticMappers/Vouchers/PromotionMapper.php +++ b/src/StaticMappers/Vouchers/PromotionMapper.php @@ -2,6 +2,7 @@ namespace Piggy\Api\StaticMappers\Vouchers; +use Piggy\Api\Mappers\Loyalty\MediaMapper; use Piggy\Api\Models\Vouchers\Promotion; class PromotionMapper @@ -14,6 +15,10 @@ public static function map($data): Promotion $attributes = get_object_vars($data->attributes); } + if (isset($data->media)) { + $media = (new MediaMapper)->map($data->media); + } + return new Promotion( $data->uuid, $data->name, @@ -23,7 +28,8 @@ public static function map($data): Promotion $data->expiration_duration ?? null, isset($data->attributes) ? $attributes : [], $data->type, - $data->redemptions_per_voucher + $data->redemptions_per_voucher, + $media ?? null ); } }