| 12345678910111213141516171819202122232425262728 |
- <?php
-
- namespace App\Commerce;
-
- use App\Models\AutomaticDiscount;
- use App\Models\DiscountCode;
-
- /**
- * The one discount a cart gets: the shopper's code, or an automatic discount, whichever saves more.
- * Amounts are in sen.
- */
- final readonly class CartDiscount
- {
- public function __construct(
- /** What comes off the products. */
- public int $amount,
- public ?DiscountCode $code = null,
- public ?AutomaticDiscount $offer = null,
- ) {}
-
- /**
- * "RAYA10" for a code, "Raya Sale" for an automatic discount.
- */
- public function name(): string
- {
- return $this->code !== null ? $this->code->code : (string) $this->offer?->name;
- }
- }
|