您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ReductionCartSolver.php 1.6KB

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 static function getAppliedToChoices()
  39. {
  40. return [
  41. // ReductionCartModel::APPLIED_TO_DELIVERY,
  42. ReductionCartModel::APPLIED_TO_ORDER_PRODUCTS,
  43. ];
  44. }
  45. }