Sfoglia il codice sorgente

Frontend : intégration des réductions panier

feature/export_comptable
Guillaume 4 anni fa
parent
commit
4f15355d99
5 ha cambiato i file con 61 aggiunte e 0 eliminazioni
  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 Vedi File

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

}

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

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

]);
}
}

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

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

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

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

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

@@ -336,6 +336,8 @@ class OrderUtils
$orderReductionCart->setAppliedTo($reductionCart->getAppliedTo());
$orderReductionCart->setType($reductionCart->getType());

$this->em->persist($orderReductionCart) ;
$this->em->flush() ;

return $orderReductionCart;
}

Loading…
Annulla
Salva