query = $query; $this->orderShopStore = $orderShopStore; } // getReductionCartByCode public function getByCode(string $code) { $query = $this->query->create(); $query->filterByCode($code); $reductionCarts = $query->find(); $findReductionCart = null; foreach ($reductionCarts as $reductionCart) { if ($reductionCart && in_array($code, $reductionCart->getCodes())) { $findReductionCart = $reductionCart; } } return $findReductionCart; } // getReductionCartRemainingQuantity public function getRemainingQuantity(ReductionCartInterface $reductionCart): float { return $reductionCart->getAvailableQuantity() - $this->orderShopStore->countValidOrderWithReductionCart( $reductionCart ); } // getReductionCartUsedQuantityPerUser public function getUsedQuantityByUser(ReductionCartInterface $reductionCart, UserInterface $user): float { return $this->orderShopStore->countValidOrderWithReductionCartPerUser($reductionCart, $user); } // getReductionCartUsedQuantity public function getUsedQuantity(ReductionCartInterface $reductionCart): float { return $this->orderShopStore->countValidOrderWithReductionCart($reductionCart); } // getReductionCartRemainingQuantityPerUser public function getRemainingQuantityByUser(ReductionCartInterface $reductionCart, UserInterface $user): float { if ($reductionCart->getAvailableQuantityPerUser()) { return $reductionCart->getAvailableQuantityPerUser( ) - $this->orderShopRepo->countValidOrderWithReductionCartPerUser($reductionCart, $user); } return false; } // findAllAvailableForUser / getReductionCartsAvailableByUser public function getAvailablesByUser(UserInterface $user) { $reductionCarts = $this->query->find(); $reductionCartsArray = []; foreach ($reductionCarts as $reductionCart) { if ($reductionCart->matchWithUser($user) && $reductionCart->matchWithGroupUser($user) && $this->getRemainingQuantityByUser($reductionCart, $user) && ($reductionCart->getUsers()->count() > 0 || $reductionCart->getGroupUsers()->count() > 0)) { $reductionCartsArray[] = $reductionCart; } } return $reductionCartsArray; } }