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.

MerchantModel.php 10KB

3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Product\ProductFamilyInterface", mappedBy="merchant")
  35. */
  36. protected $productFamilies;
  37. /**
  38. * @ORM\OneToOne(targetEntity="Lc\CaracoleBundle\Model\Address\AddressInterface", inversedBy="merchant", cascade={"persist", "remove"})
  39. * @ORM\JoinColumn(nullable=true)
  40. */
  41. protected $address;
  42. /**
  43. * @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Product\ProductCategoryInterface", mappedBy="merchant", orphanRemoval=true)
  44. */
  45. protected $productCategories;
  46. /**
  47. * @ORM\OneToMany(targetEntity="Lc\SovBundle\Model\Site\NewsInterface", mappedBy="merchant", orphanRemoval=true)
  48. */
  49. protected $news;
  50. /**
  51. * @ORM\OneToMany(targetEntity="Lc\SovBundle\Model\Site\PageInterface", mappedBy="merchant", orphanRemoval=true)
  52. */
  53. protected $pages;
  54. /**
  55. * @ORM\OneToMany(targetEntity="Lc\SovBundle\Model\Newsletter\NewsletterInterface", mappedBy="merchant")
  56. */
  57. protected $newsletters;
  58. /**
  59. * @ORM\OneToMany(targetEntity="Lc\SovBundle\Model\User\GroupUserInterface", mappedBy="merchant")
  60. */
  61. protected $groupUsers;
  62. /**
  63. * @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Setting\MerchantSettingInterface", mappedBy="merchant", orphanRemoval=true, cascade={"persist"}, fetch="EAGER")
  64. */
  65. protected $settings;
  66. public function __construct()
  67. {
  68. $this->pointSales = new ArrayCollection();
  69. $this->productFamilies = new ArrayCollection();
  70. $this->productCategories = new ArrayCollection();
  71. $this->news = new ArrayCollection();
  72. $this->groupUsers = new ArrayCollection();
  73. $this->newsletters = new ArrayCollection();
  74. }
  75. public function __toString()
  76. {
  77. return $this->getTitle() ;
  78. }
  79. public function getTaxRate(): ?TaxRateInterface
  80. {
  81. return $this->taxRate;
  82. }
  83. public function setTaxRate(?TaxRateInterface $taxRate): self
  84. {
  85. $this->taxRate = $taxRate;
  86. return $this;
  87. }
  88. /**
  89. * @return Collection|PointSaleInterface[]
  90. */
  91. public function getPointSales(): Collection
  92. {
  93. return $this->pointSales;
  94. }
  95. public function addPointSale(PointSaleInterface $pointSale): self
  96. {
  97. if (!$this->pointSales->contains($pointSale)) {
  98. $this->pointSales[] = $pointSale;
  99. $pointSale->addMerchant($this);
  100. }
  101. return $this;
  102. }
  103. public function removePointSale(PointSaleInterface $pointSale): self
  104. {
  105. if ($this->pointSales->contains($pointSale)) {
  106. $this->pointSales->removeElement($pointSale);
  107. $pointSale->removeMerchant($this);
  108. }
  109. return $this;
  110. }
  111. /**
  112. * @return Collection|ProductFamilyInterface[]
  113. */
  114. public function getProductFamilies(): Collection
  115. {
  116. return $this->productFamilies;
  117. }
  118. public function addProductFamily(ProductFamilyInterface $productFamily): self
  119. {
  120. if (!$this->productFamilies->contains($productFamily)) {
  121. $this->productFamilies[] = $productFamily;
  122. $productFamily->setMerchant($this);
  123. }
  124. return $this;
  125. }
  126. public function removeProductFamily(ProductFamilyInterface $productFamily): self
  127. {
  128. if ($this->productFamilies->contains($productFamily)) {
  129. $this->productFamilies->removeElement($productFamily);
  130. // set the owning side to null (unless already changed)
  131. if ($productFamily->getMerchant() === $this) {
  132. $productFamily->setMerchant(null);
  133. }
  134. }
  135. return $this;
  136. }
  137. /**
  138. * @return Collection|MerchantSettingInterface[]
  139. */
  140. public function getSettings(): Collection
  141. {
  142. return $this->settings;
  143. }
  144. public function addSetting(MerchantSettingInterface $merchantSetting): self
  145. {
  146. if (!$this->settings->contains($merchantSetting)) {
  147. $this->settings[] = $merchantSetting;
  148. $merchantSetting->setMerchant($this);
  149. }
  150. return $this;
  151. }
  152. public function removeSetting(MerchantSettingInterface $merchantSetting): self
  153. {
  154. if ($this->settings->contains($merchantSetting)) {
  155. $this->settings->removeElement($merchantSetting);
  156. // set the owning side to null (unless already changed)
  157. if ($merchantSetting->getMerchant() === $this) {
  158. $merchantSetting->setMerchant(null);
  159. }
  160. }
  161. return $this;
  162. }
  163. public function getAddress(): ?AddressInterface
  164. {
  165. return $this->address;
  166. }
  167. public function setAddress(AddressInterface $address): self
  168. {
  169. $this->address = $address;
  170. return $this;
  171. }
  172. /**
  173. * @return Collection|ProductCategoryInterface[]
  174. */
  175. public function getProductCategories(): Collection
  176. {
  177. return $this->productCategories;
  178. }
  179. public function addProductCategory(ProductCategoryInterface $productCategory): self
  180. {
  181. if (!$this->productCategories->contains($productCategory)) {
  182. $this->productCategories[] = $productCategory;
  183. $productCategory->setMerchant($this);
  184. }
  185. return $this;
  186. }
  187. public function removeProductCategory(ProductCategoryInterface $productCategory): self
  188. {
  189. if ($this->productCategories->contains($productCategory)) {
  190. $this->productCategories->removeElement($productCategory);
  191. // set the owning side to null (unless already changed)
  192. if ($productCategory->getMerchant() === $this) {
  193. $productCategory->setMerchant(null);
  194. }
  195. }
  196. return $this;
  197. }
  198. /**
  199. * @return Collection|NewsInterface[]
  200. */
  201. public function getNews(): Collection
  202. {
  203. return $this->news;
  204. }
  205. public function addNews(NewsInterface $news): self
  206. {
  207. if (!$this->news->contains($news)) {
  208. $this->news[] = $news;
  209. $news->setMerchant($this);
  210. }
  211. return $this;
  212. }
  213. public function removeNews(NewsInterface $news): self
  214. {
  215. if ($this->news->contains($news)) {
  216. $this->news->removeElement($news);
  217. // set the owning side to null (unless already changed)
  218. if ($news->getMerchant() === $this) {
  219. $news->setMerchant(null);
  220. }
  221. }
  222. return $this;
  223. }
  224. /**
  225. * @return Collection|PageInterface[]
  226. */
  227. public function getPages(): Collection
  228. {
  229. return $this->pages;
  230. }
  231. public function addPage(PageInterface $page): self
  232. {
  233. if (!$this->pages->contains($page)) {
  234. $this->pages[] = $page;
  235. $page->setMerchant($this);
  236. }
  237. return $this;
  238. }
  239. public function removePage(PageInterface $page): self
  240. {
  241. if ($this->pages->contains($page)) {
  242. $this->pages->removeElement($page);
  243. // set the owning side to null (unless already changed)
  244. if ($page->getMerchant() === $this) {
  245. $page->setMerchant(null);
  246. }
  247. }
  248. return $this;
  249. }
  250. /**
  251. * @return Collection|NewsletterInterface[]
  252. */
  253. public function getNewsletters(): Collection
  254. {
  255. return $this->newsletters;
  256. }
  257. public function addNewsletter(NewsletterInterface $newsletter): self
  258. {
  259. if (!$this->newsletters->contains($newsletter)) {
  260. $this->newsletters[] = $newsletter;
  261. $newsletter->setMerchant($this);
  262. }
  263. return $this;
  264. }
  265. public function removeNewsletter(NewsletterInterface $newsletter): self
  266. {
  267. if ($this->newsletters->contains($newsletter)) {
  268. $this->newsletters->removeElement($newsletter);
  269. // set the owning side to null (unless already changed)
  270. if ($newsletter->getMerchant() === $this) {
  271. $newsletter->setMerchant(null);
  272. }
  273. }
  274. return $this;
  275. }
  276. public function getNewsletter()
  277. {
  278. $newsletters = $this->getNewsletters();
  279. foreach ($newsletters as $newsletter) {
  280. if ($newsletter->getIsMain()) {
  281. return $newsletter;
  282. }
  283. }
  284. return false;
  285. }
  286. /**
  287. * @return Collection|GroupUserInterface[]
  288. */
  289. public function getGroupUsers(): Collection
  290. {
  291. return $this->groupUsers;
  292. }
  293. public function addGroupUser(GroupUserInterface $groupUser): self
  294. {
  295. if (!$this->groupUsers->contains($groupUser)) {
  296. $this->groupUsers[] = $groupUser;
  297. $groupUser->setMerchant($this);
  298. }
  299. return $this;
  300. }
  301. public function removeGroupUser(GroupUserInterface $groupUser): self
  302. {
  303. if ($this->groupUsers->contains($groupUser)) {
  304. $this->groupUsers->removeElement($groupUser);
  305. // set the owning side to null (unless already changed)
  306. if ($groupUser->getMerchant() === $this) {
  307. $groupUser->setMerchant(null);
  308. }
  309. }
  310. return $this;
  311. }
  312. }