Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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 роки тому
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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\SovBundle\Model\User\UserInterface;
  7. use Lc\SovBundle\Repository\AbstractStore;
  8. use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
  9. class ReductionCartStore extends AbstractStore
  10. {
  11. protected ReductionCartRepositoryQuery $query;
  12. protected OrderShopStore $orderShopStore;
  13. protected PriceSolver $priceSolver;
  14. protected FlashBagInterface $flashBag;
  15. public function __construct(
  16. ReductionCartRepositoryQuery $query,
  17. OrderShopStore $orderShopStore,
  18. PriceSolver $priceSolver,
  19. FlashBagInterface $flashBag
  20. ) {
  21. $this->query = $query;
  22. $this->orderShopStore = $orderShopStore;
  23. $this->priceSolver = $priceSolver;
  24. $this->flashBag = $flashBag;
  25. }
  26. // getReductionCartByCode
  27. public function getByCode(string $code)
  28. {
  29. $query = $this->query->create();
  30. $query->filterByCode($code);
  31. $reductionCarts = $query->find();
  32. $findReductionCart = null;
  33. foreach ($reductionCarts as $reductionCart) {
  34. if ($reductionCart && in_array($code, $reductionCart->getCodes())) {
  35. $findReductionCart = $reductionCart;
  36. }
  37. }
  38. return $findReductionCart;
  39. }
  40. // getReductionCartRemainingQuantity
  41. public function getRemainingQuantity(ReductionCartInterface $reductionCart): float
  42. {
  43. return $reductionCart->getAvailableQuantity() - $this->orderShopStore->countValidOrderWithReductionCart(
  44. $reductionCart
  45. );
  46. }
  47. // getReductionCartUsedQuantityPerUser
  48. public function getUsedQuantityByUser(ReductionCartInterface $reductionCart, UserInterface $user): float
  49. {
  50. return $this->orderShopStore->countValidWithReductionCartPerUser($reductionCart, $user);
  51. }
  52. // getReductionCartUsedQuantity
  53. public function getUsedQuantity(ReductionCartInterface $reductionCart): float
  54. {
  55. return $this->orderShopStore->countValidWithReductionCartPerUser($reductionCart);
  56. }
  57. // getReductionCartRemainingQuantityPerUser
  58. public function getRemainingQuantityByUser(ReductionCartInterface $reductionCart, UserInterface $user): float
  59. {
  60. if ($reductionCart->getAvailableQuantityPerUser()) {
  61. return $reductionCart->getAvailableQuantityPerUser(
  62. ) - $this->orderShopStore->countValidWithReductionCartPerUser($reductionCart, $user);
  63. }
  64. return false;
  65. }
  66. // findAllAvailableForUser / getReductionCartsAvailableByUser
  67. public function getAvailablesByUser(UserInterface $user)
  68. {
  69. $reductionCarts = $this->query->find();
  70. $reductionCartsArray = [];
  71. foreach ($reductionCarts as $reductionCart) {
  72. if ($reductionCart->matchWithUser($user)
  73. && $reductionCart->matchWithGroupUser($user)
  74. && $this->getRemainingQuantityByUser($reductionCart, $user)
  75. && ($reductionCart->getUsers()->count() > 0 || $reductionCart->getGroupUsers()->count() > 0)) {
  76. $reductionCartsArray[] = $reductionCart;
  77. }
  78. }
  79. return $reductionCartsArray;
  80. }
  81. }