src/Entity/Cart.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\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Exception;
  9. /**
  10.  * @ORM\Table(name="carts__carts", uniqueConstraints={@ORM\UniqueConstraint(name="guest_idx", columns={"guest_id"})})
  11.  * @ORM\Entity(repositoryClass="App\Repository\CartRepository")
  12.  */
  13. class Cart
  14. {
  15.     use IdTrait;
  16.     /**
  17.      * @ORM\Column(name="created_at", type="datetime", nullable=false)
  18.      */
  19.     private DateTime $createdAt;
  20.     /**
  21.      * @ORM\OneToOne(targetEntity="App\Entity\User", inversedBy="cart", cascade={"persist"})
  22.      * @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=true, onDelete="SET NULL")
  23.      */
  24.     private ?User $user;
  25.     /**
  26.      * @ORM\Column(name="guest_id", type="string", nullable=true)
  27.      */
  28.     private ?string $guestId;
  29.     /**
  30.      * @ORM\Column(name="first_name", type="string", nullable=true)
  31.      */
  32.     private ?string $firstName null;
  33.     /**
  34.      * @ORM\Column(name="last_name", type="string", nullable=true)
  35.      */
  36.     private ?string $lastName null;
  37.     /**
  38.      * @ORM\Column(name="father_name", type="string", nullable=true)
  39.      */
  40.     private ?string $fatherName null;
  41.     /**
  42.      * @ORM\Column(name="phone", type="string", nullable=true)
  43.      */
  44.     private ?string $phone null;
  45.     /**
  46.      * @var Collection|CartElement[]
  47.      *
  48.      * @ORM\OneToMany(targetEntity="App\Entity\CartElement", mappedBy="cart", cascade={"persist"})
  49.      */
  50.     private $elements;
  51.     /**
  52.      * @ORM\Column(type="string", name="delivery_type", nullable=true)
  53.      */
  54.     private ?string $deliveryType null;
  55.     /**
  56.      * @ORM\Column(type="string", name="town", nullable=true)
  57.      */
  58.     private ?string $town null;
  59.     /**
  60.      * @ORM\Column(type="integer", nullable=true)
  61.      */
  62.     private ?int $postcode null;
  63.     /**
  64.      * @ORM\Column(type="string", name="street", nullable=true)
  65.      */
  66.     private ?string $street null;
  67.     /**
  68.      * @ORM\Column(type="string", name="house", nullable=true)
  69.      */
  70.     private ?string $house null;
  71.     /**
  72.      * @ORM\Column(type="string", name="apartment", nullable=true)
  73.      */
  74.     private ?string $apartment null;
  75.     /**
  76.      * @ORM\Column(type="float", nullable=true)
  77.      */
  78.     private ?float $longitude null;
  79.     /**
  80.      * @ORM\Column(type="float", nullable=true)
  81.      */
  82.     private ?float $latitude null;
  83.     /**
  84.      * @ORM\Column(type="string", name="payment_type", nullable=true)
  85.      */
  86.     private ?string $paymentType null;
  87.     /**
  88.      * @ORM\ManyToOne(targetEntity="App\Entity\TransportCompany")
  89.      * @ORM\JoinColumn(name="transport_company_id", referencedColumnName="id", nullable=true, onDelete="SET NULL")
  90.      */
  91.     private ?TransportCompany $transportCompany null;
  92.     /**
  93.      * @ORM\Column(name="comment", type="text", nullable=true)
  94.      */
  95.     private ?string $comment;
  96.     /**
  97.      * @throws Exception
  98.      */
  99.     public function __construct(User $user null$guestId null)
  100.     {
  101.         $this->user $user;
  102.         $this->guestId $guestId;
  103.         $this->elements = new ArrayCollection();
  104.         $this->createdAt DateTimeHelper::getNowDateTime();
  105.     }
  106.     public function getUser(): ?User
  107.     {
  108.         return $this->user;
  109.     }
  110.     public function setUser(?User $user): Cart
  111.     {
  112.         $this->user $user;
  113.         return $this;
  114.     }
  115.     public function getGuestId()
  116.     {
  117.         return $this->guestId;
  118.     }
  119.     public function setGuestId($guestId): Cart
  120.     {
  121.         $this->guestId $guestId;
  122.         return $this;
  123.     }
  124.     public function getFirstName(): ?string
  125.     {
  126.         return $this->firstName;
  127.     }
  128.     public function setFirstName(?string $firstName): Cart
  129.     {
  130.         $this->firstName $firstName;
  131.         return $this;
  132.     }
  133.     public function getLastName(): ?string
  134.     {
  135.         return $this->lastName;
  136.     }
  137.     public function setLastName(?string $lastName): Cart
  138.     {
  139.         $this->lastName $lastName;
  140.         return $this;
  141.     }
  142.     public function getFatherName(): ?string
  143.     {
  144.         return $this->fatherName;
  145.     }
  146.     public function setFatherName(?string $fatherName): Cart
  147.     {
  148.         $this->fatherName $fatherName;
  149.         return $this;
  150.     }
  151.     public function getPhone(): ?string
  152.     {
  153.         return $this->phone;
  154.     }
  155.     public function setPhone(?string $phone): Cart
  156.     {
  157.         $this->phone $phone;
  158.         return $this;
  159.     }
  160.     /**
  161.      * @return Collection|CartElement[]
  162.      */
  163.     public function getElements()
  164.     {
  165.         return $this->elements;
  166.     }
  167.     public function getDeliveryType(): ?string
  168.     {
  169.         return $this->deliveryType;
  170.     }
  171.     public function setDeliveryType(?string $deliveryType): Cart
  172.     {
  173.         $this->deliveryType $deliveryType;
  174.         return $this;
  175.     }
  176.     public function getPaymentType(): ?string
  177.     {
  178.         return $this->paymentType;
  179.     }
  180.     public function setPaymentType(?string $paymentType): Cart
  181.     {
  182.         $this->paymentType $paymentType;
  183.         return $this;
  184.     }
  185.     public function getComment(): ?string
  186.     {
  187.         return $this->comment;
  188.     }
  189.     public function setComment(?string $comment): Cart
  190.     {
  191.         $this->comment $comment;
  192.         return $this;
  193.     }
  194.     public function getTown(): ?string
  195.     {
  196.         return $this->town;
  197.     }
  198.     public function setTown(?string $town): Cart
  199.     {
  200.         $this->town $town;
  201.         return $this;
  202.     }
  203.     public function getPostcode(): ?int
  204.     {
  205.         return $this->postcode;
  206.     }
  207.     public function setPostcode(?int $postcode): Cart
  208.     {
  209.         $this->postcode $postcode;
  210.         return $this;
  211.     }
  212.     public function getStreet(): ?string
  213.     {
  214.         return $this->street;
  215.     }
  216.     public function setStreet(?string $street): Cart
  217.     {
  218.         $this->street $street;
  219.         return $this;
  220.     }
  221.     public function getHouse(): ?string
  222.     {
  223.         return $this->house;
  224.     }
  225.     public function setHouse(?string $house): Cart
  226.     {
  227.         $this->house $house;
  228.         return $this;
  229.     }
  230.     public function getApartment(): ?string
  231.     {
  232.         return $this->apartment;
  233.     }
  234.     public function setApartment(?string $apartment): Cart
  235.     {
  236.         $this->apartment $apartment;
  237.         return $this;
  238.     }
  239.     public function getLongitude(): ?float
  240.     {
  241.         return $this->longitude;
  242.     }
  243.     public function setLongitude(?float $longitude): Cart
  244.     {
  245.         $this->longitude $longitude;
  246.         return $this;
  247.     }
  248.     public function getLatitude(): ?float
  249.     {
  250.         return $this->latitude;
  251.     }
  252.     public function setLatitude(?float $latitude): Cart
  253.     {
  254.         $this->latitude $latitude;
  255.         return $this;
  256.     }
  257.     public function getTransportCompany(): ?TransportCompany
  258.     {
  259.         return $this->transportCompany;
  260.     }
  261.     public function setTransportCompany(?TransportCompany $transportCompany): Cart
  262.     {
  263.         $this->transportCompany $transportCompany;
  264.         return $this;
  265.     }
  266.     public function getElementsPrice()
  267.     {
  268.         $price 0;
  269.         foreach ($this->getElements() as $element) {
  270.             $price += $element->getPrice() * $element->getQuantity();
  271.         }
  272.         return $price;
  273.     }
  274. }