You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
преди 3 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace Lc\CaracoleBundle\Repository\Reduction;
  3. use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface;
  4. use Lc\CaracoleBundle\Repository\Order\OrderShopStore;
  5. use Lc\CaracoleBundle\Solver\Price\PriceSolver;
  6. use Lc\CaracoleBundle\Solver\Reduction\ReductionCartSolver;
  7. use Lc\SovBundle\Model\User\UserInterface;
  8. use Lc\SovBundle\Repository\AbstractStore;
  9. use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
  10. class ReductionCartStore extends AbstractStore
  11. {
  12. protected ReductionCartRepositoryQuery $query;
  13. protected ReductionCartSolver $reductionCartSolver;
  14. protected OrderShopStore $orderShopStore;
  15. protected PriceSolver $priceSolver;
  16. protected FlashBagInterface $flashBag;
  17. public function __construct(
  18. ReductionCartRepositoryQuery $query,
  19. ReductionCartSolver $reductionCartSolver,
  20. OrderShopStore $orderShopStore,
  21. PriceSolver $priceSolver,
  22. FlashBagInterface $flashBag,
  23. ) {
  24. $this->query = $query;
  25. $this->reductionCartSolver = $reductionCartSolver;
  26. $this->orderShopStore = $orderShopStore;
  27. $this->priceSolver = $priceSolver;
  28. $this->flashBag = $flashBag;
  29. }
  30. // getReductionCartByCode
  31. public function getByCode(string $code, $query = null)
  32. {
  33. $query = $this->createQuery($query);
  34. $query->filterByCode($code);
  35. $reductionCarts = $query->find();
  36. $findReductionCart = null;
  37. foreach ($reductionCarts as $reductionCart) {
  38. if ($reductionCart && in_array($code, $reductionCart->getCodes())) {
  39. $findReductionCart = $reductionCart;
  40. }
  41. }
  42. return $findReductionCart;
  43. }
  44. // getReductionCartRemainingQuantity
  45. public function getRemainingQuantity(ReductionCartInterface $reductionCart): float
  46. {
  47. return $reductionCart->getAvailableQuantity() - $this->orderShopStore->countValidWithReductionCart(
  48. $reductionCart
  49. );
  50. }
  51. // getReductionCartUsedQuantityPerUser
  52. public function getUsedQuantityByUser(ReductionCartInterface $reductionCart, UserInterface $user): float
  53. {
  54. return $this->orderShopStore->countValidWithReductionCartByUser($reductionCart, $user);
  55. }
  56. // getReductionCartUsedQuantity
  57. public function getUsedQuantity(ReductionCartInterface $reductionCart): float
  58. {
  59. return $this->orderShopStore->countValidWithReductionCart($reductionCart);
  60. }
  61. // getReductionCartRemainingQuantityPerUser
  62. public function getRemainingQuantityByUser(ReductionCartInterface $reductionCart, UserInterface $user): float
  63. {
  64. if ($reductionCart->getAvailableQuantityPerUser()) {
  65. return $reductionCart->getAvailableQuantityPerUser(
  66. ) - $this->orderShopStore->countValidWithReductionCartByUser($reductionCart, $user);
  67. }
  68. return false;
  69. }
  70. // findAllAvailableForUser / getReductionCartsAvailableByUser
  71. public function getAvailableByUser(UserInterface $user, $query = null)
  72. {
  73. $query = $this->createQuery($query);
  74. $reductionCarts = $query->find();
  75. $reductionCartsArray = [];
  76. foreach ($reductionCarts as $reductionCart) {
  77. if ($this->reductionCartSolver->matchWithUser($user)
  78. && $this->reductionCartSolver->matchWithGroupUser($user)
  79. && $this->getRemainingQuantityByUser($reductionCart, $user)
  80. && ($reductionCart->getUsers()->count() > 0 || $reductionCart->getGroupUsers()->count() > 0)) {
  81. $reductionCartsArray[] = $reductionCart;
  82. }
  83. }
  84. return $reductionCartsArray;
  85. }
  86. }