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.

89 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(OrderShopInterface $orderShop, OrderProductInterface $orderProductTest)
  18. {
  19. foreach ($orderShop->getOrderProducts() as $orderProduct) {
  20. if ($orderProduct->getProduct() == $orderProductTest->getProduct()) {
  21. return $orderProduct;
  22. }
  23. }
  24. return false;
  25. }
  26. public function isValid(OrderShopInterface $orderShop)
  27. {
  28. if ($orderShop->getOrderStatus() && in_array(
  29. $orderShop->getOrderStatus()->getAlias(),
  30. OrderStatusModel::$statusAliasAsValid
  31. ) > 0) {
  32. return true;
  33. }
  34. return false;
  35. }
  36. public function isCart(OrderShopInterface $orderShop)
  37. {
  38. if ($orderShop->getOrderStatus() && in_array(
  39. $orderShop->getOrderStatus()->getAlias(),
  40. OrderStatusModel::$statusAliasAsCart
  41. ) > 0) {
  42. return true;
  43. }
  44. return false;
  45. }
  46. // isOrderShopPositiveAmount
  47. public function isPositiveAmount(OrderShopInterface $orderShop)
  48. {
  49. return $this->priceSolver->getTotalWithTax($orderShop) >= 0;
  50. }
  51. public function isPaid(OrderShopInterface $orderShop, $mergeComplementaryOrderShop = false)
  52. {
  53. $totalOrderPayments = $this->orderShopSolver->getTotalOrderPayments($orderShop, $mergeComplementaryOrderShop);
  54. $totalOrder = $this->priceSolver->getTotalWithTax($orderShop);
  55. if ((abs($totalOrderPayments - $totalOrder) < 0.00001
  56. || $totalOrderPayments >= $totalOrder)
  57. && $totalOrder > 0) {
  58. return true;
  59. } else {
  60. return false;
  61. }
  62. }
  63. // isOrderShopPositiveAmountRemainingToBePaid
  64. public function isPositiveAmountRemainingToBePaid(OrderShopInterface $orderShop): bool
  65. {
  66. return $this->orderShopSolver->getTotalRemainingToBePaid($orderShop) > 0;
  67. }
  68. public function isCartAllowToBeOrder(OrderShopInterface $orderShop)
  69. {
  70. return true;
  71. }
  72. }