<?php
namespace App\Entity;
use App\Repository\CartRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=CartRepository::class)
* @ORM\EntityListeners({
* "App\Listener\EntityListener"
* })
*/
class Cart
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=190, nullable=true)
*/
private $sid;
/**
* @ORM\Column(type="string", length=3, nullable=true)
*/
private $countryDelivery;
/**
* @ORM\ManyToOne(targetEntity=Client::class, inversedBy="carts")
*/
private $client;
/**
* @ORM\Column(type="datetime")
*/
private $createts;
/**
* @ORM\OneToMany(targetEntity=CartItem::class, mappedBy="cart", orphanRemoval=true, cascade={"persist","remove"})
*/
private $cartItems;
/**
* @ORM\Column(type="string", length=100, nullable=true)
*/
protected $firstName;
/**
* @ORM\Column(type="string", length=100, nullable=true)
*/
protected $lastName;
/**
* @ORM\Column(type="string", length=100, nullable=true)
*/
protected $phone;
/**
* @ORM\Column(type="string", length=100, nullable=true)
*/
protected $email;
/**
* @ORM\Column(type="text", nullable=true)
*/
protected $note;
/**
* @ORM\ManyToOne(targetEntity=Transport::class)
* @ORM\JoinColumn(nullable=true)
*/
private $transport;
/**
* @ORM\Column(type="float", nullable=true)
*/
protected $transportPrice;
/**
* @ORM\ManyToOne(targetEntity=Payment::class)
* @ORM\JoinColumn(nullable=true)
*/
private $payment;
/**
* @ORM\Column(type="float", nullable=true)
*/
protected $paymentPrice;
/**
* @ORM\ManyToOne(targetEntity=CartAddress::class, cascade={"persist"})
*/
private $billingAddress;
/**
* @ORM\ManyToOne(targetEntity=CartAddress::class, cascade={"persist"})
*/
private $deliveryAddress;
/**
* @ORM\ManyToOne(targetEntity=Dealer::class)
*/
private $dealer;
/**
* @ORM\Column(type="boolean")
*/
protected $hasDeliveryAddress = false;
public function __construct()
{
$this->cartItems = new ArrayCollection();
}
public function getSumPrice($currency)
{
$suma = 0;
foreach ($this->getCartItems() as $cartItem) {
$suma += $cartItem->getProduct()->getPricelists()[$currency]->getPrice()*$cartItem->getCount();
}
//$suma+= $this->getPaymentPrice() + $this->getTransportPrice();
return $suma;
}
public function getId(): ?int
{
return $this->id;
}
public function getSid(): ?string
{
return $this->sid;
}
public function setSid(?string $sid): self
{
$this->sid = $sid;
return $this;
}
public function getClient(): ?Client
{
return $this->client;
}
public function setClient(?Client $client): self
{
$this->client = $client;
return $this;
}
public function getCreatets(): ?\DateTimeInterface
{
return $this->createts;
}
public function setCreatets(\DateTimeInterface $createts): self
{
$this->createts = $createts;
return $this;
}
/**
* @return Collection|CartItem[]
*/
public function getCartItems(): Collection
{
return $this->cartItems;
}
public function addCartItem(CartItem $cartItem): self
{
if (!$this->cartItems->contains($cartItem)) {
$this->cartItems[] = $cartItem;
$cartItem->setCart($this);
}
return $this;
}
public function removeCartItem(CartItem $cartItem): self
{
if ($this->cartItems->contains($cartItem)) {
$this->cartItems->removeElement($cartItem);
// set the owning side to null (unless already changed)
if ($cartItem->getCart() === $this) {
$cartItem->setCart(null);
}
}
return $this;
}
/**
* Get FirstName
*
* @return mixed
*/
public function getFirstName()
{
return $this->firstName;
}
/**
* Set FirstName
*
* @param mixed $firstName
*/
public function setFirstName( $firstName )
{
$this->firstName = $firstName;
}
/**
* Get LastName
*
* @return mixed
*/
public function getLastName()
{
return $this->lastName;
}
/**
* Set LastName
*
* @param mixed $lastName
*/
public function setLastName( $lastName )
{
$this->lastName = $lastName;
}
/**
* Get Phone
*
* @return mixed
*/
public function getPhone()
{
return $this->phone;
}
/**
* Set Phone
*
* @param mixed $phone
*/
public function setPhone( $phone )
{
$this->phone = $phone;
}
/**
* Get Email
*
* @return mixed
*/
public function getEmail()
{
return $this->email;
}
/**
* Set Email
*
* @param mixed $email
*/
public function setEmail( $email )
{
$this->email = $email;
}
/**
* Get Note
*
* @return mixed
*/
public function getNote()
{
return $this->note;
}
/**
* Set Note
*
* @param mixed $note
*/
public function setNote( $note )
{
$this->note = $note;
}
/**
* Get Transport
*
* @return mixed
*/
public function getTransport()
{
return $this->transport;
}
/**
* Set Transport
*
* @param mixed $transport
*/
public function setTransport( $transport )
{
$this->transport = $transport;
}
/**
* Get Payment
*
* @return mixed
*/
public function getPayment()
{
return $this->payment;
}
/**
* Set Payment
*
* @param mixed $payment
*/
public function setPayment( $payment )
{
$this->payment = $payment;
}
/**
* Get BillingAddress
*
* @return mixed
*/
public function getBillingAddress()
{
return $this->billingAddress;
}
/**
* Set BillingAddress
*
* @param mixed $billingAddress
*/
public function setBillingAddress( $billingAddress )
{
$this->billingAddress = $billingAddress;
}
/**
* Get DeliveryAddress
*
* @return mixed
*/
public function getDeliveryAddress()
{
return $this->deliveryAddress;
}
/**
* Set DeliveryAddress
*
* @param mixed $deliveryAddress
*/
public function setDeliveryAddress( $deliveryAddress )
{
$this->deliveryAddress = $deliveryAddress;
}
/**
* Get HasDeliveryAddress
*
* @return mixed
*/
public function getHasDeliveryAddress()
{
return $this->hasDeliveryAddress;
}
/**
* Set HasDeliveryAddress
*
* @param mixed $hasDeliveryAddress
*/
public function setHasDeliveryAddress( $hasDeliveryAddress )
{
$this->hasDeliveryAddress = $hasDeliveryAddress;
}
/**
* Get TransportPrice
*
* @return mixed
*/
public function getTransportPrice()
{
return $this->transportPrice;
}
/**
* Set TransportPrice
*
* @param mixed $transportPrice
*/
public function setTransportPrice( $transportPrice )
{
$this->transportPrice = $transportPrice;
}
/**
* Get PaymentPrice
*
* @return mixed
*/
public function getPaymentPrice()
{
return $this->paymentPrice;
}
/**
* Set PaymentPrice
*
* @param mixed $paymentPrice
*/
public function setPaymentPrice( $paymentPrice )
{
$this->paymentPrice = $paymentPrice;
}
/**
* Get Dealer
*
* @return mixed
*/
public function getDealer(): ?Dealer
{
return $this->dealer;
}
/**
* Set Dealer
*
* @param mixed $dealer
*/
public function setDealer( $dealer )
{
$this->dealer = $dealer;
}
/**
* Get CountryDelivery
*
* @return mixed
*/
public function getCountryDelivery()
{
return $this->countryDelivery;
}
/**
* Set CountryDelivery
*
* @param mixed $countryDelivery
*/
public function setCountryDelivery( $countryDelivery )
{
$this->countryDelivery = $countryDelivery;
}
}