src/Entity/CartProduct.php line 30

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