Browse Source

Frontend : intégration des réductions panier

feature/export_comptable
Guillaume 4 years ago
parent
commit
4f15355d99
5 changed files with 61 additions and 0 deletions
  1. +23
    -0
      ShopBundle/Controller/Frontend/CartController.php
  2. +26
    -0
      ShopBundle/Form/Frontend/ReductionCartType.php
  3. +3
    -0
      ShopBundle/Repository/OrderShopRepository.php
  4. +7
    -0
      ShopBundle/Repository/ReductionCartRepository.php
  5. +2
    -0
      ShopBundle/Services/OrderUtils.php

+ 23
- 0
ShopBundle/Controller/Frontend/CartController.php View File

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') ;
}

} }

+ 26
- 0
ShopBundle/Form/Frontend/ReductionCartType.php View File

<?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([

]);
}
}

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



$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) {

+ 7
- 0
ShopBundle/Repository/ReductionCartRepository.php View File

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');

+ 2
- 0
ShopBundle/Services/OrderUtils.php View File

$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;
} }

Loading…
Cancel
Save