You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

181 lines
4.9KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Model\Merchant;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Lc\CaracoleBundle\Model\Address\AddressInterface;
  7. use Lc\CaracoleBundle\Model\Config\TaxRateInterface;
  8. use Lc\SovBundle\Model\Newsletter\NewsletterInterface;
  9. use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface;
  10. use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface;
  11. use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
  12. use Lc\CaracoleBundle\Model\Setting\MerchantSettingInterface;
  13. use Lc\SovBundle\Model\Setting\EntitySettingTrait;
  14. use Lc\SovBundle\Model\Site\NewsInterface;
  15. use Lc\SovBundle\Model\Site\PageInterface;
  16. use Lc\SovBundle\Model\User\GroupUserInterface;
  17. use Lc\SovBundle\Doctrine\Pattern\AbstractFullEntity;
  18. /**
  19. * @ORM\MappedSuperclass()
  20. */
  21. abstract class MerchantModel extends AbstractFullEntity
  22. {
  23. use EntitySettingTrait;
  24. /**
  25. * @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Config\TaxRateInterface")
  26. * @ORM\JoinColumn(nullable=false)
  27. */
  28. protected $taxRate;
  29. /**
  30. * @ORM\ManyToMany(targetEntity="Lc\CaracoleBundle\Model\PointSale\PointSaleInterface", mappedBy="merchants")
  31. */
  32. protected $pointSales;
  33. /**
  34. * @ORM\OneToOne(targetEntity="Lc\CaracoleBundle\Model\Address\AddressInterface", inversedBy="merchant", cascade={"persist", "remove"})
  35. * @ORM\JoinColumn(nullable=true)
  36. */
  37. protected $address;
  38. /**
  39. * @ORM\OneToMany(targetEntity="Lc\SovBundle\Model\User\GroupUserInterface", mappedBy="merchant")
  40. */
  41. protected $groupUsers;
  42. /**
  43. * @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Setting\MerchantSettingInterface", mappedBy="merchant", orphanRemoval=true, cascade={"persist"}, fetch="EAGER")
  44. */
  45. protected $settings;
  46. public function __construct()
  47. {
  48. $this->pointSales = new ArrayCollection();
  49. $this->groupUsers = new ArrayCollection();
  50. }
  51. public function __toString()
  52. {
  53. return $this->getTitle() ;
  54. }
  55. public function getTaxRate(): ?TaxRateInterface
  56. {
  57. return $this->taxRate;
  58. }
  59. public function setTaxRate(?TaxRateInterface $taxRate): self
  60. {
  61. $this->taxRate = $taxRate;
  62. return $this;
  63. }
  64. /**
  65. * @return Collection|PointSaleInterface[]
  66. */
  67. public function getPointSales(): Collection
  68. {
  69. return $this->pointSales;
  70. }
  71. public function addPointSale(PointSaleInterface $pointSale): self
  72. {
  73. if (!$this->pointSales->contains($pointSale)) {
  74. $this->pointSales[] = $pointSale;
  75. $pointSale->addMerchant($this);
  76. }
  77. return $this;
  78. }
  79. public function removePointSale(PointSaleInterface $pointSale): self
  80. {
  81. if ($this->pointSales->contains($pointSale)) {
  82. $this->pointSales->removeElement($pointSale);
  83. $pointSale->removeMerchant($this);
  84. }
  85. return $this;
  86. }
  87. /**
  88. * @return Collection|MerchantSettingInterface[]
  89. */
  90. public function getSettings(): Collection
  91. {
  92. return $this->settings;
  93. }
  94. public function addSetting(MerchantSettingInterface $merchantSetting): self
  95. {
  96. if (!$this->settings->contains($merchantSetting)) {
  97. $this->settings[] = $merchantSetting;
  98. $merchantSetting->setMerchant($this);
  99. }
  100. return $this;
  101. }
  102. public function removeSetting(MerchantSettingInterface $merchantSetting): self
  103. {
  104. if ($this->settings->contains($merchantSetting)) {
  105. $this->settings->removeElement($merchantSetting);
  106. // set the owning side to null (unless already changed)
  107. if ($merchantSetting->getMerchant() === $this) {
  108. $merchantSetting->setMerchant(null);
  109. }
  110. }
  111. return $this;
  112. }
  113. public function getAddress(): ?AddressInterface
  114. {
  115. return $this->address;
  116. }
  117. public function setAddress(AddressInterface $address): self
  118. {
  119. $this->address = $address;
  120. return $this;
  121. }
  122. /**
  123. * @return Collection|GroupUserInterface[]
  124. */
  125. public function getGroupUsers(): Collection
  126. {
  127. return $this->groupUsers;
  128. }
  129. public function addGroupUser(GroupUserInterface $groupUser): self
  130. {
  131. if (!$this->groupUsers->contains($groupUser)) {
  132. $this->groupUsers[] = $groupUser;
  133. $groupUser->setMerchant($this);
  134. }
  135. return $this;
  136. }
  137. public function removeGroupUser(GroupUserInterface $groupUser): self
  138. {
  139. if ($this->groupUsers->contains($groupUser)) {
  140. $this->groupUsers->removeElement($groupUser);
  141. // set the owning side to null (unless already changed)
  142. if ($groupUser->getMerchant() === $this) {
  143. $groupUser->setMerchant(null);
  144. }
  145. }
  146. return $this;
  147. }
  148. }