Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

91 lines
2.7KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Checker;
  3. use Lc\CaracoleBundle\Model\Order\OrderProductInterface;
  4. use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
  5. use Lc\CaracoleBundle\Model\Order\OrderStatusModel;
  6. use Lc\CaracoleBundle\Solver\Order\OrderShopSolver;
  7. use Lc\CaracoleBundle\Solver\Price\PriceSolver;
  8. class OrderChecker
  9. {
  10. protected PriceSolver $priceSolver;
  11. protected OrderShopSolver $orderShopSolver;
  12. public function __construct(PriceSolver $priceSolver, OrderShopSolver $orderShopSolver)
  13. {
  14. $this->priceSolver = $priceSolver;
  15. $this->orderShopSolver = $orderShopSolver;
  16. }
  17. public function hasOrderProductAlreadyInCart(
  18. OrderShopInterface $orderShop,
  19. OrderProductInterface $orderProductTest
  20. ): ?OrderProductInterface {
  21. foreach ($orderShop->getOrderProducts() as $orderProduct) {
  22. if ($orderProduct->getProduct() == $orderProductTest->getProduct()) {
  23. return $orderProduct;
  24. }
  25. }
  26. return null;
  27. }
  28. public function isValid(OrderShopInterface $orderShop): bool
  29. {
  30. if ($orderShop->getOrderStatus() && in_array(
  31. $orderShop->getOrderStatus()->getAlias(),
  32. OrderStatusModel::$statusAliasAsValid
  33. ) > 0) {
  34. return true;
  35. }
  36. return false;
  37. }
  38. public function isCart(OrderShopInterface $orderShop): bool
  39. {
  40. if ($orderShop->getOrderStatus() && in_array(
  41. $orderShop->getOrderStatus()->getAlias(),
  42. OrderStatusModel::$statusAliasAsCart
  43. ) > 0) {
  44. return true;
  45. }
  46. return false;
  47. }
  48. // isOrderShopPositiveAmount
  49. public function isPositiveAmount(OrderShopInterface $orderShop): bool
  50. {
  51. return $this->priceSolver->getTotalWithTax($orderShop) >= 0;
  52. }
  53. public function isPaid(OrderShopInterface $orderShop, $mergeComplementaryOrderShop = false): bool
  54. {
  55. $totalOrderPayments = $this->orderShopSolver->getTotalOrderPayments($orderShop, $mergeComplementaryOrderShop);
  56. $totalOrder = $this->priceSolver->getTotalWithTax($orderShop);
  57. if ((abs($totalOrderPayments - $totalOrder) < 0.00001
  58. || $totalOrderPayments >= $totalOrder)
  59. && $totalOrder > 0) {
  60. return true;
  61. } else {
  62. return false;
  63. }
  64. }
  65. // isOrderShopPositiveAmountRemainingToBePaid
  66. public function isPositiveAmountRemainingToBePaid(OrderShopInterface $orderShop): bool
  67. {
  68. return $this->orderShopSolver->getTotalRemainingToBePaid($orderShop) > 0;
  69. }
  70. public function isCartAllowToBeOrder(OrderShopInterface $orderShop): bool
  71. {
  72. return true;
  73. }
  74. }