選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

100 行
3.4KB

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