Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

230 lines
7.2KB

  1. <?php
  2. namespace Lc\ShopBundle\Model;
  3. use App\Entity\ProductCategory;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8. * @ORM\MappedSuperclass()
  9. */
  10. abstract class Merchant extends AbstractDocumentEntity
  11. {
  12. /**
  13. * @ORM\OneToOne(targetEntity="Lc\ShopBundle\Context\CreditConfigInterface", cascade={"persist", "remove"})
  14. * @ORM\JoinColumn(nullable=true)
  15. */
  16. protected $creditConfig;
  17. /**
  18. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\TaxRateInterface")
  19. * @ORM\JoinColumn(nullable=false)
  20. */
  21. protected $taxRate;
  22. /**
  23. * @ORM\ManyToMany(targetEntity="Lc\ShopBundle\Context\PointSaleInterface", mappedBy="merchant")
  24. */
  25. protected $pointSales;
  26. /**
  27. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\ProductFamilyInterface", mappedBy="merchant")
  28. */
  29. protected $productFamilies;
  30. /**
  31. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\MerchantConfigInterface", mappedBy="merchant", orphanRemoval=true, cascade={"persist"})
  32. */
  33. protected $merchantConfigs;
  34. /**
  35. * @ORM\OneToOne(targetEntity="Lc\ShopBundle\Context\AddressInterface", inversedBy="merchant", cascade={"persist", "remove"})
  36. * @ORM\JoinColumn(nullable=true)
  37. */
  38. protected $address;
  39. /**
  40. * @ORM\OneToMany(targetEntity="App\Entity\ProductCategory", mappedBy="merchant", orphanRemoval=true)
  41. */
  42. private $productCategories;
  43. public function __construct()
  44. {
  45. $this->pointSales = new ArrayCollection();
  46. $this->productFamilies = new ArrayCollection();
  47. $this->merchantConfigs = new ArrayCollection();
  48. $this->productCategories = new ArrayCollection();
  49. }
  50. public function getCreditConfig(): ?CreditConfig
  51. {
  52. return $this->creditConfig;
  53. }
  54. public function setCreditConfig(CreditConfig $creditConfig): self
  55. {
  56. $this->creditConfig = $creditConfig;
  57. return $this;
  58. }
  59. public function getTaxRate(): ?TaxRate
  60. {
  61. return $this->taxRate;
  62. }
  63. public function setTaxRate(?TaxRate $taxRate): self
  64. {
  65. $this->taxRate = $taxRate;
  66. return $this;
  67. }
  68. /**
  69. * @return Collection|PointSale[]
  70. */
  71. public function getPointSales(): Collection
  72. {
  73. return $this->pointSales;
  74. }
  75. public function addPointSale(PointSale $pointSale): self
  76. {
  77. if (!$this->pointSales->contains($pointSale)) {
  78. $this->pointSales[] = $pointSale;
  79. $pointSale->addMerchant($this);
  80. }
  81. return $this;
  82. }
  83. public function removePointSale(PointSale $pointSale): self
  84. {
  85. if ($this->pointSales->contains($pointSale)) {
  86. $this->pointSales->removeElement($pointSale);
  87. $pointSale->removeMerchant($this);
  88. }
  89. return $this;
  90. }
  91. /**
  92. * @return Collection|ProductFamily[]
  93. */
  94. public function getProductFamilies(): Collection
  95. {
  96. return $this->productFamilies;
  97. }
  98. public function addProductFamily(ProductFamily $productFamily): self
  99. {
  100. if (!$this->productFamilies->contains($productFamily)) {
  101. $this->productFamilies[] = $productFamily;
  102. $productFamily->setMerchant($this);
  103. }
  104. return $this;
  105. }
  106. public function removeProductFamily(ProductFamily $productFamily): self
  107. {
  108. if ($this->productFamilies->contains($productFamily)) {
  109. $this->productFamilies->removeElement($productFamily);
  110. // set the owning side to null (unless already changed)
  111. if ($productFamily->getMerchant() === $this) {
  112. $productFamily->setMerchant(null);
  113. }
  114. }
  115. return $this;
  116. }
  117. /**
  118. * @return Collection|MerchantConfig[]
  119. */
  120. public function getMerchantConfigs(): Collection
  121. {
  122. return $this->merchantConfigs;
  123. }
  124. public function addMerchantConfig(MerchantConfig $merchantConfig): self
  125. {
  126. if (!$this->merchantConfigs->contains($merchantConfig)) {
  127. $this->merchantConfigs[] = $merchantConfig;
  128. $merchantConfig->setMerchant($this);
  129. }
  130. return $this;
  131. }
  132. public function removeMerchantConfig(MerchantConfig $merchantConfig): self
  133. {
  134. if ($this->merchantConfigs->contains($merchantConfig)) {
  135. $this->merchantConfigs->removeElement($merchantConfig);
  136. // set the owning side to null (unless already changed)
  137. if ($merchantConfig->getMerchant() === $this) {
  138. $merchantConfig->setMerchant(null);
  139. }
  140. }
  141. return $this;
  142. }
  143. public function getMerchantConfig($name)
  144. {
  145. if($this->getMerchantConfigs()) {
  146. foreach($this->getMerchantConfigs() as $merchantConfig) {
  147. if($merchantConfig->getName() == $name) {
  148. return $merchantConfig->getValue() ;
  149. }
  150. }
  151. }
  152. return false ;
  153. }
  154. public function getAddress(): ?Address
  155. {
  156. return $this->address;
  157. }
  158. public function setAddress(Address $address): self
  159. {
  160. $this->address = $address;
  161. return $this;
  162. }
  163. /**
  164. * @return Collection|ProductCategory[]
  165. */
  166. public function getProductCategories(): Collection
  167. {
  168. return $this->productCategories;
  169. }
  170. public function addProductCategory(ProductCategory $productCategory): self
  171. {
  172. if (!$this->productCategories->contains($productCategory)) {
  173. $this->productCategories[] = $productCategory;
  174. $productCategory->setMerchant($this);
  175. }
  176. return $this;
  177. }
  178. public function removeProductCategory(ProductCategory $productCategory): self
  179. {
  180. if ($this->productCategories->contains($productCategory)) {
  181. $this->productCategories->removeElement($productCategory);
  182. // set the owning side to null (unless already changed)
  183. if ($productCategory->getMerchant() === $this) {
  184. $productCategory->setMerchant(null);
  185. }
  186. }
  187. return $this;
  188. }
  189. }