43 lines
1.1 KiB
PHP
43 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Dto;
|
|
|
|
use Domain\Models\Entities\Basket;
|
|
use Money\Money;
|
|
use Webmozart\Assert\Assert;
|
|
|
|
final readonly class BasketDto
|
|
{
|
|
/**
|
|
* @param list<\App\Dto\BasketProductDto> $items
|
|
*/
|
|
public function __construct(
|
|
public array $items,
|
|
public Money $totalTaxIncluded,
|
|
public Money $totalVat,
|
|
public Money $totalRaw,
|
|
public Money $totalDiscount,
|
|
public int $totalWeight,
|
|
public int $countItems,
|
|
) {
|
|
Assert::allIsInstanceOf($items, BasketProductDto::class);
|
|
}
|
|
|
|
/**
|
|
* @param list<\App\Dto\BasketProductDto> $items
|
|
*/
|
|
public static function fromEntity(Basket $basket, array $items): self
|
|
{
|
|
return new self(
|
|
items: $items,
|
|
totalTaxIncluded: $basket->totalTaxIncluded(),
|
|
totalVat: $basket->totalVat(),
|
|
totalRaw: $basket->totalRaw(),
|
|
totalDiscount: $basket->totalDiscount(),
|
|
totalWeight: $basket->totalWeight(),
|
|
countItems: $basket->countItems(),
|
|
);
|
|
}
|
|
}
|