|
- <?php
-
- namespace Lc\CaracoleBundle\Resolver;
-
- use Lc\CaracoleBundle\Model\Reduction\ReductionCreditModel;
- use Lc\CaracoleBundle\Repository\Order\OrderShopStore;
- use Lc\CaracoleBundle\Repository\Reduction\ReductionCreditStore;
- use Lc\SovBundle\Model\User\UserInterface;
-
- class ReductionResolver
- {
- protected OrderShopStore $orderShopStore;
- protected ReductionCreditStore $reductionCreditStore;
-
- public function __construct(OrderShopStore $orderShopStore, ReductionCreditStore $reductionCreditStore)
- {
- $this->orderShopStore = $orderShopStore;
- $this->reductionCreditStore = $reductionCreditStore;
- }
-
- public function getReductionCreditsAvailableByUser(UserInterface $user)
- {
- $reductionCredits = $this->reductionCreditStore->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->reductionCreditStore->getByTypeAndUser(ReductionCreditModel::TYPE_GIFT, $user);
-
- $reductionGiftsArray = [];
- foreach ($reductionGifts as $reductionGift) {
- if (!$this->orderShopStore->countValidOrderWithReductionCredit($reductionGift)) {
- $reductionGiftsArray[] = $reductionGift;
- }
- }
-
- return $reductionGiftsArray;
- }
- }
|