Skip to content

Commit

Permalink
Parse array trackings on mapping from entity checkout
Browse files Browse the repository at this point in the history
  • Loading branch information
subiabre committed Dec 9, 2024
1 parent fe21280 commit 3f370c7
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/ApiResource/Gateway/CheckoutApiResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use App\Gateway\Tracking;
use App\State\ApiResourceStateProvider;
use App\State\Gateway\CheckoutStateProcessor;
use AutoMapper\Attribute\MapFrom;
use Symfony\Component\Validator\Constraints as Assert;

/**
Expand Down Expand Up @@ -72,5 +73,17 @@ class CheckoutApiResource
* @var Tracking[]
*/
#[API\ApiProperty(writable: false)]
#[MapFrom(transformer: [self::class, 'parseTrackings'])]
public array $trackings = [];

public static function parseTrackings(array $values)
{
return \array_map(function ($value) {
$tracking = new Tracking();
$tracking->title = $value['title'];
$tracking->value = $value['value'];

return $tracking;
}, $values);
}
}

0 comments on commit 3f370c7

Please sign in to comment.