src/Entity/Gos/ProductPackItem.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Gos;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. /**
  7.  * @ORM\Entity(repositoryClass="App\Repository\Gos\ProductPackItemRepository")
  8.  * @ORM\HasLifecycleCallbacks
  9.  */
  10. class ProductPackItem
  11. {
  12.     /**
  13.      * @ORM\Id()
  14.      * @ORM\GeneratedValue()
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.     /**
  19.      * @var bool
  20.      *
  21.      * @ORM\Column(type="boolean", nullable=true)
  22.      */
  23.     private $isGross;
  24.     /**
  25.      * @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
  26.      */
  27.     private $discount;
  28.     /**
  29.      * @ORM\ManyToOne(targetEntity="App\Entity\Gos\ProductPack", inversedBy="productPackItem")
  30.      * @ORM\JoinColumn()
  31.      */
  32.     private $productPack;
  33.     /**
  34.      * @ORM\ManyToOne(targetEntity="App\Entity\Gos\ProductVariant", inversedBy="productPackItem")
  35.      * @ORM\JoinColumn()
  36.      */
  37.     private $productVariant;
  38.     /**
  39.      * @ORM\OneToMany(targetEntity="App\Entity\Gos\OrderProductVariant", mappedBy="productPackItem")
  40.      */
  41.     private $orderProductVariant;
  42.     /**
  43.      * @ORM\Column(type="datetime")
  44.      */
  45.     private $createdAt;
  46.     /**
  47.      * @ORM\Column(type="datetime", nullable=true)
  48.      */
  49.     private $updatedAt;
  50.     /**
  51.      * @ORM\Column(type="float", nullable=true)
  52.      */
  53.     private $price;
  54.     /**
  55.      * @ORM\Column(type="array", nullable=true)
  56.      */
  57.     private $bulletPoints = [];
  58.     /**
  59.      * @var string
  60.      *
  61.      * @ORM\Column(type="string", length=255, nullable=true)
  62.      */
  63.     private $description;
  64.     /**
  65.      * @ORM\Column(type="integer", options={"default": 1})
  66.      */
  67.     private $quantity 1;
  68.     public function __construct()
  69.     {
  70.         $this->orderProductVariant = new ArrayCollection();
  71.     }
  72.     /** @ORM\PrePersist() */
  73.     public function prePersist()
  74.     {
  75.         $this->createdAt = new \DateTime();
  76.     }
  77.     /** @ORM\PreUpdate() */
  78.     public function preUpdate()
  79.     {
  80.         $this->updatedAt = new \DateTime();
  81.     }
  82.     public function __toString()
  83.     {
  84.         return (string) $this->id;
  85.     }
  86.     public function getDiscountNet()
  87.     {
  88.         if ($this->getIsGross())
  89.         {
  90.             return $this->getProductVariant()->getFullPrice('net') - $this->getPriceNet();
  91.         }
  92.         return $this->getDiscount();
  93.     }
  94.     public function getDiscountGross()
  95.     {
  96.         if ($this->getIsGross())
  97.         {
  98.             return $this->getDiscount();
  99.         }
  100.         return $this->getProductVariant()->getFullPrice('gross') - $this->getPriceGross();
  101.     }
  102.     public function getPriceNet(): ?float
  103.     {
  104.         $productVariant $this->getProductVariant();
  105.         $fullPriceGross $productVariant->getFullPrice('gross');
  106.         if ($this->getIsGross())
  107.         {
  108.             $priceNet $productVariant->getPriceNetDiscountAmount($fullPriceGross$this->getDiscount());
  109.             /** @var ProductVariant $virtualVariant */
  110.             foreach ($productVariant->getVirtualVariant() as $virtualVariant)
  111.             {
  112.                 $priceNet += $virtualVariant->getPriceNetDiscountAmount($fullPriceGross$this->getDiscount());
  113.             }
  114.         }
  115.         else
  116.         {
  117.             $priceNet $productVariant->getFullPrice('net') - $this->getDiscount();
  118.         }
  119.         if ($priceNet 0$priceNet 0;
  120.         return round($priceNet2);
  121.     }
  122.     public function getPriceGross(): ?float
  123.     {
  124.         $productVariant $this->getProductVariant();
  125.         $fullPriceNet   $productVariant->getFullPrice('net');
  126.         if ($this->getIsGross())
  127.         {
  128.             $priceGross $productVariant->getFullPrice('gross') - $this->getDiscount();
  129.         }
  130.         else
  131.         {
  132.             $priceGross $productVariant->getPriceGrossDiscountAmount($fullPriceNet$this->getDiscount());
  133.             /** @var ProductVariant $virtualVariant */
  134.             foreach ($productVariant->getVirtualVariant() as $virtualVariant)
  135.             {
  136.                 $priceGross += $virtualVariant->getPriceGrossDiscountAmount($fullPriceNet$this->getDiscount());
  137.             }
  138.         }
  139.         if ($priceGross 0$priceGross 0;
  140.         return round($priceGross2);
  141.     }
  142.     //------------------------------ setters & getters
  143.     public function getId(): ?int
  144.     {
  145.         return $this->id;
  146.     }
  147.     public function getCreatedAt(): ?\DateTimeInterface
  148.     {
  149.         return $this->createdAt;
  150.     }
  151.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  152.     {
  153.         $this->createdAt $createdAt;
  154.         return $this;
  155.     }
  156.     public function getUpdatedAt(): ?\DateTimeInterface
  157.     {
  158.         return $this->updatedAt;
  159.     }
  160.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  161.     {
  162.         $this->updatedAt $updatedAt;
  163.         return $this;
  164.     }
  165.     public function getProductPack(): ?ProductPack
  166.     {
  167.         return $this->productPack;
  168.     }
  169.     public function setProductPack(?ProductPack $productPack): self
  170.     {
  171.         $this->productPack $productPack;
  172.         return $this;
  173.     }
  174.     public function getProductVariant(): ?ProductVariant
  175.     {
  176.         return $this->productVariant;
  177.     }
  178.     public function setProductVariant(?ProductVariant $productVariant): self
  179.     {
  180.         $this->productVariant $productVariant;
  181.         return $this;
  182.     }
  183.     /**
  184.      * @return Collection|OrderProductVariant[]
  185.      */
  186.     public function getOrderProductVariant(): Collection
  187.     {
  188.         return $this->orderProductVariant;
  189.     }
  190.     public function addOrderProductVariant(OrderProductVariant $orderProductVariant): self
  191.     {
  192.         if (!$this->orderProductVariant->contains($orderProductVariant)) {
  193.             $this->orderProductVariant[] = $orderProductVariant;
  194.             $orderProductVariant->setProductPackItem($this);
  195.         }
  196.         return $this;
  197.     }
  198.     public function removeOrderProductVariant(OrderProductVariant $orderProductVariant): self
  199.     {
  200.         if ($this->orderProductVariant->contains($orderProductVariant)) {
  201.             $this->orderProductVariant->removeElement($orderProductVariant);
  202.             // set the owning side to null (unless already changed)
  203.             if ($orderProductVariant->getProductPackItem() === $this) {
  204.                 $orderProductVariant->setProductPackItem(null);
  205.             }
  206.         }
  207.         return $this;
  208.     }
  209.     public function getIsGross(): ?bool
  210.     {
  211.         return $this->isGross;
  212.     }
  213.     public function setIsGross(?bool $isGross): self
  214.     {
  215.         $this->isGross $isGross;
  216.         return $this;
  217.     }
  218.     public function getDiscount(): ?float
  219.     {
  220.         return $this->discount;
  221.     }
  222.     public function setDiscount(?float $discount): self
  223.     {
  224.         $this->discount $discount;
  225.         return $this;
  226.     }
  227.     public function getPrice(): ?float
  228.     {
  229.         return $this->price;
  230.     }
  231.     public function setPrice(?float $price): self
  232.     {
  233.         $this->price $price;
  234.         return $this;
  235.     }
  236.     public function getBulletPoints(): ?array
  237.     {
  238.         return $this->bulletPoints;
  239.     }
  240.     public function setBulletPoints(?array $bulletPoints): self
  241.     {
  242.         $this->bulletPoints array_values($bulletPoints);
  243.         return $this;
  244.     }
  245.     public function getDescription()
  246.     {
  247.         return $this->description;
  248.     }
  249.     public function setDescription(string $description): void
  250.     {
  251.         $this->description $description;
  252.     }
  253.     public function getQuantity(): ?int
  254.     {
  255.         return $this->quantity;
  256.     }
  257.     public function setQuantity(int $quantity): self
  258.     {
  259.         $this->quantity $quantity;
  260.         return $this;
  261.     }
  262. }