Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

316 linhas
9.8KB

  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. }