|
- <?php
-
- namespace Lc\CaracoleBundle\Repository\Reduction;
-
- use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
- use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface;
- use Lc\CaracoleBundle\Model\Reduction\ReductionCreditModel;
- use Lc\CaracoleBundle\Repository\Order\OrderShopStore;
- use Lc\SovBundle\Model\User\UserInterface;
- use Lc\SovBundle\Repository\AbstractStore;
-
- class ReductionCreditStore extends AbstractStore
- {
- protected ReductionCreditRepositoryQuery $query;
-
- public function __construct(
- ReductionCreditRepositoryQuery $query
- ) {
- $this->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 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;
- }
- }
|