src/Entity/CartItemDiscount.php line 9

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CartItemDiscountRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. #[ORM\Entity(repositoryClass: CartItemDiscountRepository::class)]
  6. class CartItemDiscount extends CartItem
  7. {
  8.     #[ORM\OneToOne(inversedBy: 'cartItemDiscount', targetEntity: Discount::class, cascade: ['persist', 'remove'])]
  9.     private $discount;
  10.     public function setPrice(?float $price): CartItem
  11.     {
  12.         if ($price > 0) {
  13.             $price *= -1;
  14.         }
  15.         parent::setPrice($price);
  16.         return $this;
  17.     }
  18.     public function getDiscount(): ?Discount
  19.     {
  20.         return $this->discount;
  21.     }
  22.     public function setDiscount(?Discount $discount): self
  23.     {
  24.         $this->discount = $discount;
  25.         return $this;
  26.     }
  27. }