src/Entity/CartProduct.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Knp\DoctrineBehaviors\Contract\Entity\SoftDeletableInterface;
  4. use Knp\DoctrineBehaviors\Model\SoftDeletable\SoftDeletableTrait;
  5. use Knp\DoctrineBehaviors\Model\Blameable\BlameableTrait;
  6. use Knp\DoctrineBehaviors\Contract\Entity\BlameableInterface;
  7. use Knp\DoctrineBehaviors\Model\Timestampable\TimestampableTrait;
  8. use Knp\DoctrineBehaviors\Contract\Entity\TimestampableInterface;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. use Symfony\Component\HttpFoundation\File\UploadedFile;
  14. use Symfony\Component\HttpFoundation\File\File;
  15. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  16. /**
  17.  * @ORM\Entity
  18.  * @ORM\Table(name="cart_product")
  19.  */
  20. class CartProduct implements BlameableInterfaceTimestampableInterface  {
  21.     use BlameableTrait;
  22.     use TimestampableTrait;
  23.     /**
  24.      * @ORM\Id
  25.      * @ORM\Column(type="integer")
  26.      * @ORM\GeneratedValue(strategy="AUTO")
  27.      */
  28.     protected $id;
  29.     /**
  30.      * @ORM\ManyToOne(targetEntity="App\Entity\Cart", inversedBy="products")
  31.      */
  32.     private $cart;
  33.     /**
  34.      * @ORM\ManyToOne(targetEntity="App\Entity\Product")
  35.      */
  36.     private $product;
  37.     /**
  38.      * @ORM\ManyToOne(targetEntity="App\Entity\SubProduct", inversedBy="carts")
  39.      */
  40.     private $subProduct;
  41.     /**
  42.      * @ORM\ManyToOne(targetEntity="App\Entity\Currency")
  43.      */
  44.     private $currency;
  45.     /**
  46.      * @ORM\ManyToOne(targetEntity="App\Entity\ProductVat")
  47.      */
  48.     private $vat;
  49.     /**
  50.      * @ORM\ManyToOne(targetEntity="App\Entity\ProductPriceVariants")
  51.      */
  52.     private $variant;
  53.     /**
  54.      * @var integer
  55.      *
  56.      * @ORM\Column(name="quantity", type="integer", length=6, nullable=true)
  57.      */
  58.     private $quantity;
  59.     /**
  60.      * @var string
  61.      *
  62.      * @ORM\Column(name="inscription", type="text", nullable=true)
  63.      */
  64.     private $inscription;
  65.     /**
  66.      * @Doctrine\ORM\Mapping\Column(type="decimal", precision=10, scale=2, nullable=true)
  67.      */
  68.     protected $price;
  69.     /**
  70.      * @var string
  71.      *
  72.      * @ORM\Column(name="session", type="string", length=40, nullable=true)
  73.      */
  74.     private $session;
  75.     /**
  76.      * @var string
  77.      *
  78.      * @ORM\Column(name="code", type="string", length=255, nullable=true)
  79.      */
  80.     private $code;
  81.     /**
  82.      * @Doctrine\ORM\Mapping\Column(name="price_initial", type="decimal", precision=10, scale=2, nullable=true)
  83.      */
  84.     protected $priceInitial;
  85.     /**
  86.      * @ORM\OneToMany(targetEntity="App\Entity\CartProductParameterValue", mappedBy="cartProduct", cascade={"all"})
  87.      */
  88.     protected $parameterValues;
  89.     /**
  90.      * @ORM\OneToMany(targetEntity="App\Entity\CartProductEquipment", mappedBy="cartProduct", cascade={"all"})
  91.      * @Doctrine\ORM\Mapping\OrderBy({"id" = "DESC"})
  92.      */
  93.     protected $equipments;
  94.     /**
  95.      * @Doctrine\ORM\Mapping\Column(type="decimal", precision=10, name="price_net", scale=2, nullable=true)
  96.      */
  97.     protected $priceNet;
  98.     public function __construct()
  99.     {
  100.         $this->parameterValues = new ArrayCollection();
  101.         $this->equipments = new ArrayCollection();
  102.     }
  103.     public function getEquipmentAsString($cut false$delimiter ', ')
  104.     {
  105.         $data = array();
  106.         $equipments $this->getEquipments();
  107.         /** @var $kind CartProductEquipment */
  108.         foreach ($equipments as $kind)
  109.         {
  110.             $sign = ($kind->getCurrency()) ? $kind->getCurrency()->getSign() : '';
  111.             $data[] = $kind->getEquipment()->getName().' ('.$kind->getPrice().$sign.')';
  112.         }
  113.         return implode($delimiter$data);
  114.     }
  115.     /**
  116.      * Get id
  117.      *
  118.      * @return integer
  119.      */
  120.     public function getId()
  121.     {
  122.         return $this->id;
  123.     }
  124.     public function getGrossPrice() {
  125.         return $this->price;
  126.     }
  127.     /**
  128.      * Set quantity
  129.      *
  130.      * @param integer $quantity
  131.      *
  132.      * @return CartProduct
  133.      */
  134.     public function setQuantity($quantity)
  135.     {
  136.         $this->quantity $quantity;
  137.         return $this;
  138.     }
  139.     /**
  140.      * Get quantity
  141.      *
  142.      * @return integer
  143.      */
  144.     public function getQuantity()
  145.     {
  146.         return $this->quantity;
  147.     }
  148.     /**
  149.      * Set inscription
  150.      *
  151.      * @param string $inscription
  152.      *
  153.      * @return CartProduct
  154.      */
  155.     public function setInscription($inscription)
  156.     {
  157.         $this->inscription $inscription;
  158.         return $this;
  159.     }
  160.     /**
  161.      * Get inscription
  162.      *
  163.      * @return string
  164.      */
  165.     public function getInscription()
  166.     {
  167.         return $this->inscription;
  168.     }
  169.     /**
  170.      * Set price
  171.      *
  172.      * @param string $price
  173.      *
  174.      * @return CartProduct
  175.      */
  176.     public function setPrice($price)
  177.     {
  178.         $this->price $price;
  179.         return $this;
  180.     }
  181.     /**
  182.      * Get price
  183.      *
  184.      * @return string
  185.      */
  186.     public function getPrice()
  187.     {
  188.         return $this->price;
  189.     }
  190.     /**
  191.      * Set session
  192.      *
  193.      * @param string $session
  194.      *
  195.      * @return CartProduct
  196.      */
  197.     public function setSession($session)
  198.     {
  199.         $this->session $session;
  200.         return $this;
  201.     }
  202.     /**
  203.      * Get session
  204.      *
  205.      * @return string
  206.      */
  207.     public function getSession()
  208.     {
  209.         return $this->session;
  210.     }
  211.     /**
  212.      * Set priceInitial
  213.      *
  214.      * @param string $priceInitial
  215.      *
  216.      * @return CartProduct
  217.      */
  218.     public function setPriceInitial($priceInitial)
  219.     {
  220.         $this->priceInitial $priceInitial;
  221.         return $this;
  222.     }
  223.     /**
  224.      * Get priceInitial
  225.      *
  226.      * @return string
  227.      */
  228.     public function getPriceInitial()
  229.     {
  230.         return $this->priceInitial;
  231.     }
  232.     /**
  233.      * Set cart
  234.      *
  235.      * @param \App\Entity\Cart $cart
  236.      *
  237.      * @return CartProduct
  238.      */
  239.     public function setCart(\App\Entity\Cart $cart null)
  240.     {
  241.         $this->cart $cart;
  242.         return $this;
  243.     }
  244.     /**
  245.      * Get cart
  246.      *
  247.      * @return \App\Entity\Cart
  248.      */
  249.     public function getCart()
  250.     {
  251.         return $this->cart;
  252.     }
  253.     /**
  254.      * Set product
  255.      *
  256.      * @param \App\Entity\Product $product
  257.      *
  258.      * @return CartProduct
  259.      */
  260.     public function setProduct(\App\Entity\Product $product null)
  261.     {
  262.         $this->product $product;
  263.         return $this;
  264.     }
  265.     public function getProductName() {
  266.         if ($this->getSubProduct()) {
  267.             return $this->getSubProduct()->getName();
  268.         }
  269.         return $this->getProduct()->getName();
  270.     }
  271.     /**
  272.      * Get product
  273.      *
  274.      * @return \App\Entity\Product
  275.      */
  276.     public function getProduct()
  277.     {
  278.         return $this->product;
  279.     }
  280.     /**
  281.      * Set currency
  282.      *
  283.      * @param \App\Entity\Currency $currency
  284.      *
  285.      * @return CartProduct
  286.      */
  287.     public function setCurrency(\App\Entity\Currency $currency null)
  288.     {
  289.         $this->currency $currency;
  290.         return $this;
  291.     }
  292.     /**
  293.      * Get currency
  294.      *
  295.      * @return \App\Entity\Currency
  296.      */
  297.     public function getCurrency()
  298.     {
  299.         return $this->currency;
  300.     }
  301.     public function getVariant(): ?ProductPriceVariants
  302.     {
  303.         return $this->variant;
  304.     }
  305.     public function setVariant(?ProductPriceVariants $variant): self
  306.     {
  307.         $this->variant $variant;
  308.         return $this;
  309.     }
  310.     public function getVat(): ?ProductVat
  311.     {
  312.         return $this->vat;
  313.     }
  314.     public function setVat(?ProductVat $vat): self
  315.     {
  316.         $this->vat $vat;
  317.         return $this;
  318.     }
  319.     /**
  320.      * @return Collection|CartProductParameterValue[]
  321.      */
  322.     public function getParameterValues(): Collection
  323.     {
  324.         return $this->parameterValues;
  325.     }
  326.     public function addParameterValue(CartProductParameterValue $parameterValue): self
  327.     {
  328.         if (!$this->parameterValues->contains($parameterValue)) {
  329.             $this->parameterValues[] = $parameterValue;
  330.             $parameterValue->setCartProduct($this);
  331.         }
  332.         return $this;
  333.     }
  334.     public function removeParameterValue(CartProductParameterValue $parameterValue): self
  335.     {
  336.         if ($this->parameterValues->contains($parameterValue)) {
  337.             $this->parameterValues->removeElement($parameterValue);
  338.             // set the owning side to null (unless already changed)
  339.             if ($parameterValue->getCartProduct() === $this) {
  340.                 $parameterValue->setCartProduct(null);
  341.             }
  342.         }
  343.         return $this;
  344.     }
  345.     public function getCode(): ?string
  346.     {
  347.         return $this->code;
  348.     }
  349.     public function setCode(?string $code): self
  350.     {
  351.         $this->code $code;
  352.         return $this;
  353.     }
  354.     /**
  355.      * @return Collection|CartProductEquipment[]
  356.      */
  357.     public function getEquipments(): Collection
  358.     {
  359.         return $this->equipments;
  360.     }
  361.     public function addEquipment(CartProductEquipment $equipment): self
  362.     {
  363.         if (!$this->equipments->contains($equipment)) {
  364.             $this->equipments[] = $equipment;
  365.             $equipment->setCartProduct($this);
  366.         }
  367.         return $this;
  368.     }
  369.     public function removeEquipment(CartProductEquipment $equipment): self
  370.     {
  371.         if ($this->equipments->contains($equipment)) {
  372.             $this->equipments->removeElement($equipment);
  373.             // set the owning side to null (unless already changed)
  374.             if ($equipment->getCartProduct() === $this) {
  375.                 $equipment->setCartProduct(null);
  376.             }
  377.         }
  378.         return $this;
  379.     }
  380.     public function getSubProduct(): ?SubProduct
  381.     {
  382.         return $this->subProduct;
  383.     }
  384.     public function setSubProduct(?SubProduct $subProduct): self
  385.     {
  386.         $this->subProduct $subProduct;
  387.         return $this;
  388.     }
  389.     /**
  390.      * @return mixed
  391.      */
  392.     public function getPriceNet()
  393.     {
  394.         return $this->priceNet;
  395.     }
  396.     /**
  397.      * @param mixed $priceNet
  398.      */
  399.     public function setPriceNet($priceNet): void
  400.     {
  401.         $this->priceNet $priceNet;
  402.     }
  403.     public function getSubtotal() {
  404.         if ($this->getCart()->getLanguage()->getLocaleShort() == 'ro') {
  405.             $params $this->getProduct()->getLangParams();
  406.             foreach ($params as $param) {
  407.                 if ($param->getLanguage()->getLocaleShort() == 'ro') {
  408.                     $vat $param->getVat();
  409.                     $vatRate = ($vat->getValue()+100)/100;
  410.                     return $this->getPriceNet() * $this->getQuantity() * $vatRate;
  411.                 }
  412.             }
  413.         }
  414.         return $this->getPrice() * $this->getQuantity();
  415.     }
  416. }