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

CartDiscount.php 691B

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. }