Merchant.php 11KB

hace 4 años
hace 4 años
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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\NewsletterInterface", mappedBy="merchant")
  50. */
  51. protected $newsletters;
  52. /**
  53. * @ORM\OneToMany(targetEntity="App\Entity\GroupUser", mappedBy="merchant")
  54. */
  55. protected $groupUsers;
  56. public function __construct()
  57. {
  58. $this->pointSales = new ArrayCollection();
  59. $this->productFamilies = new ArrayCollection();
  60. $this->merchantConfigs = new ArrayCollection();
  61. $this->productCategories = new ArrayCollection();
  62. $this->news = new ArrayCollection();
  63. $this->groupUsers = new ArrayCollection();
  64. $this->newsletters = new ArrayCollection();
  65. }
  66. public function getCreditConfig(): ?CreditConfig
  67. {
  68. return $this->creditConfig;
  69. }
  70. public function setCreditConfig(CreditConfigInterface $creditConfig): self
  71. {
  72. $this->creditConfig = $creditConfig;
  73. return $this;
  74. }
  75. public function getTaxRate(): ?TaxRate
  76. {
  77. return $this->taxRate;
  78. }
  79. public function setTaxRate(?TaxRate $taxRate): self
  80. {
  81. $this->taxRate = $taxRate;
  82. return $this;
  83. }
  84. /**
  85. * @return Collection|PointSale[]
  86. */
  87. public function getPointSales(): Collection
  88. {
  89. return $this->pointSales;
  90. }
  91. public function addPointSale(PointSale $pointSale): self
  92. {
  93. if (!$this->pointSales->contains($pointSale)) {
  94. $this->pointSales[] = $pointSale;
  95. $pointSale->addMerchant($this);
  96. }
  97. return $this;
  98. }
  99. public function removePointSale(PointSale $pointSale): self
  100. {
  101. if ($this->pointSales->contains($pointSale)) {
  102. $this->pointSales->removeElement($pointSale);
  103. $pointSale->removeMerchant($this);
  104. }
  105. return $this;
  106. }
  107. /**
  108. * @return Collection|ProductFamily[]
  109. */
  110. public function getProductFamilies(): Collection
  111. {
  112. return $this->productFamilies;
  113. }
  114. public function addProductFamily(ProductFamily $productFamily): self
  115. {
  116. if (!$this->productFamilies->contains($productFamily)) {
  117. $this->productFamilies[] = $productFamily;
  118. $productFamily->setMerchant($this);
  119. }
  120. return $this;
  121. }
  122. public function removeProductFamily(ProductFamily $productFamily): self
  123. {
  124. if ($this->productFamilies->contains($productFamily)) {
  125. $this->productFamilies->removeElement($productFamily);
  126. // set the owning side to null (unless already changed)
  127. if ($productFamily->getMerchant() === $this) {
  128. $productFamily->setMerchant(null);
  129. }
  130. }
  131. return $this;
  132. }
  133. /**
  134. * @return Collection|MerchantConfig[]
  135. */
  136. public function getMerchantConfigs(): Collection
  137. {
  138. return $this->merchantConfigs;
  139. }
  140. public function addMerchantConfig(MerchantConfig $merchantConfig): self
  141. {
  142. if (!$this->merchantConfigs->contains($merchantConfig)) {
  143. $this->merchantConfigs[] = $merchantConfig;
  144. $merchantConfig->setMerchant($this);
  145. }
  146. return $this;
  147. }
  148. public function removeMerchantConfig(MerchantConfig $merchantConfig): self
  149. {
  150. if ($this->merchantConfigs->contains($merchantConfig)) {
  151. $this->merchantConfigs->removeElement($merchantConfig);
  152. // set the owning side to null (unless already changed)
  153. if ($merchantConfig->getMerchant() === $this) {
  154. $merchantConfig->setMerchant(null);
  155. }
  156. }
  157. return $this;
  158. }
  159. public function getMerchantConfig($name)
  160. {
  161. if($this->getMerchantConfigs()) {
  162. foreach($this->getMerchantConfigs() as $merchantConfig) {
  163. if($merchantConfig->getName() == $name) {
  164. return $merchantConfig->getValue() ;
  165. }
  166. }
  167. }
  168. return false ;
  169. }
  170. public function getAddress(): ?Address
  171. {
  172. return $this->address;
  173. }
  174. public function setAddress(Address $address): self
  175. {
  176. $this->address = $address;
  177. return $this;
  178. }
  179. /**
  180. * @return Collection|ProductCategory[]
  181. */
  182. public function getProductCategories(): Collection
  183. {
  184. return $this->productCategories;
  185. }
  186. public function addProductCategory(ProductCategory $productCategory): self
  187. {
  188. if (!$this->productCategories->contains($productCategory)) {
  189. $this->productCategories[] = $productCategory;
  190. $productCategory->setMerchant($this);
  191. }
  192. return $this;
  193. }
  194. public function removeProductCategory(ProductCategory $productCategory): self
  195. {
  196. if ($this->productCategories->contains($productCategory)) {
  197. $this->productCategories->removeElement($productCategory);
  198. // set the owning side to null (unless already changed)
  199. if ($productCategory->getMerchant() === $this) {
  200. $productCategory->setMerchant(null);
  201. }
  202. }
  203. return $this;
  204. }
  205. /**
  206. * @return Collection|News[]
  207. */
  208. public function getNews(): Collection
  209. {
  210. return $this->news;
  211. }
  212. public function addNews(News $news): self
  213. {
  214. if (!$this->news->contains($news)) {
  215. $this->news[] = $news;
  216. $news->setMerchant($this);
  217. }
  218. return $this;
  219. }
  220. public function removeNews(News $news): self
  221. {
  222. if ($this->news->contains($news)) {
  223. $this->news->removeElement($news);
  224. // set the owning side to null (unless already changed)
  225. if ($news->getMerchant() === $this) {
  226. $news->setMerchant(null);
  227. }
  228. }
  229. return $this;
  230. }
  231. /**
  232. * @return Collection|Newsletter[]
  233. */
  234. public function getNewsletters(): Collection
  235. {
  236. return $this->newsletters;
  237. }
  238. public function addNewsletter(Newsletter $newsletter): self
  239. {
  240. if (!$this->newsletters->contains($newsletter)) {
  241. $this->newsletters[] = $newsletter;
  242. $newsletter->setMerchant($this);
  243. }
  244. return $this;
  245. }
  246. public function removeNewsletter(News $newsletter): self
  247. {
  248. if ($this->newsletters->contains($newsletter)) {
  249. $this->newsletters->removeElement($newsletter);
  250. // set the owning side to null (unless already changed)
  251. if ($newsletter->getMerchant() === $this) {
  252. $newsletter->setMerchant(null);
  253. }
  254. }
  255. return $this;
  256. }
  257. public function getNewsletter()
  258. {
  259. $newsletters = $this->getNewsletters() ;
  260. if(isset($newsletters[0])) {
  261. return $newsletters[0] ;
  262. }
  263. return false ;
  264. }
  265. /**
  266. * @return Collection|GroupUser[]
  267. */
  268. public function getGroupUsers(): Collection
  269. {
  270. return $this->groupUsers;
  271. }
  272. public function addGroupUser(GroupUser $groupUser): self
  273. {
  274. if (!$this->groupUsers->contains($groupUser)) {
  275. $this->groupUsers[] = $groupUser;
  276. $groupUser->setMerchant($this);
  277. }
  278. return $this;
  279. }
  280. public function removeGroupUser(GroupUser $groupUser): self
  281. {
  282. if ($this->groupUsers->contains($groupUser)) {
  283. $this->groupUsers->removeElement($groupUser);
  284. // set the owning side to null (unless already changed)
  285. if ($groupUser->getMerchant() === $this) {
  286. $groupUser->setMerchant(null);
  287. }
  288. }
  289. return $this;
  290. }
  291. }