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.

407 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\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\Config\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\Site\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\GroupUserInterface", 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 __toString()
  80. {
  81. return $this->getTitle() ;
  82. }
  83. public function getCreditConfig(): ?CreditConfigInterface
  84. {
  85. return $this->creditConfig;
  86. }
  87. public function setCreditConfig(CreditConfigInterface $creditConfig): self
  88. {
  89. $this->creditConfig = $creditConfig;
  90. return $this;
  91. }
  92. public function getTaxRate(): ?TaxRateInterface
  93. {
  94. return $this->taxRate;
  95. }
  96. public function setTaxRate(?TaxRateInterface $taxRate): self
  97. {
  98. $this->taxRate = $taxRate;
  99. return $this;
  100. }
  101. /**
  102. * @return Collection|PointSaleInterface[]
  103. */
  104. public function getPointSales(): Collection
  105. {
  106. return $this->pointSales;
  107. }
  108. public function addPointSale(PointSaleInterface $pointSale): self
  109. {
  110. if (!$this->pointSales->contains($pointSale)) {
  111. $this->pointSales[] = $pointSale;
  112. $pointSale->addMerchant($this);
  113. }
  114. return $this;
  115. }
  116. public function removePointSale(PointSaleInterface $pointSale): self
  117. {
  118. if ($this->pointSales->contains($pointSale)) {
  119. $this->pointSales->removeElement($pointSale);
  120. $pointSale->removeMerchant($this);
  121. }
  122. return $this;
  123. }
  124. /**
  125. * @return Collection|ProductFamilyInterface[]
  126. */
  127. public function getProductFamilies(): Collection
  128. {
  129. return $this->productFamilies;
  130. }
  131. public function addProductFamily(ProductFamilyInterface $productFamily): self
  132. {
  133. if (!$this->productFamilies->contains($productFamily)) {
  134. $this->productFamilies[] = $productFamily;
  135. $productFamily->setMerchant($this);
  136. }
  137. return $this;
  138. }
  139. public function removeProductFamily(ProductFamilyInterface $productFamily): self
  140. {
  141. if ($this->productFamilies->contains($productFamily)) {
  142. $this->productFamilies->removeElement($productFamily);
  143. // set the owning side to null (unless already changed)
  144. if ($productFamily->getMerchant() === $this) {
  145. $productFamily->setMerchant(null);
  146. }
  147. }
  148. return $this;
  149. }
  150. /**
  151. * @return Collection|MerchantConfigInterface[]
  152. */
  153. public function getMerchantConfigs(): Collection
  154. {
  155. return $this->merchantConfigs;
  156. }
  157. public function addMerchantConfig(MerchantConfigInterface $merchantConfig): self
  158. {
  159. if (!$this->merchantConfigs->contains($merchantConfig)) {
  160. $this->merchantConfigs[] = $merchantConfig;
  161. $merchantConfig->setMerchant($this);
  162. }
  163. return $this;
  164. }
  165. public function removeMerchantConfig(MerchantConfigInterface $merchantConfig): self
  166. {
  167. if ($this->merchantConfigs->contains($merchantConfig)) {
  168. $this->merchantConfigs->removeElement($merchantConfig);
  169. // set the owning side to null (unless already changed)
  170. if ($merchantConfig->getMerchant() === $this) {
  171. $merchantConfig->setMerchant(null);
  172. }
  173. }
  174. return $this;
  175. }
  176. public function getMerchantConfig($name)
  177. {
  178. if ($this->getMerchantConfigs()) {
  179. foreach ($this->getMerchantConfigs() as $merchantConfig) {
  180. if ($merchantConfig->getName() == $name) {
  181. return $merchantConfig->getValue();
  182. }
  183. }
  184. }
  185. return false;
  186. }
  187. public function getAddress(): ?AddressInterface
  188. {
  189. return $this->address;
  190. }
  191. public function setAddress(AddressInterface $address): self
  192. {
  193. $this->address = $address;
  194. return $this;
  195. }
  196. /**
  197. * @return Collection|ProductCategoryInterface[]
  198. */
  199. public function getProductCategories(): Collection
  200. {
  201. return $this->productCategories;
  202. }
  203. public function addProductCategory(ProductCategoryInterface $productCategory): self
  204. {
  205. if (!$this->productCategories->contains($productCategory)) {
  206. $this->productCategories[] = $productCategory;
  207. $productCategory->setMerchant($this);
  208. }
  209. return $this;
  210. }
  211. public function removeProductCategory(ProductCategoryInterface $productCategory): self
  212. {
  213. if ($this->productCategories->contains($productCategory)) {
  214. $this->productCategories->removeElement($productCategory);
  215. // set the owning side to null (unless already changed)
  216. if ($productCategory->getMerchant() === $this) {
  217. $productCategory->setMerchant(null);
  218. }
  219. }
  220. return $this;
  221. }
  222. /**
  223. * @return Collection|NewsInterface[]
  224. */
  225. public function getNews(): Collection
  226. {
  227. return $this->news;
  228. }
  229. public function addNews(NewsInterface $news): self
  230. {
  231. if (!$this->news->contains($news)) {
  232. $this->news[] = $news;
  233. $news->setMerchant($this);
  234. }
  235. return $this;
  236. }
  237. public function removeNews(NewsInterface $news): self
  238. {
  239. if ($this->news->contains($news)) {
  240. $this->news->removeElement($news);
  241. // set the owning side to null (unless already changed)
  242. if ($news->getMerchant() === $this) {
  243. $news->setMerchant(null);
  244. }
  245. }
  246. return $this;
  247. }
  248. /**
  249. * @return Collection|PageInterface[]
  250. */
  251. public function getPages(): Collection
  252. {
  253. return $this->pages;
  254. }
  255. public function addPage(PageInterface $page): self
  256. {
  257. if (!$this->pages->contains($page)) {
  258. $this->pages[] = $page;
  259. $page->setMerchant($this);
  260. }
  261. return $this;
  262. }
  263. public function removePage(PageInterface $page): self
  264. {
  265. if ($this->pages->contains($page)) {
  266. $this->pages->removeElement($page);
  267. // set the owning side to null (unless already changed)
  268. if ($page->getMerchant() === $this) {
  269. $page->setMerchant(null);
  270. }
  271. }
  272. return $this;
  273. }
  274. /**
  275. * @return Collection|NewsletterInterface[]
  276. */
  277. public function getNewsletters(): Collection
  278. {
  279. return $this->newsletters;
  280. }
  281. public function addNewsletter(NewsletterInterface $newsletter): self
  282. {
  283. if (!$this->newsletters->contains($newsletter)) {
  284. $this->newsletters[] = $newsletter;
  285. $newsletter->setMerchant($this);
  286. }
  287. return $this;
  288. }
  289. public function removeNewsletter(NewsletterInterface $newsletter): self
  290. {
  291. if ($this->newsletters->contains($newsletter)) {
  292. $this->newsletters->removeElement($newsletter);
  293. // set the owning side to null (unless already changed)
  294. if ($newsletter->getMerchant() === $this) {
  295. $newsletter->setMerchant(null);
  296. }
  297. }
  298. return $this;
  299. }
  300. public function getNewsletter()
  301. {
  302. $newsletters = $this->getNewsletters();
  303. foreach ($newsletters as $newsletter) {
  304. if ($newsletter->getIsMain()) {
  305. return $newsletter;
  306. }
  307. }
  308. return false;
  309. }
  310. /**
  311. * @return Collection|GroupUserInterface[]
  312. */
  313. public function getGroupUsers(): Collection
  314. {
  315. return $this->groupUsers;
  316. }
  317. public function addGroupUser(GroupUserInterface $groupUser): self
  318. {
  319. if (!$this->groupUsers->contains($groupUser)) {
  320. $this->groupUsers[] = $groupUser;
  321. $groupUser->setMerchant($this);
  322. }
  323. return $this;
  324. }
  325. public function removeGroupUser(GroupUserInterface $groupUser): self
  326. {
  327. if ($this->groupUsers->contains($groupUser)) {
  328. $this->groupUsers->removeElement($groupUser);
  329. // set the owning side to null (unless already changed)
  330. if ($groupUser->getMerchant() === $this) {
  331. $groupUser->setMerchant(null);
  332. }
  333. }
  334. return $this;
  335. }
  336. }