AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

12345678910111213141516171819202122232425262728
  1. <?php
  2. namespace App\Commerce;
  3. use App\Models\AutomaticDiscount;
  4. use App\Models\DiscountCode;
  5. /**
  6. * The one discount a cart gets: the shopper's code, or an automatic discount, whichever saves more.
  7. * Amounts are in sen.
  8. */
  9. final readonly class CartDiscount
  10. {
  11. public function __construct(
  12. /** What comes off the products. */
  13. public int $amount,
  14. public ?DiscountCode $code = null,
  15. public ?AutomaticDiscount $offer = null,
  16. ) {}
  17. /**
  18. * "RAYA10" for a code, "Raya Sale" for an automatic discount.
  19. */
  20. public function name(): string
  21. {
  22. return $this->code !== null ? $this->code->code : (string) $this->offer?->name;
  23. }
  24. }