<?php
namespace App\Entity\Gos;
use App\Entity\Gos\Uniqskills\Course;
use App\Entity\Gos\Uniqskills\OrderCycle;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* OrderProduct
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="App\Repository\OrderProductVariantRepository")
* @ORM\HasLifecycleCallbacks
*/
class OrderProductVariant
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(type="string", length=255)
*/
private $title;
/**
* @var string
*
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $productVariantNoComplete;
/**
* @var int
*
* @ORM\Column(name="quantity", type="integer")
*/
private $quantity;
/**
* @var float
*
* @ORM\Column(type="float", precision=18, scale=2)
*/
private $priceNet;
/**
* @var float
*
* @ORM\Column(type="float", precision=18, scale=2)
*/
private $priceGross;
/**
* @var float
*
* @ORM\Column(type="float", precision=18, scale=2)
*/
private $priceBeforeCouponNet;
/**
* @var float
*
* @ORM\Column(type="float", precision=18, scale=2)
*/
private $priceBeforeCouponGross;
/**
* @var bool
*
* @ORM\Column(type="boolean", nullable=true)
*/
private $isGross;
/**
* @var bool
*
* @ORM\Column(type="boolean", nullable=true)
*/
private $isFreeAccess;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $freeAccessEndAt;
/**
* @var int
*
* @ORM\Column(type="integer", options={"default" : 1})
*/
private $maxUsers;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Gos\PaymentMethod", inversedBy="orderProductVariant")
* @ORM\JoinColumn()
*/
private $paymentMethod;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Gos\OrderPart", inversedBy="orderProductVariant")
* @ORM\JoinColumn()
*/
private $orderPart;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Gos\OrderCoupon", mappedBy="orderProductVariant")
*/
private $orderCoupon;
/**
* @ORM\ManyToOne(targetEntity="OrderProductVariantType", inversedBy="orderProductVariant")
* @ORM\JoinColumn()
*/
private $orderProductVariantType;
/**
* @ORM\OneToMany(targetEntity="OrderProductVariantUser", mappedBy="orderProductVariant", cascade={"persist"})
*/
private $orderProductVariantUser;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Gos\UpdateProductVariantHistory", mappedBy="orderProductVariant")
*/
private $updateProductVariantHistory;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Gos\ProductVariant", inversedBy="orderProductVariant")
* @ORM\JoinColumn()
*/
private $productVariant;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Gos\OrderProductVariant", mappedBy="primaryVariant")
*/
private $additionalVariant;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Gos\OrderProductVariant", inversedBy="additionalVariant")
* @ORM\JoinColumn(name="primary_variant_id", referencedColumnName="id")
*/
private $primaryVariant;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Gos\ProductPackItem", inversedBy="orderProductVariant")
* @ORM\JoinColumn()
*/
private $productPackItem;
/**
* @ORM\OneToOne(targetEntity="Gift", mappedBy="orderProductVariant")
*/
private $gift;
/**
* @ORM\Column(type="datetime")
*/
private $createdAt;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $updatedAt;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Gos\Uniqskills\OrderCycle", inversedBy="orderProductVariants")
*/
private $cycle;
/**
* @ORM\Column(type="boolean", nullable=true, options={"default": 0})
*/
private $isReminderSend;
/**
* @ORM\Column(type="boolean", nullable=true, options={"default": 0})
*/
private $isUserDone;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $showDate;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $reminderStartDate;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $upsellingType;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $omittedShippingCosts;
/**
* @ORM\ManyToOne(targetEntity=Course::class)
*/
private $course;
/**
* @ORM\OneToMany(targetEntity=OrderProductVariantOmittedUpsell::class, mappedBy="orderProductVariant", orphanRemoval=true)
*/
private $orderProductVariantOmittedUpsells;
/**
* @ORM\OneToMany(targetEntity=EventNotificationScheduler::class, mappedBy="orderProductVariant", orphanRemoval=true, cascade={"remove"})
*/
private $eventNotificationSchedulers;
/**
* @ORM\OneToMany(targetEntity=FailureEventNotifications::class, mappedBy="orderProductVariant", orphanRemoval=true, cascade={"remove"})
*/
private $failureEventNotifications;
/**
* @ORM\OneToMany(targetEntity=SentEventNotifications::class, mappedBy="orderProductVariant", orphanRemoval=true, cascade={"remove"})
*/
private $sentEventNotifications;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $productDuplicationMessageDisplayed;
/** @ORM\PrePersist() */
public function prePersist()
{
$this->createdAt = new \DateTime();
}
/** @ORM\PreUpdate() */
public function preUpdate()
{
$this->updatedAt = new \DateTime();
}
public function __toString()
{
return (string)$this->title;
}
public function checkIfProductVariantHavePaymentMethod(string $paymentMethodSlug): bool
{
$additionalOptionsByClientType = $this->getAdditionalOptionsByClientType();
if ($additionalOptionsByClientType)
{
foreach ($additionalOptionsByClientType->getPaymentMethod() as $paymentMethod)
{
if ($paymentMethod->getSlug() === $paymentMethodSlug)
{
return true;
}
}
}
return false;
}
public function checkIfProductVariantHaveToBeHiddenInSB(): bool
{
$additionalOptionsByClientType = $this->getAdditionalOptionsByClientType();
if ($additionalOptionsByClientType && $additionalOptionsByClientType->getHiddenInSBTillPaid() === true)
{
return true;
}
return false;
}
public function getAdditionalOptionsByClientType(): ?AdditionalOptionsByClientType
{
return $this->getProductVariant()->getAdditionalOptionsByClientType($this->getClientTypeByOrder());
}
private function getClientTypeByOrder(): ?ClientType
{
$order = $this->getOrderPart()->getOrders();
return $order->getAddress() ? $order->getAddress()->getClientType() : null;
}
/**
* Set orderPart
*
* @param OrderPart $orderPart
*
* @return OrderProductVariant
*/
public function setOrderPart(OrderPart $orderPart = null)
{
$this->orderPart = $orderPart;
if (!empty($orderPart))
{
$orderPart->setOrderProductVariant($this);
}
return $this;
}
//------------------------------ setters & getters
/**
* Constructor
*/
public function __construct()
{
$this->orderCoupon = new ArrayCollection();
$this->orderProductVariantUser = new ArrayCollection();
$this->updateProductVariantHistory = new ArrayCollection();
$this->additionalVariant = new ArrayCollection();
$this->orderProductVariantOmittedUpsells = new ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set title
*
* @param string $title
*
* @return OrderProductVariant
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set productVariantNoComplete
*
* @param string $productVariantNoComplete
*
* @return OrderProductVariant
*/
public function setProductVariantNoComplete($productVariantNoComplete)
{
$this->productVariantNoComplete = $productVariantNoComplete;
return $this;
}
/**
* Get productVariantNoComplete
*
* @return string
*/
public function getProductVariantNoComplete()
{
return $this->productVariantNoComplete;
}
/**
* Set quantity
*
* @param integer $quantity
*
* @return OrderProductVariant
*/
public function setQuantity($quantity)
{
$this->quantity = $quantity;
return $this;
}
/**
* Get quantity
*
* @return integer
*/
public function getQuantity()
{
return $this->quantity;
}
/**
* Set priceNet
*
* @param float $priceNet
*
* @return OrderProductVariant
*/
public function setPriceNet($priceNet)
{
$this->priceNet = $priceNet;
return $this;
}
/**
* Get priceNet
*
* @return float
*/
public function getPriceNet()
{
return $this->priceNet;
}
/**
* Set priceGross
*
* @param float $priceGross
*
* @return OrderProductVariant
*/
public function setPriceGross($priceGross)
{
$this->priceGross = $priceGross;
return $this;
}
/**
* Get priceGross
*
* @return float
*/
public function getPriceGross()
{
return $this->priceGross;
}
/**
* Set priceBeforeCouponNet
*
* @param float $priceBeforeCouponNet
*
* @return OrderProductVariant
*/
public function setPriceBeforeCouponNet($priceBeforeCouponNet)
{
$this->priceBeforeCouponNet = $priceBeforeCouponNet;
return $this;
}
/**
* Get priceBeforeCouponNet
*
* @return float
*/
public function getPriceBeforeCouponNet()
{
return $this->priceBeforeCouponNet;
}
/**
* Set priceBeforeCouponGross
*
* @param float $priceBeforeCouponGross
*
* @return OrderProductVariant
*/
public function setPriceBeforeCouponGross($priceBeforeCouponGross)
{
$this->priceBeforeCouponGross = $priceBeforeCouponGross;
return $this;
}
/**
* Get priceBeforeCouponGross
*
* @return float
*/
public function getPriceBeforeCouponGross()
{
return $this->priceBeforeCouponGross;
}
/**
* Set isGross
*
* @param boolean $isGross
*
* @return OrderProductVariant
*/
public function setIsGross($isGross)
{
$this->isGross = $isGross;
return $this;
}
/**
* Get isGross
*
* @return boolean
*/
public function getIsGross()
{
return $this->isGross;
}
/**
* Set createdAt
*
* @param \DateTime $createdAt
*
* @return OrderProductVariant
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
/**
* Get createdAt
*
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* Set updatedAt
*
* @param \DateTime $updatedAt
*
* @return OrderProductVariant
*/
public function setUpdatedAt($updatedAt)
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* Get updatedAt
*
* @return \DateTime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* Set paymentMethod
*
* @param PaymentMethod $paymentMethod
*
* @return OrderProductVariant
*/
public function setPaymentMethod(PaymentMethod $paymentMethod = null)
{
$this->paymentMethod = $paymentMethod;
return $this;
}
/**
* Get paymentMethod
*
* @return PaymentMethod
*/
public function getPaymentMethod()
{
return $this->paymentMethod;
}
/**
* Get orderPart
*
* @return OrderPart
*/
public function getOrderPart()
{
return $this->orderPart;
}
/**
* Add orderCoupon
*
* @param OrderCoupon $orderCoupon
*
* @return OrderProductVariant
*/
public function addOrderCoupon(OrderCoupon $orderCoupon)
{
$this->orderCoupon[] = $orderCoupon;
return $this;
}
/**
* Remove orderCoupon
*
* @param OrderCoupon $orderCoupon
*/
public function removeOrderCoupon(OrderCoupon $orderCoupon)
{
$this->orderCoupon->removeElement($orderCoupon);
}
/**
* Get orderCoupon
*
* @return Collection
*/
public function getOrderCoupon()
{
return $this->orderCoupon;
}
/**
* Set orderProductVariantType
*
* @param OrderProductVariantType $orderProductVariantType
*
* @return OrderProductVariant
*/
public function setOrderProductVariantType(
OrderProductVariantType $orderProductVariantType = null
) {
$this->orderProductVariantType = $orderProductVariantType;
return $this;
}
/**
* Get orderProductVariantType
*
* @return OrderProductVariantType
*/
public function getOrderProductVariantType()
{
return $this->orderProductVariantType;
}
/**
* Add orderProductVariantUser
*
* @param OrderProductVariantUser $orderProductVariantUser
*
* @return OrderProductVariant
*/
public function addOrderProductVariantUser(OrderProductVariantUser $orderProductVariantUser)
{
$this->orderProductVariantUser[] = $orderProductVariantUser;
return $this;
}
/**
* Remove orderProductVariantUser
*
* @param OrderProductVariantUser $orderProductVariantUser
*/
public function removeOrderProductVariantUser(
OrderProductVariantUser $orderProductVariantUser
) {
$this->orderProductVariantUser->removeElement($orderProductVariantUser);
}
/**
* Get orderProductVariantUser
*
* @return Collection
*/
public function getOrderProductVariantUser()
{
return $this->orderProductVariantUser;
}
public function isUserAdmin(User $user): bool
{
/** @var OrderProductVariantUser $opvu */
foreach ($this->orderProductVariantUser as $opvu)
{
if ($opvu->getUser() === $user)
{
if ($opvu->getRoles() === 'ADMIN')
{
return true;
}
}
}
return false;
}
/**
* Set maxUsers
*
* @param integer $maxUsers
*
* @return OrderProductVariant
*/
public function setMaxUsers($maxUsers)
{
$this->maxUsers = $maxUsers;
return $this;
}
/**
* Get maxUsers
*
* @return integer
*/
public function getMaxUsers()
{
return $this->maxUsers;
}
/**
* Set isFreeAccess
*
* @param boolean $isFreeAccess
*
* @return OrderProductVariant
*/
public function setIsFreeAccess($isFreeAccess)
{
$this->isFreeAccess = $isFreeAccess;
return $this;
}
/**
* Get isFreeAccess
*
* @return boolean
*/
public function getIsFreeAccess()
{
return $this->isFreeAccess;
}
/**
* Set freeAccessEndAt
*
* @param \DateTime $freeAccessEndAt
*
* @return OrderProductVariant
*/
public function setFreeAccessEndAt($freeAccessEndAt)
{
$this->freeAccessEndAt = $freeAccessEndAt;
return $this;
}
/**
* Get freeAccessEndAt
*
* @return \DateTime
*/
public function getFreeAccessEndAt()
{
return $this->freeAccessEndAt;
}
/**
* Add updateProductVariantHistory
*
* @param UpdateProductVariantHistory $updateProductVariantHistory
*
* @return OrderProductVariant
*/
public function addUpdateProductVariantHistory(
UpdateProductVariantHistory $updateProductVariantHistory
) {
$this->updateProductVariantHistory[] = $updateProductVariantHistory;
return $this;
}
/**
* Remove updateProductVariantHistory
*
* @param UpdateProductVariantHistory $updateProductVariantHistory
*/
public function removeUpdateProductVariantHistory(
UpdateProductVariantHistory $updateProductVariantHistory
) {
$this->updateProductVariantHistory->removeElement($updateProductVariantHistory);
}
/**
* Get updateProductVariantHistory
*
* @return Collection
*/
public function getUpdateProductVariantHistory()
{
return $this->updateProductVariantHistory;
}
/**
* Set productVariant
*
* @param ProductVariant $productVariant
*
* @return OrderProductVariant
*/
public function setProductVariant(ProductVariant $productVariant = null)
{
$this->productVariant = $productVariant;
return $this;
}
/**
* Get productVariant
*
* @return ProductVariant
*/
public function getProductVariant()
{
return $this->productVariant;
}
/**
* @return Collection|OrderProductVariant[]
*/
public function getAdditionalVariant(): Collection
{
return $this->additionalVariant;
}
public function addAdditionalVariant(OrderProductVariant $additionalVariant): self
{
if (!$this->additionalVariant->contains($additionalVariant))
{
$this->additionalVariant[] = $additionalVariant;
$additionalVariant->setPrimaryVariant($this);
}
return $this;
}
public function removeAdditionalVariant(OrderProductVariant $additionalVariant): self
{
if ($this->additionalVariant->contains($additionalVariant))
{
$this->additionalVariant->removeElement($additionalVariant);
// set the owning side to null (unless already changed)
if ($additionalVariant->getPrimaryVariant() === $this)
{
$additionalVariant->setPrimaryVariant(null);
}
}
return $this;
}
public function getPrimaryVariant(): ?self
{
return $this->primaryVariant;
}
public function setPrimaryVariant(?self $primaryVariant): self
{
$this->primaryVariant = $primaryVariant;
return $this;
}
public function getProductPackItem(): ?ProductPackItem
{
return $this->productPackItem;
}
public function setProductPackItem(?ProductPackItem $productPackItem): self
{
$this->productPackItem = $productPackItem;
return $this;
}
public function getGift(): ?Gift
{
return $this->gift;
}
public function setGift(?Gift $gift): self
{
$this->gift = $gift;
// set (or unset) the owning side of the relation if necessary
$newOrderProductVariant = $gift === null ? null : $this;
if ($newOrderProductVariant !== $gift->getOrderProductVariant()) {
$gift->setOrderProductVariant($newOrderProductVariant);
}
return $this;
}
public function getCycle(): ?OrderCycle
{
return $this->cycle;
}
public function setCycle(?OrderCycle $cycle): self
{
$this->cycle = $cycle;
return $this;
}
public function getIsReminderSend(): ?bool
{
return $this->isReminderSend;
}
public function setIsReminderSend(?bool $isReminderSend): self
{
$this->isReminderSend = $isReminderSend;
return $this;
}
public function getIsUserDone(): ?bool
{
return $this->isUserDone;
}
public function setIsUserDone(?bool $isUserDone): self
{
$this->isUserDone = $isUserDone;
return $this;
}
public function getShowDate(): ?\DateTimeInterface
{
return $this->showDate;
}
public function setShowDate(?\DateTimeInterface $showDate): self
{
$this->showDate = $showDate;
return $this;
}
public function getReminderStartDate(): ?\DateTimeInterface
{
return $this->reminderStartDate;
}
public function setReminderStartDate(?\DateTimeInterface $reminderStartDate): self
{
$this->reminderStartDate = $reminderStartDate;
return $this;
}
public function getUpsellingType(): ?int
{
return $this->upsellingType;
}
public function setUpsellingType(?int $upsellingType): self
{
$this->upsellingType = $upsellingType;
return $this;
}
public function getOmittedShippingCosts(): ?bool
{
return $this->omittedShippingCosts;
}
public function setOmittedShippingCosts(?bool $omittedShippingCosts): self
{
$this->omittedShippingCosts = $omittedShippingCosts;
return $this;
}
public function getCourse(): ?Course
{
return $this->course;
}
public function setCourse(?Course $course): self
{
$this->course = $course;
return $this;
}
/**
* @return Collection|OrderProductVariantOmittedUpsell[]
*/
public function getOrderProductVariantOmittedUpsells(): Collection
{
return $this->orderProductVariantOmittedUpsells;
}
public function addOrderProductVariantOmittedUpsell(OrderProductVariantOmittedUpsell $orderProductVariantOmittedUpsell): self
{
if (!$this->orderProductVariantOmittedUpsells->contains($orderProductVariantOmittedUpsell)) {
$this->orderProductVariantOmittedUpsells[] = $orderProductVariantOmittedUpsell;
$orderProductVariantOmittedUpsell->setOrderProductVariant($this);
}
return $this;
}
public function removeOrderProductVariantOmittedUpsell(OrderProductVariantOmittedUpsell $orderProductVariantOmittedUpsell): self
{
if ($this->orderProductVariantOmittedUpsells->contains($orderProductVariantOmittedUpsell)) {
$this->orderProductVariantOmittedUpsells->removeElement($orderProductVariantOmittedUpsell);
// set the owning side to null (unless already changed)
if ($orderProductVariantOmittedUpsell->getOrderProductVariant() === $this) {
$orderProductVariantOmittedUpsell->setOrderProductVariant(null);
}
}
return $this;
}
public function getProductDuplicationMessageDisplayed(): ?bool
{
return $this->productDuplicationMessageDisplayed;
}
public function setProductDuplicationMessageDisplayed(?bool $productDuplicationMessageDisplayed): self
{
$this->productDuplicationMessageDisplayed = $productDuplicationMessageDisplayed;
return $this;
}
}