Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

278 lines
7.1KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Model\Reduction;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
  7. use Lc\CaracoleBundle\Doctrine\Extension\OrderAmountMinInterface;
  8. use Lc\CaracoleBundle\Doctrine\Extension\OrderAmountMinTrait;
  9. use Lc\CaracoleBundle\Doctrine\Extension\ReductionCartPropertyInterface;
  10. use Lc\CaracoleBundle\Doctrine\Extension\ReductionCartPropertyTrait;
  11. use Lc\CaracoleBundle\Doctrine\Extension\ReductionInterface;
  12. use Lc\CaracoleBundle\Doctrine\Extension\ReductionPropertyTrait;
  13. use Lc\CaracoleBundle\Doctrine\Extension\ReductionTrait;
  14. use Lc\CaracoleBundle\Doctrine\Extension\ReductionPropertyInterface;
  15. use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
  16. use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface;
  17. use Lc\SovBundle\Doctrine\Extension\StatusInterface;
  18. use Lc\SovBundle\Doctrine\Extension\StatusTrait;
  19. use Lc\SovBundle\Doctrine\Pattern\AbstractLightEntity;
  20. use Lc\SovBundle\Model\User\UserInterface;
  21. /**
  22. * @ORM\MappedSuperclass()
  23. */
  24. abstract class ReductionCartModel extends AbstractLightEntity implements ReductionPropertyInterface, ReductionInterface,
  25. ReductionCartPropertyInterface,
  26. FilterMerchantInterface,
  27. OrderAmountMinInterface, StatusInterface
  28. {
  29. const APPLIED_TO_DELIVERY = 'delivery';
  30. const APPLIED_TO_ORDER_PRODUCTS = 'order-products';
  31. use StatusTrait;
  32. use OrderAmountMinTrait;
  33. use ReductionTrait;
  34. use ReductionCartPropertyTrait;
  35. use ReductionPropertyTrait {
  36. ReductionPropertyTrait::__construct as private __reductionPropertyConstruct;
  37. }
  38. /**
  39. * @ORM\Column(type="string", length=255)
  40. */
  41. protected $title;
  42. /**
  43. * @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Merchant\MerchantInterface")
  44. * @ORM\JoinColumn(nullable=false)
  45. */
  46. protected $merchant;
  47. /**
  48. * @ORM\Column(type="array", nullable=true)
  49. */
  50. protected $codes = [];
  51. /**
  52. * @ORM\Column(type="integer")
  53. */
  54. protected $availableQuantity;
  55. /**
  56. * @ORM\Column(type="integer")
  57. */
  58. protected $availableQuantityPerUser;
  59. /**
  60. * @ORM\ManyToMany(targetEntity="Lc\CaracoleBundle\Model\PointSale\PointSaleInterface")
  61. */
  62. protected $pointSales;
  63. /**
  64. * @ORM\ManyToMany(targetEntity="Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface")
  65. */
  66. protected $uncombinables;
  67. /**
  68. * @ORM\Column(type="array", nullable=true)
  69. */
  70. protected $uncombinableTypes = [];
  71. /**
  72. * @ORM\Column(type="integer", nullable=true)
  73. */
  74. protected $availableQuantityPerCode;
  75. public function __toString()
  76. {
  77. return $this->title;
  78. }
  79. public function __construct()
  80. {
  81. $this->__reductionPropertyConstruct();
  82. $this->pointSales = new ArrayCollection();
  83. $this->uncombinables = new ArrayCollection();
  84. }
  85. // isReductionCartMatchWithUser
  86. public function matchWithUser(UserInterface $user)
  87. {
  88. $conditionUser = false;
  89. if ($user) {
  90. if ($this->getUsers()->isEmpty() || $this->getUsers()->contains($user)) {
  91. $conditionUser = true;
  92. }
  93. }
  94. return $conditionUser;
  95. }
  96. // isReductionCartMatchWithGroupUser
  97. public function matchWithGroupUser(UserInterface $user)
  98. {
  99. $conditionGroupUser = false;
  100. if ($user) {
  101. if ($user->getGroupUsers() && count($user->getGroupUsers()) > 0) {
  102. foreach ($user->getGroupUsers() as $groupUser) {
  103. if ($this->getGroupUsers()->isEmpty() || $this->getGroupUsers()->contains($groupUser)) {
  104. $conditionGroupUser = true;
  105. }
  106. }
  107. } else {
  108. if ($reductionCart->getGroupUsers()->isEmpty()) {
  109. $conditionGroupUser = true;
  110. }
  111. }
  112. }
  113. return $conditionGroupUser;
  114. }
  115. public function getTitle(): ?string
  116. {
  117. return $this->title;
  118. }
  119. public function setTitle(string $title): self
  120. {
  121. $this->title = $title;
  122. return $this;
  123. }
  124. public function getMerchant(): ?MerchantInterface
  125. {
  126. return $this->merchant;
  127. }
  128. public function setMerchant(?MerchantInterface $merchant): self
  129. {
  130. $this->merchant = $merchant;
  131. return $this;
  132. }
  133. public function getCodes(): ?array
  134. {
  135. return $this->codes;
  136. }
  137. public function setCodes(?array $codes): self
  138. {
  139. $this->codes = $codes;
  140. return $this;
  141. }
  142. /**
  143. * @return Collection|PointSaleInterface[]
  144. */
  145. public function getPointSales(): Collection
  146. {
  147. return $this->pointSales;
  148. }
  149. public function addPointSale(PointSaleInterface $pointSale): self
  150. {
  151. if (!$this->pointSales->contains($pointSale)) {
  152. $this->pointSales[] = $pointSale;
  153. }
  154. return $this;
  155. }
  156. public function removePointSale(PointSaleInterface $pointSale): self
  157. {
  158. if ($this->pointSales->contains($pointSale)) {
  159. $this->pointSales->removeElement($pointSale);
  160. }
  161. return $this;
  162. }
  163. public function getAvailableQuantity(): ?int
  164. {
  165. return $this->availableQuantity;
  166. }
  167. public function setAvailableQuantity(int $availableQuantity): self
  168. {
  169. $this->availableQuantity = $availableQuantity;
  170. return $this;
  171. }
  172. public function getAvailableQuantityPerUser(): ?int
  173. {
  174. return $this->availableQuantityPerUser;
  175. }
  176. public function setAvailableQuantityPerUser(int $availableQuantityPerUser): self
  177. {
  178. $this->availableQuantityPerUser = $availableQuantityPerUser;
  179. return $this;
  180. }
  181. /**
  182. * @return Collection|self[]
  183. */
  184. public function getUncombinables(): Collection
  185. {
  186. return $this->uncombinables;
  187. }
  188. public function addUncombinable(self $uncombinable): self
  189. {
  190. if (!$this->uncombinables->contains($uncombinable)) {
  191. $this->uncombinables[] = $uncombinable;
  192. }
  193. return $this;
  194. }
  195. public function removeUncombinables(self $uncombinable): self
  196. {
  197. if ($this->uncombinables->contains($uncombinable)) {
  198. $this->uncombinables->removeElement($uncombinable);
  199. }
  200. return $this;
  201. }
  202. public function getUncombinableTypes(): ?array
  203. {
  204. return $this->uncombinableTypes;
  205. }
  206. public function setUncombinableTypes(?array $uncombinableTypes): self
  207. {
  208. $this->uncombinableTypes = $uncombinableTypes;
  209. return $this;
  210. }
  211. public function getAvailableQuantityPerCode(): ?int
  212. {
  213. return $this->availableQuantityPerCode;
  214. }
  215. public function setAvailableQuantityPerCode(int $availableQuantityPerCode): self
  216. {
  217. $this->availableQuantityPerCode = $availableQuantityPerCode;
  218. return $this;
  219. }
  220. }