|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
-
- namespace Lc\CaracoleBundle\Checker;
-
- use Lc\CaracoleBundle\Model\Order\OrderProductInterface;
- use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
- use Lc\CaracoleBundle\Model\Order\OrderStatusModel;
- use Lc\CaracoleBundle\Solver\Order\OrderShopSolver;
- use Lc\CaracoleBundle\Solver\Price\PriceSolver;
-
- class OrderChecker
- {
- protected PriceSolver $priceSolver;
- protected OrderShopSolver $orderShopSolver;
-
- public function __construct(PriceSolver $priceSolver, OrderShopSolver $orderShopSolver)
- {
- $this->priceSolver = $priceSolver;
- $this->orderShopSolver = $orderShopSolver;
- }
-
- public function hasOrderProductAlreadyInCart(
- OrderShopInterface $orderShop,
- OrderProductInterface $orderProductTest
- ): ?OrderProductInterface {
- foreach ($orderShop->getOrderProducts() as $orderProduct) {
- if ($orderProduct->getProduct() == $orderProductTest->getProduct()) {
- return $orderProduct;
- }
- }
-
- return null;
- }
-
- public function isValid(OrderShopInterface $orderShop): bool
- {
- if ($orderShop->getOrderStatus() && in_array(
- $orderShop->getOrderStatus()->getAlias(),
- OrderStatusModel::$statusAliasAsValid
- ) > 0) {
- return true;
- }
-
- return false;
- }
-
- public function isCart(OrderShopInterface $orderShop): bool
- {
- if ($orderShop->getOrderStatus() && in_array(
- $orderShop->getOrderStatus()->getAlias(),
- OrderStatusModel::$statusAliasAsCart
- ) > 0) {
- return true;
- }
-
- return false;
- }
-
- // isOrderShopPositiveAmount
- public function isPositiveAmount(OrderShopInterface $orderShop): bool
- {
- return $this->priceSolver->getTotalWithTax($orderShop) >= 0;
- }
-
- public function isPaid(OrderShopInterface $orderShop, $mergeComplementaryOrderShop = false): bool
- {
- $totalOrderPayments = $this->orderShopSolver->getTotalOrderPayments($orderShop, $mergeComplementaryOrderShop);
- $totalOrder = $this->priceSolver->getTotalWithTax($orderShop);
-
- if ((abs($totalOrderPayments - $totalOrder) < 0.00001
- || $totalOrderPayments >= $totalOrder)
- && $totalOrder > 0) {
- return true;
- } else {
- return false;
- }
- }
-
- // isOrderShopPositiveAmountRemainingToBePaid
- public function isPositiveAmountRemainingToBePaid(OrderShopInterface $orderShop): bool
- {
- return $this->orderShopSolver->getTotalRemainingToBePaid($orderShop) > 0;
- }
-
- public function isCartAllowToBeOrder(OrderShopInterface $orderShop): bool
- {
- return true;
- }
-
- }
|