|
|
@@ -11,13 +11,18 @@ use Lc\ShopBundle\Context\OrderUtilsInterface; |
|
|
|
use Lc\ShopBundle\Context\ProductFamilyInterface; |
|
|
|
use Lc\ShopBundle\Context\ReductionCartInterface; |
|
|
|
use Lc\ShopBundle\Model\OrderReductionCart; |
|
|
|
use Lc\ShopBundle\Services\UserUtils; |
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
|
|
use Symfony\Component\Routing\Generator\UrlGenerator; |
|
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
|
|
|
use Symfony\Component\Security\Core\Security; |
|
|
|
|
|
|
|
class CartController extends BaseController |
|
|
|
{ |
|
|
|
protected $orderUtils ; |
|
|
|
protected $userUtils ; |
|
|
|
protected $router ; |
|
|
|
protected $productFamilyRepository ; |
|
|
|
protected $orderProductRepository ; |
|
|
|
|
|
|
@@ -25,21 +30,35 @@ class CartController extends BaseController |
|
|
|
protected $orderProducts = [] ; |
|
|
|
|
|
|
|
|
|
|
|
public function __construct(EntityManagerInterface $em, Security $security, MerchantUtilsInterface $merchantUtils, OrderUtilsInterface $orderUtils) |
|
|
|
public function __construct(EntityManagerInterface $em, Security $security, MerchantUtilsInterface $merchantUtils, OrderUtilsInterface $orderUtils, |
|
|
|
UserUtils $userUtils, UrlGeneratorInterface $router) |
|
|
|
{ |
|
|
|
parent::__construct($em, $security, $merchantUtils); |
|
|
|
$this->orderUtils = $orderUtils ; |
|
|
|
$this->userUtils = $userUtils ; |
|
|
|
$this->router = $router ; |
|
|
|
$this->productFamilyRepository = $this->em->getRepository($this->em->getClassMetaData(ProductFamilyInterface::class)->getName()) ; |
|
|
|
$this->orderProductRepository = $this->em->getRepository($this->em->getClassMetaData(OrderProductInterface::class)->getName()) ; |
|
|
|
} |
|
|
|
|
|
|
|
public function addProductFamily(Request $request) |
|
|
|
{ |
|
|
|
$user = $this->security->getUser() ; |
|
|
|
$visitor = $this->userUtils->getVisitorCurrent() ; |
|
|
|
|
|
|
|
$return = [] ; |
|
|
|
$data = $request->request->all() ; |
|
|
|
|
|
|
|
if(isset($data['order_products']['id_product_family'])) { |
|
|
|
$idProductFamily = $data['order_products']['id_product_family'] ; |
|
|
|
$this->productFamily = $this->productFamilyRepository->find($idProductFamily) ; |
|
|
|
|
|
|
|
// alerte si cookies non acceptés |
|
|
|
if (!$user && !$visitor) { |
|
|
|
$this->addFlash('error', 'Vous devez <a href="'.$this->router->generate('frontend_page', ['devAlias' => 'politique-de-confidentialite']).'">accepter les cookies</a> ou vous <a href="'.$this->router->generate('fos_user_security_login').'">connecter</a> pour ajouter un produit.'); |
|
|
|
return false ; |
|
|
|
} |
|
|
|
|
|
|
|
if($this->productFamily) { |
|
|
|
$form = $this->createForm(OrderProductsType::class, ['id_product_family' => $this->productFamily->getId()]); |
|
|
|
$form->handleRequest($request); |
|
|
@@ -49,8 +68,8 @@ class CartController extends BaseController |
|
|
|
$data = $form->getData() ; |
|
|
|
foreach($data as $orderProduct) { |
|
|
|
if($orderProduct instanceof OrderProductInterface) { |
|
|
|
$this->orderUtils->addOrderProduct($orderShop, $orderProduct) ; |
|
|
|
if($orderProduct->getQuantityOrder() > 0) { |
|
|
|
$addOrderProduct = $this->orderUtils->addOrderProduct($orderShop, $orderProduct) ; |
|
|
|
if($addOrderProduct && $orderProduct->getQuantityOrder() > 0) { |
|
|
|
$this->orderProducts[] = $orderProduct ; |
|
|
|
} |
|
|
|
} |