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.

398 lines
11KB

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