Browse Source

Merge branch 'feature/gift_coupon' of https://gitea.laclic.fr/Laclic/LcShopBundle into feature/gift_coupon

feature/module_traiteur_v1
Guillaume 4 years ago
parent
commit
e89162432f
2 changed files with 27 additions and 7 deletions
  1. +6
    -3
      ShopBundle/Repository/OrderShopRepository.php
  2. +21
    -4
      ShopBundle/Services/Order/OrderUtilsReductionTrait.php

+ 6
- 3
ShopBundle/Repository/OrderShopRepository.php View File

return OrderShopInterface::class; return OrderShopInterface::class;
} }


public function countValidOrderWithReductionCredit($reductionCredit, $user)
public function countValidOrderWithReductionCredit($reductionCredit, $user=null)
{ {
$query = $this->findByMerchantQuery(); $query = $this->findByMerchantQuery();
$query = $this->filterOrderValid($query); $query = $this->filterOrderValid($query);
$query->select('count(e.id)'); $query->select('count(e.id)');
$query->andWhere('e.user = :user');
if($user) {
$query->andWhere('e.user = :user');
$query->setParameter('user', $user);
}
$query->innerJoin('e.orderReductionCredits', 'orc'); $query->innerJoin('e.orderReductionCredits', 'orc');
$query->andWhere('orc.reductionCredit = :reductionCredit'); $query->andWhere('orc.reductionCredit = :reductionCredit');
$query->setParameter('reductionCredit', $reductionCredit); $query->setParameter('reductionCredit', $reductionCredit);
$query->setParameter('user', $user);
return $query->getQuery()->getSingleScalarResult(); return $query->getQuery()->getSingleScalarResult();
} }



+ 21
- 4
ShopBundle/Services/Order/OrderUtilsReductionTrait.php View File

use Lc\ShopBundle\Context\OrderShopInterface; use Lc\ShopBundle\Context\OrderShopInterface;
use Lc\ShopBundle\Context\ReductionCartInterface; use Lc\ShopBundle\Context\ReductionCartInterface;
use Lc\ShopBundle\Context\ReductionCreditInterface; use Lc\ShopBundle\Context\ReductionCreditInterface;
use Lc\ShopBundle\Model\ReductionCredit;
use function Matrix\trace;


trait OrderUtilsReductionTrait trait OrderUtilsReductionTrait
{ {
} }


// n'a pas été utilisé // n'a pas été utilisé
if ($this->orderShopRepo->countValidOrderWithReductionCredit($reductionCredit, $user) > 0) {
$this->utils->addFlash('error', 'error.reductionCredit.alreadyUse');
return false;
if($reductionCredit->getType()== ReductionCredit::TYPE_CREDIT){
if ($this->orderShopRepo->countValidOrderWithReductionCredit($reductionCredit, $user) > 0) {
$this->utils->addFlash('error', 'error.reductionCredit.alreadyUse');
return false;
}
}else{
if ($this->orderShopRepo->countValidOrderWithReductionCredit($reductionCredit) > 0) {
$this->utils->addFlash('error', 'error.reductionCredit.alreadyUse');
return false;
}

} }


return true; return true;


$reductionGiftsArray = [] ; $reductionGiftsArray = [] ;
foreach($reductionGifts as $reductionGift) { foreach($reductionGifts as $reductionGift) {
if(!$this->orderShopRepo->countValidOrderWithReductionCredit($reductionGift, $user)) {
if(!$this->orderShopRepo->countValidOrderWithReductionCredit($reductionGift)) {
$reductionGiftsArray[] = $reductionGift ; $reductionGiftsArray[] = $reductionGift ;
} }
} }
return $reductionGiftsArray ; return $reductionGiftsArray ;
} }


public function isReductionGiftUsed($reductionGift){
if(!$this->orderShopRepo->countValidOrderWithReductionCredit($reductionGift)) {
return true;
}else{
return false;
}
}
public function isReductionCreditAddedToOrder($orderShop, $reductionCredit) public function isReductionCreditAddedToOrder($orderShop, $reductionCredit)
{ {
foreach($orderShop->getOrderReductionCredits() as $orderReductionCredit) { foreach($orderShop->getOrderReductionCredits() as $orderReductionCredit) {

Loading…
Cancel
Save