src/Entity/CartElement.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Service\Helper\DateTimeHelper;
  4. use DateTime;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Exception;
  7. /**
  8.  * Class CartElement
  9.  *
  10.  * @ORM\Table(name="carts__elements")
  11.  * @ORM\Entity(repositoryClass="App\Repository\CartElementRepository")
  12.  */
  13. class CartElement
  14. {
  15.     use IdTrait;
  16.     /**
  17.      * @ORM\Column(name="created_at", type="datetime", nullable=false)
  18.      */
  19.     private DateTime $createdAt;
  20.     /**
  21.      * @ORM\ManyToOne(targetEntity="App\Entity\Cart", cascade={"persist"})
  22.      * @ORM\JoinColumn(name="cart_id", referencedColumnName="id", onDelete="CASCADE")
  23.      */
  24.     private Cart $cart;
  25.     /**
  26.      * @ORM\ManyToOne(targetEntity="App\Entity\Item")
  27.      * @ORM\JoinColumn(name="item_id", referencedColumnName="id", onDelete="CASCADE")
  28.      */
  29.     private Item $item;
  30.     /**
  31.      * @ORM\Column(name="quantity", type="integer")
  32.      */
  33.     private int $quantity;
  34.     /**
  35.      * @ORM\Column(name="price", type="integer")
  36.      */
  37.     private int $price;
  38.     /**
  39.      * @throws Exception
  40.      */
  41.     public function __construct(Cart $cartItem $itemint $quantityint $price)
  42.     {
  43.         $this->cart $cart;
  44.         $this->item $item;
  45.         $this->quantity $quantity;
  46.         $this->price $price;
  47.         $this->createdAt DateTimeHelper::getNowDateTime();
  48.     }
  49.     public function getCart(): Cart
  50.     {
  51.         return $this->cart;
  52.     }
  53.     public function getItem(): Item
  54.     {
  55.         return $this->item;
  56.     }
  57.     public function getQuantity(): int
  58.     {
  59.         return $this->quantity;
  60.     }
  61.     public function getPrice(): int
  62.     {
  63.         return $this->price;
  64.     }
  65.     public function setQuantity(int $quantity): CartElement
  66.     {
  67.         $this->quantity $quantity;
  68.         return $this;
  69.     }
  70.     public function getStringInfo(): string
  71.     {
  72.         return $this->getItem()
  73.             ? $this->getItem()->getProduct()->getDescription()
  74.             . ' ' $this->getItem()->getProduct()->getBrandName()
  75.             . ' / ' mb_strtoupper($this->getItem()->getProduct()->getArticleSearch())
  76.             : ''
  77.             ;
  78.     }
  79. }