<?php
namespace Boab\EcommerceBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Order
* @ORM\Table(name="orders")
* @ORM\Entity(repositoryClass="Boab\EcommerceBundle\Repository\OrderRepository")
*/
class Order extends AbstractOrder implements OrderInterface
{
/**
*@ORM\OneToMany(targetEntity="OrderItem", mappedBy="order", cascade={"persist","remove"}, orphanRemoval=true)
* @ORM\JoinColumn(onDelete="CASCADE")
*/
protected $orderItems;
/**
* @ORM\Column(type="string", length=100, nullable=true)
*/
private $city;
/**
* @ORM\Column(type="string", length=100)
*/
private $country;
/**
* @ORM\Column(type="string", length=100)
*/
private $email;
/**
* @ORM\Column(type="string", length=20)
*/
private $postalCode;
/**
* @ORM\Column(type="string", length=150, nullable=true)
*/
private $hash;
private $cart;
/**
* @ORM\Column(type="string", length=10, nullable=true)
*/
private $pin;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $customerId;
/**
* Constructor
*/
public function __construct($cart=null)
{
$this->orderItems = new \Doctrine\Common\Collections\ArrayCollection();
$this->cart = $cart;
}
/**
* Add OrderItem.
*
* @param \Boab\EcommerceBundle\Entity\OrderItem $orderItem
*
* @return User
*/
public function addOrderItem(OrderItem $orderItem)
{
$this->orderItems[] = $orderItem;
return $this;
}
/**
* Remove OrderItem.
*
* @param \Boab\EcommerceBundle\Entity\OrderItem $orderItem
*
* @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
*/
public function removeOrderItem(\Boab\EcommerceBundle\Entity\OrderItem $orderItem)
{
return $this->orderItems->removeElement($orderItem);
}
/**
* Get OrderItems.
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getOrderItems()
{
return $this->orderItems;
}
public function getCustomerName()
{
return $this->getFirstName() .' '.$this->getLastName();
}
public function getCountry(): ?string
{
return $this->country;
}
public function setCountry(string $country): self
{
$this->country = $country;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getPostalCode(): ?string
{
return $this->postalCode;
}
public function setPostalCode(?string $postalCode): self
{
$this->postalCode = $postalCode;
return $this;
}
public function addCart(CartInterface $cart)
{
$this->cart = $cart;
}
public function getCart()
{
return $this->cart;
}
public function isPaid(): bool
{
return self::PAID == $this->getStatus() || 'approved'==strtolower($this->getStatus()) ;
}
public function getHash(): ?string
{
return $this->hash;
}
public function setHash(?string $hash): self
{
$this->hash = $hash;
return $this;
}
public function getSubtotal():float
{
if($this->orderItems->isEmpty()){
throw new \Exception('Your order is empty how did this happen.');
}
$total = 0;
foreach($this->orderItems as $item){
$total += $item->getAmount();
}
return $total;
}
public function getPin(): ?string
{
return $this->pin;
}
public function setPin(?string $pin): self
{
$this->pin = $pin;
return $this;
}
public function getCustomerId(): ?int
{
return $this->customerId;
}
public function setCustomerId(?int $customerId): self
{
$this->customerId = $customerId;
return $this;
}
/**
* Get the value of city
*/
public function getCity()
{
return $this->city;
}
/**
* Set the value of city
*
* @return self
*/
public function setCity($city)
{
$this->city = $city;
return $this;
}
}