Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

393 lines
12KB

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