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.

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