query = $query; } // findReductionCreditsByUser public function getByTypeAndUser(string $type = ReductionCreditModel::TYPE_CREDIT, UserInterface $user) { $query = $this->query->create(); $query ->filterStatusOnline() ->filterByType($type) ->filterByUser($user); return $query->find(); } public function getReductionCreditsAvailableByUser(UserInterface $user) { $reductionCredits = $this->getByTypeAndUser(ReductionCreditModel::TYPE_CREDIT, $user); $reductionCreditsArray = []; foreach ($reductionCredits as $reductionCredit) { if (!$this->orderShopStore->countValidOrderWithReductionCredit($reductionCredit, $user)) { $reductionCreditsArray[] = $reductionCredit; } } return $reductionCreditsArray; } public function getReductionGiftsAvailableByUser($user) { $reductionGifts = $this->getByTypeAndUser(ReductionCreditModel::TYPE_GIFT, $user); $reductionGiftsArray = []; foreach ($reductionGifts as $reductionGift) { if (!$this->orderShopStore->countValidOrderWithReductionCredit($reductionGift)) { $reductionGiftsArray[] = $reductionGift; } } return $reductionGiftsArray; } public function isReductionGiftUsed(ReductionCreditInterface $reductionGift) { if ($this->orderShopStore->countValidOrderWithReductionCredit($reductionGift)) { return true; } else { return false; } } public function isReductionCreditUsed(ReductionCreditInterface $reductionCredit, UserInterface $user = null) { if ($this->orderShopStore->countValidOrderWithReductionCredit($reductionCredit, $user)) { return true; } else { return false; } } public function isReductionCreditAddedToOrder( OrderShopInterface $orderShop, ReductionCreditInterface $reductionCredit ) { foreach ($orderShop->getOrderReductionCredits() as $orderReductionCredit) { if ($orderReductionCredit->getReductionCredit() == $reductionCredit) { return true; } } return false; } }