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.

ReductionCartSolver.php 1.6KB

3 vuotta sitten
3 vuotta sitten
3 vuotta sitten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace Lc\CaracoleBundle\Solver\Reduction;
  3. use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface;
  4. use Lc\CaracoleBundle\Model\Reduction\ReductionCartModel;
  5. use Lc\SovBundle\Model\User\UserInterface;
  6. class ReductionCartSolver
  7. {
  8. // isReductionCartMatchWithUser
  9. public function matchWithUser(ReductionCartInterface $reductionCart, UserInterface $user)
  10. {
  11. $conditionUser = false;
  12. if ($user) {
  13. if ($reductionCart->getUsers()->isEmpty() || $reductionCart->getUsers()->contains($user)) {
  14. $conditionUser = true;
  15. }
  16. }
  17. return $conditionUser;
  18. }
  19. // isReductionCartMatchWithGroupUser
  20. public function matchWithGroupUser(ReductionCartInterface $reductionCart, UserInterface $user)
  21. {
  22. $conditionGroupUser = false;
  23. if ($user) {
  24. if ($user->getGroupUsers() && count($user->getGroupUsers()) > 0) {
  25. foreach ($user->getGroupUsers() as $groupUser) {
  26. if ($reductionCart->getGroupUsers()->isEmpty() || $reductionCart->getGroupUsers()->contains($groupUser)) {
  27. $conditionGroupUser = true;
  28. }
  29. }
  30. } else {
  31. if ($reductionCart->getGroupUsers()->isEmpty()) {
  32. $conditionGroupUser = true;
  33. }
  34. }
  35. }
  36. return $conditionGroupUser;
  37. }
  38. public function getAppliedToChoices()
  39. {
  40. return [
  41. // ReductionCartModel::APPLIED_TO_DELIVERY,
  42. ReductionCartModel::APPLIED_TO_ORDER_PRODUCTS,
  43. ];
  44. }
  45. }