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.

Merchant.php 9.8KB

4 yıl önce
4 yıl önce
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <?php
  2. namespace Lc\ShopBundle\Model;
  3. use App\Entity\News;
  4. use App\Entity\Newsletter;
  5. use App\Entity\ProductCategory;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. /**
  10. * @ORM\MappedSuperclass()
  11. */
  12. abstract class Merchant extends AbstractDocumentEntity
  13. {
  14. /**
  15. * @ORM\OneToOne(targetEntity="Lc\ShopBundle\Context\CreditConfigInterface", cascade={"persist", "remove"})
  16. * @ORM\JoinColumn(nullable=true)
  17. */
  18. protected $creditConfig;
  19. /**
  20. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\TaxRateInterface")
  21. * @ORM\JoinColumn(nullable=false)
  22. */
  23. protected $taxRate;
  24. /**
  25. * @ORM\ManyToMany(targetEntity="Lc\ShopBundle\Context\PointSaleInterface", mappedBy="merchants")
  26. */
  27. protected $pointSales;
  28. /**
  29. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\ProductFamilyInterface", mappedBy="merchant")
  30. */
  31. protected $productFamilies;
  32. /**
  33. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\MerchantConfigInterface", mappedBy="merchant", orphanRemoval=true, cascade={"persist"})
  34. */
  35. protected $merchantConfigs;
  36. /**
  37. * @ORM\OneToOne(targetEntity="Lc\ShopBundle\Context\AddressInterface", inversedBy="merchant", cascade={"persist", "remove"})
  38. * @ORM\JoinColumn(nullable=true)
  39. */
  40. protected $address;
  41. /**
  42. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\ProductCategoryInterface", mappedBy="merchant", orphanRemoval=true)
  43. */
  44. protected $productCategories;
  45. /**
  46. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\NewsInterface", mappedBy="merchant", orphanRemoval=true)
  47. */
  48. protected $news;
  49. /**
  50. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\NewsletterInterface", mappedBy="merchant")
  51. */
  52. protected $newsletters;
  53. public function __construct()
  54. {
  55. $this->pointSales = new ArrayCollection();
  56. $this->productFamilies = new ArrayCollection();
  57. $this->merchantConfigs = new ArrayCollection();
  58. $this->productCategories = new ArrayCollection();
  59. $this->news = new ArrayCollection();
  60. $this->newsletters = new ArrayCollection();
  61. }
  62. public function getCreditConfig(): ?CreditConfig
  63. {
  64. return $this->creditConfig;
  65. }
  66. public function setCreditConfig(CreditConfig $creditConfig): self
  67. {
  68. $this->creditConfig = $creditConfig;
  69. return $this;
  70. }
  71. public function getTaxRate(): ?TaxRate
  72. {
  73. return $this->taxRate;
  74. }
  75. public function setTaxRate(?TaxRate $taxRate): self
  76. {
  77. $this->taxRate = $taxRate;
  78. return $this;
  79. }
  80. /**
  81. * @return Collection|PointSale[]
  82. */
  83. public function getPointSales(): Collection
  84. {
  85. return $this->pointSales;
  86. }
  87. public function addPointSale(PointSale $pointSale): self
  88. {
  89. if (!$this->pointSales->contains($pointSale)) {
  90. $this->pointSales[] = $pointSale;
  91. $pointSale->addMerchant($this);
  92. }
  93. return $this;
  94. }
  95. public function removePointSale(PointSale $pointSale): self
  96. {
  97. if ($this->pointSales->contains($pointSale)) {
  98. $this->pointSales->removeElement($pointSale);
  99. $pointSale->removeMerchant($this);
  100. }
  101. return $this;
  102. }
  103. /**
  104. * @return Collection|ProductFamily[]
  105. */
  106. public function getProductFamilies(): Collection
  107. {
  108. return $this->productFamilies;
  109. }
  110. public function addProductFamily(ProductFamily $productFamily): self
  111. {
  112. if (!$this->productFamilies->contains($productFamily)) {
  113. $this->productFamilies[] = $productFamily;
  114. $productFamily->setMerchant($this);
  115. }
  116. return $this;
  117. }
  118. public function removeProductFamily(ProductFamily $productFamily): self
  119. {
  120. if ($this->productFamilies->contains($productFamily)) {
  121. $this->productFamilies->removeElement($productFamily);
  122. // set the owning side to null (unless already changed)
  123. if ($productFamily->getMerchant() === $this) {
  124. $productFamily->setMerchant(null);
  125. }
  126. }
  127. return $this;
  128. }
  129. /**
  130. * @return Collection|MerchantConfig[]
  131. */
  132. public function getMerchantConfigs(): Collection
  133. {
  134. return $this->merchantConfigs;
  135. }
  136. public function addMerchantConfig(MerchantConfig $merchantConfig): self
  137. {
  138. if (!$this->merchantConfigs->contains($merchantConfig)) {
  139. $this->merchantConfigs[] = $merchantConfig;
  140. $merchantConfig->setMerchant($this);
  141. }
  142. return $this;
  143. }
  144. public function removeMerchantConfig(MerchantConfig $merchantConfig): self
  145. {
  146. if ($this->merchantConfigs->contains($merchantConfig)) {
  147. $this->merchantConfigs->removeElement($merchantConfig);
  148. // set the owning side to null (unless already changed)
  149. if ($merchantConfig->getMerchant() === $this) {
  150. $merchantConfig->setMerchant(null);
  151. }
  152. }
  153. return $this;
  154. }
  155. public function getMerchantConfig($name)
  156. {
  157. if($this->getMerchantConfigs()) {
  158. foreach($this->getMerchantConfigs() as $merchantConfig) {
  159. if($merchantConfig->getName() == $name) {
  160. return $merchantConfig->getValue() ;
  161. }
  162. }
  163. }
  164. return false ;
  165. }
  166. public function getAddress(): ?Address
  167. {
  168. return $this->address;
  169. }
  170. public function setAddress(Address $address): self
  171. {
  172. $this->address = $address;
  173. return $this;
  174. }
  175. /**
  176. * @return Collection|ProductCategory[]
  177. */
  178. public function getProductCategories(): Collection
  179. {
  180. return $this->productCategories;
  181. }
  182. public function addProductCategory(ProductCategory $productCategory): self
  183. {
  184. if (!$this->productCategories->contains($productCategory)) {
  185. $this->productCategories[] = $productCategory;
  186. $productCategory->setMerchant($this);
  187. }
  188. return $this;
  189. }
  190. public function removeProductCategory(ProductCategory $productCategory): self
  191. {
  192. if ($this->productCategories->contains($productCategory)) {
  193. $this->productCategories->removeElement($productCategory);
  194. // set the owning side to null (unless already changed)
  195. if ($productCategory->getMerchant() === $this) {
  196. $productCategory->setMerchant(null);
  197. }
  198. }
  199. return $this;
  200. }
  201. /**
  202. * @return Collection|News[]
  203. */
  204. public function getNews(): Collection
  205. {
  206. return $this->news;
  207. }
  208. public function addNews(News $news): self
  209. {
  210. if (!$this->news->contains($news)) {
  211. $this->news[] = $news;
  212. $news->setMerchant($this);
  213. }
  214. return $this;
  215. }
  216. public function removeNews(News $news): self
  217. {
  218. if ($this->news->contains($news)) {
  219. $this->news->removeElement($news);
  220. // set the owning side to null (unless already changed)
  221. if ($news->getMerchant() === $this) {
  222. $news->setMerchant(null);
  223. }
  224. }
  225. return $this;
  226. }
  227. /**
  228. * @return Collection|Newsletter[]
  229. */
  230. public function getNewsletters(): Collection
  231. {
  232. return $this->newsletters;
  233. }
  234. public function addNewsletter(Newsletter $newsletter): self
  235. {
  236. if (!$this->newsletters->contains($newsletter)) {
  237. $this->newsletters[] = $newsletter;
  238. $newsletter->setMerchant($this);
  239. }
  240. return $this;
  241. }
  242. public function removeNewsletter(Newsletter $newsletter): self
  243. {
  244. if ($this->newsletters->contains($newsletter)) {
  245. $this->newsletters->removeElement($newsletter);
  246. // set the owning side to null (unless already changed)
  247. if ($newsletter->getMerchant() === $this) {
  248. $newsletter->setMerchant(null);
  249. }
  250. }
  251. return $this;
  252. }
  253. public function getNewsletter()
  254. {
  255. $newsletters = $this->getNewsletters() ;
  256. if(isset($newsletters[0])) {
  257. return $newsletters[0] ;
  258. }
  259. return false ;
  260. }
  261. }