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.

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