Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

49 lines
1.6KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Resolver;
  3. use Lc\CaracoleBundle\Model\Reduction\ReductionCreditModel;
  4. use Lc\CaracoleBundle\Repository\Order\OrderShopStore;
  5. use Lc\CaracoleBundle\Repository\Reduction\ReductionCreditStore;
  6. use Lc\SovBundle\Model\User\UserInterface;
  7. class ReductionResolver
  8. {
  9. protected OrderShopStore $orderShopStore;
  10. protected ReductionCreditStore $reductionCreditStore;
  11. public function __construct(OrderShopStore $orderShopStore, ReductionCreditStore $reductionCreditStore)
  12. {
  13. $this->orderShopStore = $orderShopStore;
  14. $this->reductionCreditStore = $reductionCreditStore;
  15. }
  16. public function getReductionCreditsAvailableByUser(UserInterface $user)
  17. {
  18. $reductionCredits = $this->reductionCreditStore->getByTypeAndUser(ReductionCreditModel::TYPE_CREDIT, $user);
  19. $reductionCreditsArray = [];
  20. foreach ($reductionCredits as $reductionCredit) {
  21. if (!$this->orderShopStore->countValidOrderWithReductionCredit($reductionCredit, $user)) {
  22. $reductionCreditsArray[] = $reductionCredit;
  23. }
  24. }
  25. return $reductionCreditsArray;
  26. }
  27. public function getReductionGiftsAvailableByUser($user)
  28. {
  29. $reductionGifts = $this->reductionCreditStore->getByTypeAndUser(ReductionCreditModel::TYPE_GIFT, $user);
  30. $reductionGiftsArray = [];
  31. foreach ($reductionGifts as $reductionGift) {
  32. if (!$this->orderShopStore->countValidOrderWithReductionCredit($reductionGift)) {
  33. $reductionGiftsArray[] = $reductionGift;
  34. }
  35. }
  36. return $reductionGiftsArray;
  37. }
  38. }