<?php
namespace App\Entity;
use Knp\DoctrineBehaviors\Contract\Entity\SoftDeletableInterface;
use Knp\DoctrineBehaviors\Model\SoftDeletable\SoftDeletableTrait;
use Knp\DoctrineBehaviors\Model\Blameable\BlameableTrait;
use Knp\DoctrineBehaviors\Contract\Entity\BlameableInterface;
use Knp\DoctrineBehaviors\Model\Timestampable\TimestampableTrait;
use Knp\DoctrineBehaviors\Contract\Entity\TimestampableInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity
* @ORM\Table(name="cart_product")
*/
class CartProduct implements BlameableInterface, TimestampableInterface, SoftDeletableInterface {
use BlameableTrait;
use TimestampableTrait;
use SoftDeletableTrait;
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Cart", inversedBy="products")
*/
private $cart;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Product")
*/
private $product;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\SubProduct", inversedBy="carts")
*/
private $subProduct;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Currency")
*/
private $currency;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\ProductVat")
*/
private $vat;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\ProductPriceVariants")
*/
private $variant;
/**
* @var integer
*
* @ORM\Column(name="quantity", type="integer", length=6, nullable=true)
*/
private $quantity;
/**
* @var string
*
* @ORM\Column(name="inscription", type="text", nullable=true)
*/
private $inscription;
/**
* @Doctrine\ORM\Mapping\Column(type="decimal", precision=10, scale=2, nullable=true)
*/
protected $price;
/**
* @var string
*
* @ORM\Column(name="session", type="string", length=40, nullable=true)
*/
private $session;
/**
* @var string
*
* @ORM\Column(name="code", type="string", length=255, nullable=true)
*/
private $code;
/**
* @Doctrine\ORM\Mapping\Column(name="price_initial", type="decimal", precision=10, scale=2, nullable=true)
*/
protected $priceInitial;
/**
* @ORM\OneToMany(targetEntity="App\Entity\CartProductParameterValue", mappedBy="cartProduct", cascade={"all"})
*/
protected $parameterValues;
/**
* @ORM\OneToMany(targetEntity="App\Entity\CartProductEquipment", mappedBy="cartProduct", cascade={"all"})
* @Doctrine\ORM\Mapping\OrderBy({"id" = "DESC"})
*/
protected $equipments;
/**
* @Doctrine\ORM\Mapping\Column(type="decimal", precision=10, name="price_net", scale=2, nullable=true)
*/
protected $priceNet;
public function __construct()
{
$this->parameterValues = new ArrayCollection();
$this->equipments = new ArrayCollection();
}
public function getEquipmentAsString($cut = false, $delimiter = ', ')
{
$data = array();
$equipments = $this->getEquipments();
/** @var $kind CartProductEquipment */
foreach ($equipments as $kind)
{
$sign = ($kind->getCurrency()) ? $kind->getCurrency()->getSign() : '';
$data[] = $kind->getEquipment()->getName().' ('.$kind->getPrice().$sign.')';
}
return implode($delimiter, $data);
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
public function getGrossPrice() {
return $this->price;
}
/**
* Set quantity
*
* @param integer $quantity
*
* @return CartProduct
*/
public function setQuantity($quantity)
{
$this->quantity = $quantity;
return $this;
}
/**
* Get quantity
*
* @return integer
*/
public function getQuantity()
{
return $this->quantity;
}
/**
* Set inscription
*
* @param string $inscription
*
* @return CartProduct
*/
public function setInscription($inscription)
{
$this->inscription = $inscription;
return $this;
}
/**
* Get inscription
*
* @return string
*/
public function getInscription()
{
return $this->inscription;
}
/**
* Set price
*
* @param string $price
*
* @return CartProduct
*/
public function setPrice($price)
{
$this->price = $price;
return $this;
}
/**
* Get price
*
* @return string
*/
public function getPrice()
{
return $this->price;
}
/**
* Set session
*
* @param string $session
*
* @return CartProduct
*/
public function setSession($session)
{
$this->session = $session;
return $this;
}
/**
* Get session
*
* @return string
*/
public function getSession()
{
return $this->session;
}
/**
* Set priceInitial
*
* @param string $priceInitial
*
* @return CartProduct
*/
public function setPriceInitial($priceInitial)
{
$this->priceInitial = $priceInitial;
return $this;
}
/**
* Get priceInitial
*
* @return string
*/
public function getPriceInitial()
{
return $this->priceInitial;
}
/**
* Set cart
*
* @param \App\Entity\Cart $cart
*
* @return CartProduct
*/
public function setCart(\App\Entity\Cart $cart = null)
{
$this->cart = $cart;
return $this;
}
/**
* Get cart
*
* @return \App\Entity\Cart
*/
public function getCart()
{
return $this->cart;
}
/**
* Set product
*
* @param \App\Entity\Product $product
*
* @return CartProduct
*/
public function setProduct(\App\Entity\Product $product = null)
{
$this->product = $product;
return $this;
}
public function getProductName() {
if ($this->getSubProduct()) {
return $this->getSubProduct()->getName();
}
return $this->getProduct()->getName();
}
/**
* Get product
*
* @return \App\Entity\Product
*/
public function getProduct()
{
return $this->product;
}
/**
* Set currency
*
* @param \App\Entity\Currency $currency
*
* @return CartProduct
*/
public function setCurrency(\App\Entity\Currency $currency = null)
{
$this->currency = $currency;
return $this;
}
/**
* Get currency
*
* @return \App\Entity\Currency
*/
public function getCurrency()
{
return $this->currency;
}
public function getVariant(): ?ProductPriceVariants
{
return $this->variant;
}
public function setVariant(?ProductPriceVariants $variant): self
{
$this->variant = $variant;
return $this;
}
public function getVat(): ?ProductVat
{
return $this->vat;
}
public function setVat(?ProductVat $vat): self
{
$this->vat = $vat;
return $this;
}
/**
* @return Collection|CartProductParameterValue[]
*/
public function getParameterValues(): Collection
{
return $this->parameterValues;
}
public function addParameterValue(CartProductParameterValue $parameterValue): self
{
if (!$this->parameterValues->contains($parameterValue)) {
$this->parameterValues[] = $parameterValue;
$parameterValue->setCartProduct($this);
}
return $this;
}
public function removeParameterValue(CartProductParameterValue $parameterValue): self
{
if ($this->parameterValues->contains($parameterValue)) {
$this->parameterValues->removeElement($parameterValue);
// set the owning side to null (unless already changed)
if ($parameterValue->getCartProduct() === $this) {
$parameterValue->setCartProduct(null);
}
}
return $this;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(?string $code): self
{
$this->code = $code;
return $this;
}
/**
* @return Collection|CartProductEquipment[]
*/
public function getEquipments(): Collection
{
return $this->equipments;
}
public function addEquipment(CartProductEquipment $equipment): self
{
if (!$this->equipments->contains($equipment)) {
$this->equipments[] = $equipment;
$equipment->setCartProduct($this);
}
return $this;
}
public function removeEquipment(CartProductEquipment $equipment): self
{
if ($this->equipments->contains($equipment)) {
$this->equipments->removeElement($equipment);
// set the owning side to null (unless already changed)
if ($equipment->getCartProduct() === $this) {
$equipment->setCartProduct(null);
}
}
return $this;
}
public function getSubProduct(): ?SubProduct
{
return $this->subProduct;
}
public function setSubProduct(?SubProduct $subProduct): self
{
$this->subProduct = $subProduct;
return $this;
}
/**
* @return mixed
*/
public function getPriceNet()
{
return $this->priceNet;
}
/**
* @param mixed $priceNet
*/
public function setPriceNet($priceNet): void
{
$this->priceNet = $priceNet;
}
public function getSubtotal() {
if ($this->getCart()->getLanguage()->getLocaleShort() == 'ro') {
$params = $this->getProduct()->getLangParams();
foreach ($params as $param) {
if ($param->getLanguage()->getLocaleShort() == 'ro') {
$vat = $param->getVat();
$vatRate = ($vat->getValue()+100)/100;
return $this->getPriceNet() * $this->getQuantity() * $vatRate;
}
}
}
return $this->getPrice() * $this->getQuantity();
}
}