@@ -6,8 +6,11 @@ use App\Form\Frontend\OrderProductsType; | |||
use Doctrine\ORM\EntityManagerInterface; | |||
use Lc\ShopBundle\Context\MerchantUtilsInterface; | |||
use Lc\ShopBundle\Context\OrderProductInterface; | |||
use Lc\ShopBundle\Context\OrderReductionCartInterface; | |||
use Lc\ShopBundle\Context\OrderUtilsInterface; | |||
use Lc\ShopBundle\Context\ProductFamilyInterface; | |||
use Lc\ShopBundle\Context\ReductionCartInterface; | |||
use Lc\ShopBundle\Model\OrderReductionCart; | |||
use Symfony\Component\HttpFoundation\JsonResponse; | |||
use Symfony\Component\HttpFoundation\Request; | |||
use Symfony\Component\Security\Core\Security; | |||
@@ -59,4 +62,24 @@ class CartController extends BaseController | |||
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') ; | |||
} | |||
} |
@@ -0,0 +1,26 @@ | |||
<?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([ | |||
]); | |||
} | |||
} |
@@ -57,6 +57,9 @@ class OrderShopRepository extends BaseRepository implements DefaultRepositoryInt | |||
$this->filterOrderCart($query, true) ; | |||
$query->leftJoin('e.orderReductionCarts', 'orderReductionCarts') | |||
->addSelect('orderReductionCarts'); | |||
$results = $query->getQuery()->getResult() ; | |||
if($results) { |
@@ -18,6 +18,13 @@ class ReductionCartRepository extends BaseRepository implements DefaultRepositor | |||
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(){ | |||
$query = $this->findByMerchantQuery() ; | |||
$query->select('DISTINCT e.type'); |
@@ -336,6 +336,8 @@ class OrderUtils | |||
$orderReductionCart->setAppliedTo($reductionCart->getAppliedTo()); | |||
$orderReductionCart->setType($reductionCart->getType()); | |||
$this->em->persist($orderReductionCart) ; | |||
$this->em->flush() ; | |||
return $orderReductionCart; | |||
} |