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

66 lines
1.9KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Repository\Reduction;
  3. use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
  4. use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface;
  5. use Lc\CaracoleBundle\Model\Reduction\ReductionCreditModel;
  6. use Lc\CaracoleBundle\Repository\Order\OrderShopStore;
  7. use Lc\SovBundle\Model\User\UserInterface;
  8. use Lc\SovBundle\Repository\AbstractStore;
  9. class ReductionCreditStore extends AbstractStore
  10. {
  11. protected ReductionCreditRepositoryQuery $query;
  12. public function __construct(
  13. ReductionCreditRepositoryQuery $query
  14. ) {
  15. $this->query = $query;
  16. }
  17. // findReductionCreditsByUser
  18. public function getByTypeAndUser(string $type = ReductionCreditModel::TYPE_CREDIT, UserInterface $user)
  19. {
  20. $query = $this->query->create();
  21. $query
  22. ->filterStatusOnline()
  23. ->filterByType($type)
  24. ->filterByUser($user);
  25. return $query->find();
  26. }
  27. public function isReductionGiftUsed(ReductionCreditInterface $reductionGift)
  28. {
  29. if ($this->orderShopStore->countValidOrderWithReductionCredit($reductionGift)) {
  30. return true;
  31. } else {
  32. return false;
  33. }
  34. }
  35. public function isReductionCreditUsed(ReductionCreditInterface $reductionCredit, UserInterface $user = null)
  36. {
  37. if ($this->orderShopStore->countValidOrderWithReductionCredit($reductionCredit, $user)) {
  38. return true;
  39. } else {
  40. return false;
  41. }
  42. }
  43. public function isReductionCreditAddedToOrder(
  44. OrderShopInterface $orderShop,
  45. ReductionCreditInterface $reductionCredit
  46. ) {
  47. foreach ($orderShop->getOrderReductionCredits() as $orderReductionCredit) {
  48. if ($orderReductionCredit->getReductionCredit() == $reductionCredit) {
  49. return true;
  50. }
  51. }
  52. return false;
  53. }
  54. }