use Doctrine\ORM\EntityManagerInterface; | use Doctrine\ORM\EntityManagerInterface; | ||||
use Lc\ShopBundle\Context\MerchantUtilsInterface; | use Lc\ShopBundle\Context\MerchantUtilsInterface; | ||||
use Lc\ShopBundle\Context\OrderProductInterface; | use Lc\ShopBundle\Context\OrderProductInterface; | ||||
use Lc\ShopBundle\Context\OrderReductionCartInterface; | |||||
use Lc\ShopBundle\Context\OrderUtilsInterface; | use Lc\ShopBundle\Context\OrderUtilsInterface; | ||||
use Lc\ShopBundle\Context\ProductFamilyInterface; | use Lc\ShopBundle\Context\ProductFamilyInterface; | ||||
use Lc\ShopBundle\Context\ReductionCartInterface; | |||||
use Lc\ShopBundle\Model\OrderReductionCart; | |||||
use Symfony\Component\HttpFoundation\JsonResponse; | use Symfony\Component\HttpFoundation\JsonResponse; | ||||
use Symfony\Component\HttpFoundation\Request; | use Symfony\Component\HttpFoundation\Request; | ||||
use Symfony\Component\Security\Core\Security; | use Symfony\Component\Security\Core\Security; | ||||
return new JsonResponse($return) ; | return new JsonResponse($return) ; | ||||
} | } | ||||
public function deleteReductionCart($id) | |||||
{ | |||||
$orderReductionCartRepository = $this->em->getRepository($this->em->getClassMetadata(OrderReductionCartInterface::class)->getName()) ; | |||||
$orderReductionCart = $orderReductionCartRepository->findOneById((int) $id) ; | |||||
$orderShop = $this->orderUtils->getCartCurrent() ; | |||||
if($orderReductionCart && $orderShop->getOrderReductionCarts() && $orderShop->getOrderReductionCarts()->contains($orderReductionCart)) { | |||||
$this->em->remove($orderReductionCart) ; | |||||
$this->em->flush() ; | |||||
$this->addFlash('success', 'La réduction a bien été supprimée de votre panier.') ; | |||||
} | |||||
else { | |||||
$this->addFlash('error', 'Une erreur est survenue lors de la suppression de la réduction. ') ; | |||||
} | |||||
return $this->redirectToRoute('frontend_order_cart') ; | |||||
} | |||||
} | } |
<?php | |||||
namespace Lc\ShopBundle\Form\Frontend; | |||||
use Lc\ShopBundle\Validator\Constraints\UniqueEmailValidator; | |||||
use Symfony\Component\Form\AbstractType; | |||||
use Symfony\Component\Form\Extension\Core\Type\TextType; | |||||
use Symfony\Component\Form\FormBuilderInterface; | |||||
use Symfony\Component\OptionsResolver\OptionsResolver; | |||||
class ReductionCartType extends AbstractType | |||||
{ | |||||
public function buildForm(FormBuilderInterface $builder, array $options) | |||||
{ | |||||
$builder->add('code', TextType::class, [ | |||||
'label' => 'Bon de réduction :' | |||||
]); | |||||
} | |||||
public function configureOptions(OptionsResolver $resolver) | |||||
{ | |||||
$resolver->setDefaults([ | |||||
]); | |||||
} | |||||
} |
$this->filterOrderCart($query, true) ; | $this->filterOrderCart($query, true) ; | ||||
$query->leftJoin('e.orderReductionCarts', 'orderReductionCarts') | |||||
->addSelect('orderReductionCarts'); | |||||
$results = $query->getQuery()->getResult() ; | $results = $query->getQuery()->getResult() ; | ||||
if($results) { | if($results) { |
return ReductionCartInterface::class; | return ReductionCartInterface::class; | ||||
} | } | ||||
public function findOneByCode($code) | |||||
{ | |||||
$query = $this->findByMerchantQuery() ; | |||||
$query->andWhere('e.codes LIKE :code')->setParameter('code', '%'.$code.'%') ; | |||||
return $query->getQuery()->getOneOrNullResult() ; | |||||
} | |||||
public function getValuesOfFieldType(){ | public function getValuesOfFieldType(){ | ||||
$query = $this->findByMerchantQuery() ; | $query = $this->findByMerchantQuery() ; | ||||
$query->select('DISTINCT e.type'); | $query->select('DISTINCT e.type'); |
$orderReductionCart->setAppliedTo($reductionCart->getAppliedTo()); | $orderReductionCart->setAppliedTo($reductionCart->getAppliedTo()); | ||||
$orderReductionCart->setType($reductionCart->getType()); | $orderReductionCart->setType($reductionCart->getType()); | ||||
$this->em->persist($orderReductionCart) ; | |||||
$this->em->flush() ; | |||||
return $orderReductionCart; | return $orderReductionCart; | ||||
} | } |