src/Entity/ProductPrice.php line 30

Open in your IDE?
  1. <?php
  2. // src/Acme/UserBundle/Entity/User.php
  3. namespace App\Entity;
  4. use Knp\DoctrineBehaviors\Contract\Entity\SoftDeletableInterface;
  5. use Knp\DoctrineBehaviors\Model\SoftDeletable\SoftDeletableTrait;
  6. use Knp\DoctrineBehaviors\Model\Blameable\BlameableTrait;
  7. use Knp\DoctrineBehaviors\Contract\Entity\BlameableInterface;
  8. use Knp\DoctrineBehaviors\Model\Timestampable\TimestampableTrait;
  9. use Knp\DoctrineBehaviors\Contract\Entity\TimestampableInterface;
  10. use App\Model\LangParamRelationInterface;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Doctrine\Common\Collections\Collection;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. use Doctrine\ORM\Mapping as ORM;
  15. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  16. /**
  17.  * @Doctrine\ORM\Mapping\Entity
  18.  * @Doctrine\ORM\Mapping\Table(name="product_price")
  19.  */
  20. class ProductPrice implements LangParamRelationInterface
  21. BlameableInterfaceTimestampableInterfaceSoftDeletableInterface  {
  22.     use BlameableTrait;
  23.     use TimestampableTrait;
  24.     
  25.     use SoftDeletableTrait;
  26.     
  27. /**
  28.      * @var integer
  29.      *
  30.      * @ORM\Column(name="id", type="integer", nullable=false)
  31.      * @ORM\Id
  32.      * @ORM\GeneratedValue(strategy="IDENTITY")
  33.      */
  34.     private $id;
  35.     /**
  36.      * @Doctrine\ORM\Mapping\ManyToOne(targetEntity="App\Entity\Product", inversedBy="productPrices")
  37.      * @Doctrine\ORM\Mapping\JoinColumn(name="product_id", referencedColumnName="id")
  38.      */
  39.     private $product;
  40.     /**
  41.      * @Doctrine\ORM\Mapping\ManyToOne(targetEntity="App\Entity\ProductPrice")
  42.      * @Doctrine\ORM\Mapping\JoinColumn(name="parent_product_price_id", referencedColumnName="id")
  43.      */
  44.     private $parentProductPrice;
  45.     /**
  46.      * @ORM\ManyToOne(targetEntity="App\Entity\Currency")
  47.      */
  48.     private $currency;
  49.     /**
  50.      * @Doctrine\ORM\Mapping\Column(type="float", nullable=true)
  51.      */
  52.     protected $price;
  53.     /**
  54.      * @Doctrine\ORM\Mapping\Column(type="float", nullable=true)
  55.      */
  56.     protected $discount;
  57.     /**
  58.      * @Doctrine\ORM\Mapping\Column(name="old_price", type="decimal", precision=10, scale=2, nullable=true)
  59.      */
  60.     protected $oldPrice;
  61.     /**
  62.      * @ORM\ManyToOne(targetEntity="App\Entity\Language")
  63.      * @ORM\JoinColumn(name="language", referencedColumnName="id")
  64.      */
  65.     protected $language;
  66.     /**
  67.      * Aktywny/nieakwtyny
  68.      * @Doctrine\ORM\Mapping\Column(type="boolean", options={"default"=1}, nullable=true)
  69.      */
  70.     protected $active;
  71.     /**
  72.      * @Doctrine\ORM\Mapping\OneToMany(targetEntity="App\Entity\ProductPriceVariants", mappedBy="productPrice", cascade={"persist"})
  73.      */
  74.     protected $variants;
  75.     private $tempVersion;
  76.     /**
  77.      * @var string
  78.      *
  79.      * @ORM\Column(name="automatic_price_comment", type="string", length=255, nullable=true)
  80.      */
  81.     private $automaticPriceComment;
  82.     /**
  83.      * @var string
  84.      *
  85.      * @ORM\Column(name="ean", type="string", length=255, nullable=true)
  86.      */
  87.     private $ean;
  88.     /**
  89.      * @Doctrine\ORM\Mapping\Column(name="automatic_price", type="boolean", options={"default"=1}, nullable=true)
  90.      */
  91.     protected $automaticPrice true;
  92.     /**
  93.      * @Doctrine\ORM\Mapping\Column(type="float", nullable=true)
  94.      */
  95.     protected $automaticPriceDiscount;
  96.     private $customName null;
  97.     /**
  98.      * @return null
  99.      */
  100.     public function getCustomName()
  101.     {
  102.         return $this->customName;
  103.     }
  104.     /**
  105.      * @param null $customName
  106.      */
  107.     public function setCustomName($customName): void
  108.     {
  109.         $this->customName $customName;
  110.     }
  111.     /**
  112.      * @return mixed
  113.      */
  114.     public function getDiscount()
  115.     {
  116.         return $this->discount;
  117.     }
  118.     /**
  119.      * @param mixed $discount
  120.      */
  121.     public function setDiscount($discount)
  122.     {
  123.         $this->discount $discount;
  124.     }
  125.     /**
  126.      * @return mixed
  127.      */
  128.     public function getTempVersion()
  129.     {
  130.         return $this->tempVersion;
  131.     }
  132.     /**
  133.      * @param mixed $tempVersion
  134.      */
  135.     public function setTempVersion($tempVersion): void
  136.     {
  137.         $this->tempVersion $tempVersion;
  138.     }
  139.     public function __construct()
  140.     {
  141.         $this->variants = new ArrayCollection();
  142.     }
  143.     
  144.     /**
  145.      * Get id
  146.      *
  147.      * @return integer
  148.      */
  149.     public function getId()
  150.     {
  151.         return $this->id;
  152.     }
  153.     /**
  154.      * Set price
  155.      *
  156.      * @param string $price
  157.      *
  158.      * @return ProductPrice
  159.      */
  160.     public function setPrice($price)
  161.     {
  162.         $this->price $price;
  163.         return $this;
  164.     }
  165.     /**
  166.      * Get price
  167.      *
  168.      * @return string
  169.      */
  170.     public function getPrice()
  171.     {
  172.         return $this->price;
  173.     }
  174.     public function getPriceGross(ProductVat $productVat null$precision 2$promoPriceIncluded false) {
  175.         $net $this->getPrice();
  176.         if ($promoPriceIncluded) {
  177.             foreach ($this->getProduct()->getLangParams() as $langParam) {
  178.                 if ($this->getLanguage()->getId() === $langParam->getLanguage()->getId()) {
  179.                     if ($langParam->getPromoPrice() && !$this->getProduct()->getIsVariants() && (float)$langParam->getPromoPrice() > 0) {
  180.                         $net $langParam->getPromoPrice();
  181.                     }
  182.                 }
  183.             }
  184.         }
  185.         if (is_object($productVat)) {
  186.             $vatRate = ($productVat->getValue()+100)/100;
  187.         } else {
  188.             $vatRate 1;
  189.         }
  190.         $returnPrice round($net $vatRate$precision);
  191.         return $returnPrice;
  192.     }
  193.     public function getPriceNet($priceGrossProductVat $productVat null$precision 2$promoPriceIncluded false) {
  194.         $gros $priceGross;
  195.         if (is_object($productVat)) {
  196.             $vatRate = ($productVat->getValue()+100)/100;
  197.         } else {
  198.             $vatRate 1;
  199.         }
  200.         if ($promoPriceIncluded) {
  201.             foreach ($this->getProduct()->getLangParams() as $langParam) {
  202.                 if ($this->getLanguage()->getId() === $langParam->getLanguage()->getId()) {
  203.                     if ($langParam->getPromoPrice() && !$this->getProduct()->getIsVariants() && (float)$langParam->getPromoPrice() > 0) {
  204.                         $net $langParam->getPromoPrice();
  205.                         $gros round($net $vatRate$langParam->getLanguage()->getRoundingPrecision());
  206.                     }
  207.                 }
  208.             }
  209.         }
  210.         $returnPrice round($gros $vatRate$precision);
  211.         return $returnPrice;
  212.     }
  213.     /**
  214.      * Set product
  215.      *
  216.      * @param \App\Entity\Product $product
  217.      *
  218.      * @return ProductPrice
  219.      */
  220.     public function setProduct(\App\Entity\Product $product null)
  221.     {
  222.         $this->product $product;
  223.         return $this;
  224.     }
  225.     /**
  226.      * Get product
  227.      *
  228.      * @return \App\Entity\Product
  229.      */
  230.     public function getProduct()
  231.     {
  232.         return $this->product;
  233.     }
  234.     /**
  235.      * Set currency
  236.      *
  237.      * @param \App\Entity\Currency $currency
  238.      *
  239.      * @return ProductPrice
  240.      */
  241.     public function setCurrency(\App\Entity\Currency $currency null)
  242.     {
  243.         $this->currency $currency;
  244.         return $this;
  245.     }
  246.     /**
  247.      * Get currency
  248.      *
  249.      * @return \App\Entity\Currency
  250.      */
  251.     public function getCurrency()
  252.     {
  253.         return $this->currency;
  254.     }
  255.     public function getLanguage(): ?Language
  256.     {
  257.         return $this->language;
  258.     }
  259.     public function setLanguage(?Language $language): self
  260.     {
  261.         $this->language $language;
  262.         return $this;
  263.     }
  264.     public function getOldPrice()
  265.     {
  266.         return $this->oldPrice;
  267.     }
  268.     public function setOldPrice($oldPrice): self
  269.     {
  270.         $this->oldPrice $oldPrice;
  271.         return $this;
  272.     }
  273.     /**
  274.      * @return Collection|ProductPriceVariants[]
  275.      */
  276.     public function getVariants(): Collection
  277.     {
  278.         return $this->variants;
  279.     }
  280.     public function addVariant(ProductPriceVariants $variant): self
  281.     {
  282.         if (!$this->variants->contains($variant)) {
  283.             $this->variants[] = $variant;
  284.             $variant->setProductPrice($this);
  285.         }
  286.         return $this;
  287.     }
  288.     public function removeVariant(ProductPriceVariants $variant): self
  289.     {
  290.         if ($this->variants->contains($variant)) {
  291.             $this->variants->removeElement($variant);
  292.             // set the owning side to null (unless already changed)
  293.             if ($variant->getProductPrice() === $this) {
  294.                 $variant->setProductPrice(null);
  295.             }
  296.         }
  297.         return $this;
  298.     }
  299.     /**
  300.      * @return mixed
  301.      */
  302.     public function getActive()
  303.     {
  304.         return $this->active;
  305.     }
  306.     /**
  307.      * @param mixed $active
  308.      */
  309.     public function setActive($active)
  310.     {
  311.         $this->active $active;
  312.     }
  313.     /**
  314.      * Set parentProductPrice
  315.      *
  316.      * @param \App\Entity\ProductPrice $parentProductPrice
  317.      *
  318.      * @return ProductPrice
  319.      */
  320.     public function setParentProductPrice(\App\Entity\ProductPrice $parentProductPrice null)
  321.     {
  322.         $this->parentProductPrice $parentProductPrice;
  323.         return $this;
  324.     }
  325.     /**
  326.      * Get parentProductPrice
  327.      *
  328.      * @return \App\Entity\ProductPrice
  329.      */
  330.     public function getParentProductPrice()
  331.     {
  332.         return $this->parentProductPrice;
  333.     }
  334.     /**
  335.      * @return string
  336.      */
  337.     public function getAutomaticPriceComment(): ?string
  338.     {
  339.         return $this->automaticPriceComment;
  340.     }
  341.     /**
  342.      * @param string $automaticPriceComment
  343.      */
  344.     public function setAutomaticPriceComment(string $automaticPriceComment): void
  345.     {
  346.         $this->automaticPriceComment $automaticPriceComment;
  347.     }
  348.     /**
  349.      * @return bool
  350.      */
  351.     public function isAutomaticPrice(): bool
  352.     {
  353.         return $this->automaticPrice;
  354.     }
  355.     /**
  356.      * @return bool
  357.      */
  358.     public function getAutomaticPrice(): bool
  359.     {
  360.         return $this->automaticPrice;
  361.     }
  362.     /**
  363.      * @param bool $automaticPrice
  364.      */
  365.     public function setAutomaticPrice(bool $automaticPrice): void
  366.     {
  367.         $this->automaticPrice $automaticPrice;
  368.     }
  369.     /**
  370.      * @return mixed
  371.      */
  372.     public function getAutomaticPriceDiscount()
  373.     {
  374.         return $this->automaticPriceDiscount;
  375.     }
  376.     /**
  377.      * @param mixed $automaticPriceDiscount
  378.      */
  379.     public function setAutomaticPriceDiscount($automaticPriceDiscount): void
  380.     {
  381.         $this->automaticPriceDiscount $automaticPriceDiscount;
  382.     }
  383.     /**
  384.      * @return string
  385.      */
  386.     public function getEan(): ?string
  387.     {
  388.         return $this->ean;
  389.     }
  390.     /**
  391.      * @param string $ean
  392.      */
  393.     public function setEan($ean)
  394.     {
  395.         $this->ean $ean;
  396.     }
  397. }