<?php
/**
* Created by PhpStorm.
* User: Slim Sayari
* Date: 10/07/2019
* Time: 13:43
*/
namespace App\Controller\Front;
use App\Entity\BesoinProductPage;
use App\Entity\BesoinProductPageCategory;
use App\Entity\CartDetail;
use App\Entity\CartDetailPhotos;
use App\Entity\ConfigProductDescription;
use App\Entity\DocUpload;
use App\Entity\NosCrea;
use App\Entity\OrderDetail;
use App\Entity\Orders;
use App\Entity\Product;
use App\Entity\ProductAttribute;
use App\Services\CartService;
use App\Services\CheckoutService;
use App\Services\NbDesigner;
use App\Services\OrderService;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use JMS\Serializer\Tests\Fixtures\Order;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Twig\Environment;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use App\Services\Users;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
/**
* @Route("/product-option")
*/
class ProductOptionController extends AbstractController
{
private $twig;
private $router;
private $users_service;
private $nbDesigner;
private $params;
private $cart_service;
private $checkout_service;
public function __construct( OrderService $orderService ,EntityManagerInterface $entityManager ,CheckoutService $checkout_service, Environment $twig, UrlGeneratorInterface $router, ParameterBagInterface $params, Users $users_service, NbDesigner $nbDesigner,CartService $cart_service)
{
$this->twig = $twig;
$this->router = $router;
$this->users_service = $users_service;
$this->nbDesigner = $nbDesigner;
$this->params = $params;
$this->cart_service = $cart_service;
$this->checkout_service = $checkout_service;
$this->em = $entityManager;
$this->orderService = $orderService;
}
/**
* @Route("/{token}", name="product_option",options={"expose"=true})
*/
public function index(Request $request,$token = null) : Response
{
$result = $this->cart_service->checkB2bUser($this->getUser());
$abonnement = $result['abonnement'];
$isAbonnementProInCart = $result['isAbonnementProInCart'];
$cartDetail = $this->nbDesigner->getCartDetail($request,$token);
$product = $this->nbDesigner->getProductByRequest($request);
if($abonnement['is_abonnemen_pro'] || $isAbonnementProInCart){
if($product && !$product->getIsColorLab() && !in_array($product->getTypeProduct(),[Product::PAPIER,Product::PAPIER_POSTE]) ){
$response = $this->twig->render('front/b2b/creer-communiquer/new-product-option2.html.twig', ['product'=>$product,'cartDetail' => $cartDetail, 'cart' => $this->cart_service->createCart(true)]);
}else {
if (($cartDetail && $cartDetail->getProduct()->getIsColorLab() && !$cartDetail->getProduct()->getIsNewDisplayColorLab()) || ($product && $product->getIsColorLab() && !$product->getIsNewDisplayColorLab())) {
// $response = $this->twig->render('front/b2b/creer-communiquer/product-option.html.twig', ['cartDetail' => $cartDetail, 'cart' => $this->cart_service->createCart(true)]);
$response = $this->twig->render('front/b2b/creer-communiquer/new-product-option2.html.twig', ['product'=>$product,'cartDetail' => $cartDetail, 'cart' => $this->cart_service->createCart(true)]);
} else {
// $response = $this->twig->render('front/b2b/creer-communiquer/new-product-option.html.twig', ['cartDetail' => $cartDetail, 'cart' => $this->cart_service->createCart(true)]);
$response = $this->twig->render('front/b2b/creer-communiquer/new-product-option2.html.twig', ['product'=>$product,'cartDetail' => $cartDetail, 'cart' => $this->cart_service->createCart(true)]);
}
}
}else{
if($product && !$product->getIsColorLab() && !in_array($product->getTypeProduct(),[Product::PAPIER,Product::PAPIER_POSTE]) ){
$response = $this->twig->render('front/product-option/new_index2.html.twig', ['product'=>$product,'cartDetail' => $cartDetail, 'cart' => $this->cart_service->createCart(true)]);
}else{
if(($cartDetail && $cartDetail->getProduct()->getIsColorLab() && !$cartDetail->getProduct()->getIsNewDisplayColorLab()) || ($product && $product->getIsColorLab() && !$product->getIsNewDisplayColorLab())) {
$response = $this->twig->render('front/product-option/new_index2.html.twig', ['product'=>$product,'cartDetail' => $cartDetail, 'cart' => $this->cart_service->createCart(true)]);
}else{
$response = $this->twig->render('front/product-option/new_index2.html.twig', ['product'=>$product,'cartDetail' => $cartDetail, 'cart' => $this->cart_service->createCart(true)]);
// $response = $this->twig->render('front/product-option/new_index.html.twig', ['product'=>$product,'cartDetail' => $cartDetail, 'cart' => $this->cart_service->createCart(true)]);
}
}
}
$response = new Response($response);
return $response;
}
/**
* @Route("/get-option-by-token/{token}", name="get_option_by_token",options={"expose"=true})
*/
public function optionByToken(Request $request,$token) : Response
{
$data = $this->nbDesigner->getOptionByToken($request,$token);
$responseInfoTaille = $this->twig->render('front/product-option/info-taille.html.twig',$data);
$responseOption = $this->twig->render('front/product-option/options-global.html.twig',$data);
$responseQty = $this->twig->render('front/product-option/qty-block.html.twig',$data);
$responsePrice = $this->twig->render('front/product-option/getPrice.html.twig',isset($data['price'])?$data['price']:null);
$data['isFormatType'] = true;
$responseOptionFormatType = $this->twig->render('front/product-option/options-global-new.html.twig',$data);
$data['isFormatType'] = false;
$responseOptionAutre = $this->twig->render('front/product-option/options-global-new.html.twig',$data);
$responseOptionMobile = $this->twig->render('front/product-option/options-global-new-mobile.html.twig',$data);
$responseQtyNew = $this->twig->render('front/product-option/qty-block-new.html.twig',$data);
$responseNosLovesPrinterNew = $this->twig->render('front/product-option/nosLovesPrinter.html.twig',$data);
$response = new Response(json_encode(array('responseNosLovesPrinterNew'=>$responseNosLovesPrinterNew,'responseQtyNew'=>$responseQtyNew,'responseOptionFormatType'=>$responseOptionFormatType,'responseOptionAutre'=>$responseOptionAutre,'responseOptionMobile'=>$responseOptionMobile,'responseInfoTaille'=>$responseInfoTaille,'responseoption'=>$responseOption,'responseQty'=>$responseQty,'responsePrice'=>$responsePrice)));
return $response;
}
/**
* @Route("/get-option-by-product/{idProduct}", name="get_option_by_product",options={"expose"=true})
*/
public function optionByProduct(Request $request,$idProduct) : Response
{
$data = $this->nbDesigner->getOptionByProduct($request,$idProduct);
$responseInfoTaille = $this->twig->render('front/product-option/info-taille.html.twig',$data);
$responseOption = $this->twig->render('front/product-option/options-global.html.twig',$data);
$data['isFormatType'] = true;
$responseOptionFormatType = $this->twig->render('front/product-option/options-global-new.html.twig',$data);
$data['isFormatType'] = false;
$responseOptionAutre = $this->twig->render('front/product-option/options-global-new.html.twig',$data);
$responseQty = $this->twig->render('front/product-option/qty-block.html.twig',$data);
$responseQtyNew = $this->twig->render('front/product-option/qty-block-new.html.twig',$data);
$responsePrice = $this->twig->render('front/product-option/getPrice.html.twig',isset($data['price'])?$data['price']:null);
$responseOptionMobile = $this->twig->render('front/product-option/options-global-new-mobile.html.twig',$data);
$responseNosLovesPrinterNew = $this->twig->render('front/product-option/nosLovesPrinter.html.twig',$data);
$response = new Response(json_encode(array('responseNosLovesPrinterNew'=>$responseNosLovesPrinterNew,'responseQtyNew'=>$responseQtyNew,'responseOptionFormatType'=>$responseOptionFormatType,'responseOptionAutre'=>$responseOptionAutre,'responseOptionMobile'=>$responseOptionMobile,'responseInfoTaille'=>$responseInfoTaille,'responseoption'=>$responseOption,'responseQty'=>$responseQty,'responsePrice'=>$responsePrice)));
return $response;
}
/**
* @Route("/get-next-option/product/{idProduct}/type-attribute/{typeAttribute}/value/{valueAttribute}", name="get_nex_option_product_colorLab",options={"expose"=true})
*/
public function getNextOption(Request $request,$idProduct,$typeAttribute,$valueAttribute) : Response
{
$data = $this->nbDesigner->getNextOptionByProduct($request,$idProduct,$typeAttribute,$valueAttribute);
$data['isFormatType'] = true;
$responseOption = $this->twig->render('front/product-option/options-next-new.html.twig',$data);
$data['isFormatType'] = false;
$responseOptionAutre = $this->twig->render('front/product-option/options-next-new.html.twig',$data);
$responseQty = $this->twig->render('front/product-option/qty-block.html.twig',$data);
$responsePrice = $this->twig->render('front/product-option/getPrice.html.twig',isset($data['price'])?$data['price']:null);
$responseQtyNew = $this->twig->render('front/product-option/qty-block-new.html.twig',$data);
$responseNosLovesPrinterNew = $this->twig->render('front/product-option/nosLovesPrinter.html.twig',$data);
$responseOptionMobile = $this->twig->render('front/product-option/options-next-mobile-new.html.twig',$data);
$response = new Response(json_encode(array('responseNosLovesPrinterNew'=>$responseNosLovesPrinterNew,'responseQtyNew'=>$responseQtyNew,'responseOptionAutre'=>$responseOptionAutre,'responseOption'=>$responseOption,'responseQty'=>$responseQty,'responsePrice'=>$responsePrice,'responseOptionMobile'=>$responseOptionMobile)));
return $response;
}
/**
* @Route("/get-option-by-product-and-format/{idProduct}-{idFormat}", name="get_option_by_product_and_format",options={"expose"=true})
*/
public function optionByProductAndFormat(Request $request,$idProduct,$idFormat) : Response
{
$product = $this->em->getRepository(Product::class)->find($idProduct);
if($product && $product->getIsColorlab()){
$data = $this->nbDesigner->getOptionByProduct($request,$idProduct);
}else{
$data = $this->nbDesigner->optionByProductAndFormat($request,$idProduct,$idFormat);
}
$responseInfoTaille = $this->twig->render('front/product-option/info-taille.html.twig',$data);
$responseOption = $this->twig->render('front/product-option/options-global.html.twig',$data);
$responseQty = $this->twig->render('front/product-option/qty-block.html.twig',$data);
$responsePrice = $this->twig->render('front/product-option/getPrice.html.twig',isset($data['price'])?$data['price']:null);
$data['isFormatType'] = true;
$responseOptionFormatType = $this->twig->render('front/product-option/options-global-new.html.twig',$data);
$data['isFormatType'] = false;
$responseOptionAutre = $this->twig->render('front/product-option/options-global-new.html.twig',$data);
$responseOptionMobile = $this->twig->render('front/product-option/options-global-new-mobile.html.twig',$data);
$responseQtyNew = $this->twig->render('front/product-option/qty-block-new.html.twig',$data);
$responseNosLovesPrinterNew = $this->twig->render('front/product-option/nosLovesPrinter.html.twig',$data);
$response = new Response(json_encode(array('responseNosLovesPrinterNew'=>$responseNosLovesPrinterNew,'responseQtyNew'=>$responseQtyNew,'responseOptionFormatType'=>$responseOptionFormatType,'responseOptionAutre'=>$responseOptionAutre,'responseOptionMobile'=>$responseOptionMobile,'responseInfoTaille'=>$responseInfoTaille,'responseoption'=>$responseOption,'responseQty'=>$responseQty,'responsePrice'=>$responsePrice)));
return $response;
}
/**
* @Route("/get-option-and-price-by-format/{idProduct}", name="get_option_and_price_by_format",options={"expose"=true})
*/
public function getOptionByformat(Request $request,$idProduct) : Response
{
$requestData = $request->request->all();
$format_id = isset($requestData['format_id'])? $requestData['format_id'] : null;
$rectoverso = isset($requestData['rectoverso'])? $requestData['rectoverso'] : null;
$typeImpression_id = isset($requestData['typeImpression_id'])? $requestData['typeImpression_id'] : null;
$data = $this->nbDesigner->getOptionByformat($request,$idProduct,$format_id,false,$rectoverso,$typeImpression_id);
$responseInfoTaille = $this->twig->render('front/product-option/info-taille.html.twig',$data);
$responseOption = $this->twig->render('front/product-option/options-global-by-format.html.twig',$data);
$responseOptionMobile = $this->twig->render('front/product-option/options-global-by-format-mobile.html.twig',$data);
$responseQty = $this->twig->render('front/product-option/qty-block.html.twig',$data);
$responsePrice = $this->twig->render('front/product-option/getPrice.html.twig',isset($data['price'])?$data['price']:null);
$responseImageDesc = $this->twig->render('front/product-option/options-image-desc.html.twig',$data);
$responseQtyNew = $this->twig->render('front/product-option/qty-block-new.html.twig',$data);
$responseNosLovesPrinterNew = $this->twig->render('front/product-option/nosLovesPrinter.html.twig',$data);
$response = new Response(json_encode(array('responseNosLovesPrinterNew'=>$responseNosLovesPrinterNew,'responseQtyNew'=>$responseQtyNew,'responseImageDesc'=>$responseImageDesc,'responseInfoTaille'=>$responseInfoTaille,'responseoptionByFormat'=>$responseOption,'responseoptionByFormatMobile'=>$responseOptionMobile,'responseQty'=>$responseQty,'responsePrice'=>$responsePrice)));
return $response;
}
/**
* @Route("/get-grammage-and-price-by-typeImpression-or-rectoVerso/{idProduct}", name="get_grammage_and_price_by_typeImpression_or_rectoVerso",options={"expose"=true})
*/
public function getGramgeByTypeImpressionOrRectoVerso(Request $request,$idProduct) : Response
{
$requestData = $request->request->all();
$format_id = isset($requestData['format_id'])? $requestData['format_id'] : null;
$rectoverso = isset($requestData['rectoverso'])? $requestData['rectoverso'] : null;
$finition = isset($requestData['finition'])? $requestData['finition'] : null;
$typeImpression_id = isset($requestData['typeImpression_id'])? $requestData['typeImpression_id'] : null;
$typeImpression_id = null;
$verification = isset($requestData['verification'])? $requestData['verification'] : null;
$bordsArrondis = isset($requestData['bordsArrondis'])? $requestData['bordsArrondis'] : null;
$plastification = isset($requestData['plastification'])? $requestData['plastification'] : null;
$data = $this->nbDesigner->getGramgeByTypeImpressionOrRectoVerso($request,$idProduct,$format_id,$rectoverso,$finition,$typeImpression_id,false,$verification,$bordsArrondis,$plastification);
$responseOptionGramage = $this->twig->render('front/product-option/options-gramage.html.twig',$data);
$responseQty = $this->twig->render('front/product-option/qty-block.html.twig',$data);
$responsePrice = $this->twig->render('front/product-option/getPrice.html.twig',isset($data['price'])?$data['price']:null);
$data['isFormatType'] = true;
$responseOptionFormatType = $this->twig->render('front/product-option/options-global-new.html.twig',$data);
$data['isFormatType'] = false;
$responseOptionAutre = $this->twig->render('front/product-option/options-global-new.html.twig',$data);
$responseOptionMobile = $this->twig->render('front/product-option/options-global-new-mobile.html.twig',$data);
$responseQtyNew = $this->twig->render('front/product-option/qty-block-new.html.twig',$data);
$response = new Response(json_encode(array('responseQtyNew'=>$responseQtyNew,'responseOptionFormatType'=>$responseOptionFormatType,'responseOptionAutre'=>$responseOptionAutre,'responseOptionMobile'=>$responseOptionMobile,'responseOptionGramage'=>$responseOptionGramage,'responseQty'=>$responseQty,'responsePrice'=>$responsePrice)));
return $response;
}
/**
* @Route("/get-price-and-qty/{idProduct}", name="get_price_and_qty_by_product",options={"expose"=true})
*/
public function priceAndQtyByProduct(Request $request,$idProduct) : Response
{
$requestData = $request->request->all();
$qty = isset($requestData['qty'])? $requestData['qty'] : null;
$format_id = isset($requestData['format_id'])? $requestData['format_id'] : null;
$rectoverso = isset($requestData['rectoverso'])? $requestData['rectoverso'] : null;
$finition = isset($requestData['finition'])? $requestData['finition'] : null;
$gramage_id = isset($requestData['gramage_id'])? $requestData['gramage_id'] : null;
$typeImpression_id = isset($requestData['typeImpression_id'])? $requestData['typeImpression_id'] : null;
$isEnveloppe = isset($requestData['isEnveloppe'])? $requestData['isEnveloppe'] : false;
$plus_expert = isset($requestData['plus_expert'])? $requestData['plus_expert'] : false;
$isTrait = isset($requestData['isTrait'])? $requestData['isTrait'] : false;
$verification = isset($requestData['verification'])? $requestData['verification'] : false;
$bordsArrondis = isset($requestData['bordsArrondis'])? $requestData['bordsArrondis'] : null;
$plastification = isset($requestData['plastification'])? $requestData['plastification'] : null;
$imprimeurLivraison = isset($requestData['imprimeurLivraison'])? $requestData['imprimeurLivraison'] : null;
$dateLivraison = isset($requestData['dateLivraison'])? $requestData['dateLivraison'] : null;
$timeLivraison = isset($requestData['timeLivraison'])? $requestData['timeLivraison'] : null;
$carrierId = isset($requestData['carrierId'])? $requestData['carrierId'] : null;
$typeLivraisonNational = isset($requestData['typeLivraisonNational'])? $requestData['typeLivraisonNational'] : null;
$typeLivraison30min = isset($requestData['typeLivraison30min'])? $requestData['typeLivraison30min'] : null;
$lat = isset($requestData['latLiv'])? $requestData['latLiv'] : null;
$long = isset($requestData['longLiv'])? $requestData['longLiv'] : null;
$codePostal = isset($requestData['codePostalLiv'])? $requestData['codePostalLiv'] : null;
$data = $this->nbDesigner->getPriceAndQuantity($request,$idProduct,$qty,$format_id,$rectoverso,$finition,$gramage_id,$typeImpression_id,$isEnveloppe,$plus_expert,$isTrait,$carrierId ,$typeLivraisonNational ,$typeLivraison30min,null,$imprimeurLivraison,$dateLivraison,$timeLivraison,$lat,$long,$codePostal,$verification,$bordsArrondis,$plastification);
$responseQty = $this->twig->render('front/product-option/qty-block.html.twig',$data);
$responsePrice = $this->twig->render('front/product-option/getPrice.html.twig',isset($data['price'])?$data['price']:null);
$responseDetail = $this->twig->render('front/product-option/detail-block.html.twig',$data);
$responseDetailMobile = $this->twig->render('front/product-option/detail-block-mobile.html.twig',$data);
$responseQtyNew = $this->twig->render('front/product-option/qty-block-new.html.twig',$data);
$response = new Response(json_encode(array('responseQtyNew'=>$responseQtyNew,'responseQty'=>$responseQty,'responsePrice'=>$responsePrice,'responseDetail'=>$responseDetail,'responseDetailMobile'=>$responseDetailMobile)));
return $response;
}
/**
* @Route("/get-btn-crello/", name="get_btn_crello",options={"expose"=true})
*/
public function getBtnCrello(Request $request) : Response
{
$requestData = $request->request->all();
$format_id = isset($requestData['format_id'])? $requestData['format_id'] : null;
$response = $this->nbDesigner->getBtnCrello($request,$format_id);
$response = new Response($response);
return $response;
}
/**
* @Route("/add-to-cart/", name="add_to_cart_new_nb_designer",options={"expose"=true})
*/
public function addToCartNewNbDesigner(Request $request) : Response
{
$data = $this->nbDesigner->addToCartNewNbDesigner($request,$this->getUser());
$responseDetail = $this->twig->render('front/product-option/detail-modal.html.twig',$data);
$response = new Response(json_encode(array($data,'responseDetail'=>$responseDetail)));
return $response;
}
/**
* @Route("/upload-crea/", name="upload_crea_new_nb_designer",options={"expose"=true})
*/
public function uploadCreaNewNbDesigner(Request $request) : Response
{
$files = $request->files->get('fileDesign');
$data = $this->nbDesigner->addImageCreaNewNbDesigner($files);
$response = new Response(json_encode($data));
return $response;
}
/**
* @Route("/get-array-pdf-crello/", name="get_array_pdf_crello",options={"expose"=true})
*/
public function getArrayPdfCrello(Request $request) : Response
{
$fileUrl = $request->request->get('designUrl');
$data = $this->nbDesigner->downloadPdfCrello($request,$fileUrl,'tmp-'.md5());
$response = new Response(json_encode($data));
return $response;
}
/**
* @Route("/get-detail/{idProduct}", name="get_detail_product",options={"expose"=true})
*/
public function getDetailProduct(Request $request,$idProduct) : Response
{
$requestData = $request->request->all();
$qty = isset($requestData['qty'])? $requestData['qty'] : null;
$format_id = isset($requestData['format_id'])? $requestData['format_id'] : null;
$rectoverso = isset($requestData['rectoverso'])? $requestData['rectoverso'] : null;
$finition = isset($requestData['finition'])? $requestData['finition'] : null;
$gramage_id = isset($requestData['gramage_id'])? $requestData['gramage_id'] : null;
$typeImpression_id = isset($requestData['typeImpression_id'])? $requestData['typeImpression_id'] : null;
$carrierId = isset($requestData['carrierId'])? $requestData['carrierId'] : null;
$typeLivraisonNational = isset($requestData['typeLivraisonNational'])? $requestData['typeLivraisonNational'] : null;
$typeLivraison30min = isset($requestData['typeLivraison30min'])? $requestData['typeLivraison30min'] : null;
$isEnveloppe = isset($requestData['isEnveloppe'])? $requestData['isEnveloppe'] : false;
$verification = isset($requestData['verification'])? $requestData['verification'] : false;
$bordsArrondis = isset($requestData['bordsArrondis'])? $requestData['bordsArrondis'] : null;
$plastification = isset($requestData['plastification'])? $requestData['plastification'] : null;
$plus_expert = isset($requestData['plus_expert'])? $requestData['plus_expert'] : false;
$isTrait = isset($requestData['isTrait'])? $requestData['isTrait'] : false;
$tokenDetail = isset($requestData['tokenDetail'])? $requestData['tokenDetail'] : null;
$data = $this->nbDesigner->getDetailProduct($request,$idProduct,$qty,$format_id,$rectoverso,$finition,$gramage_id,$typeImpression_id,$isEnveloppe,$plus_expert,$isTrait,$carrierId ,$typeLivraisonNational ,$typeLivraison30min,$tokenDetail,$verification,$bordsArrondis,$plastification);
$response = new Response($data);
return $response;
}
/**
* @Route("/get-detail-photos/{idProduct}", name="get_detail_product_photos",options={"expose"=true})
*/
public function getDetailProductPhotos(Request $request,$idProduct) : Response
{
$requestData = $request->request->all();
$qty = isset($requestData['qty'])? $requestData['qty'] : null;
$format_id = isset($requestData['format_id'])? $requestData['format_id'] : null;
$rectoverso = isset($requestData['rectoverso'])? $requestData['rectoverso'] : null;
$finition = isset($requestData['finition'])? $requestData['finition'] : null;
$gramage_id = isset($requestData['gramage_id'])? $requestData['gramage_id'] : null;
$typeImpression_id = isset($requestData['typeImpression_id'])? $requestData['typeImpression_id'] : null;
$carrierId = isset($requestData['carrierId'])? $requestData['carrierId'] : null;
$typeLivraisonNational = isset($requestData['typeLivraisonNational'])? $requestData['typeLivraisonNational'] : null;
$typeLivraison30min = isset($requestData['typeLivraison30min'])? $requestData['typeLivraison30min'] : null;
$isEnveloppe = isset($requestData['isEnveloppe'])? $requestData['isEnveloppe'] : false;
$verification = isset($requestData['verification'])? $requestData['verification'] : false;
$bordsArrondis = isset($requestData['bordsArrondis'])? $requestData['bordsArrondis'] : null;
$plastification = isset($requestData['plastification'])? $requestData['plastification'] : null;
$plus_expert = isset($requestData['plus_expert'])? $requestData['plus_expert'] : false;
$isTrait = isset($requestData['isTrait'])? $requestData['isTrait'] : false;
$tokenDetail = isset($requestData['tokenDetail'])? $requestData['tokenDetail'] : null;
$data = $this->nbDesigner->getDetailProductPhotos($request,$idProduct,$qty,$format_id,$rectoverso,$finition,$gramage_id,$typeImpression_id,$isEnveloppe,$plus_expert,$isTrait,$carrierId ,$typeLivraisonNational ,$typeLivraison30min,$tokenDetail,$verification,$bordsArrondis,$plastification);
$response = new Response(json_encode($data));
return $response;
}
/**
* @Route("/get-detail-mobile/{idProduct}", name="get_detail_product_mobile",options={"expose"=true})
*/
public function getDetailProductMobile(Request $request,$idProduct) : Response
{
$requestData = $request->request->all();
$qty = isset($requestData['qty'])? $requestData['qty'] : null;
$format_id = isset($requestData['format_id'])? $requestData['format_id'] : null;
$rectoverso = isset($requestData['rectoverso'])? $requestData['rectoverso'] : null;
$finition = isset($requestData['finition'])? $requestData['finition'] : null;
$gramage_id = isset($requestData['gramage_id'])? $requestData['gramage_id'] : null;
$typeImpression_id = isset($requestData['typeImpression_id'])? $requestData['typeImpression_id'] : null;
$carrierId = isset($requestData['carrierId'])? $requestData['carrierId'] : null;
$typeLivraisonNational = isset($requestData['typeLivraisonNational'])? $requestData['typeLivraisonNational'] : null;
$typeLivraison30min = isset($requestData['typeLivraison30min'])? $requestData['typeLivraison30min'] : null;
$isEnveloppe = isset($requestData['isEnveloppe'])? $requestData['isEnveloppe'] : false;
$verification = isset($requestData['verification'])? $requestData['verification'] : false;
$bordsArrondis = isset($requestData['bordsArrondis'])? $requestData['bordsArrondis'] : null;
$plastification = isset($requestData['plastification'])? $requestData['plastification'] : null;
$plus_expert = isset($requestData['plus_expert'])? $requestData['plus_expert'] : false;
$isTrait = isset($requestData['isTrait'])? $requestData['isTrait'] : false;
$tokenDetail = isset($requestData['tokenDetail'])? $requestData['tokenDetail'] : null;
$data = $this->nbDesigner->getDetailProductMobile($request,$idProduct,$qty,$format_id,$rectoverso,$finition,$gramage_id,$typeImpression_id,$isEnveloppe,$plus_expert,$isTrait,$carrierId ,$typeLivraisonNational ,$typeLivraison30min,$tokenDetail,$verification,$bordsArrondis,$plastification);
$response = new Response($data);
return $response;
}
/**
* @Route("/get-detail-tag-google/{idProduct}", name="get_detail_product_tag_google",options={"expose"=true})
*/
public function getDetailProductTagGoogle(Request $request,$idProduct) : Response
{
$requestData = $request->request->all();
$qty = isset($requestData['qty'])? $requestData['qty'] : null;
$format_id = isset($requestData['format_id'])? $requestData['format_id'] : null;
$rectoverso = isset($requestData['rectoverso'])? $requestData['rectoverso'] : null;
$finition = isset($requestData['finition'])? $requestData['finition'] : null;
$gramage_id = isset($requestData['gramage_id'])? $requestData['gramage_id'] : null;
$typeImpression_id = isset($requestData['typeImpression_id'])? $requestData['typeImpression_id'] : null;
$carrierId = isset($requestData['carrierId'])? $requestData['carrierId'] : null;
$typeLivraisonNational = isset($requestData['typeLivraisonNational'])? $requestData['typeLivraisonNational'] : null;
$typeLivraison30min = isset($requestData['typeLivraison30min'])? $requestData['typeLivraison30min'] : null;
$isEnveloppe = isset($requestData['isEnveloppe'])? $requestData['isEnveloppe'] : false;
$verification = isset($requestData['verification'])? $requestData['verification'] : false;
$bordsArrondis = isset($requestData['bordsArrondis'])? $requestData['bordsArrondis'] : null;
$plastification = isset($requestData['plastification'])? $requestData['plastification'] : null;
$plus_expert = isset($requestData['plus_expert'])? $requestData['plus_expert'] : false;
$isTrait = isset($requestData['isTrait'])? $requestData['isTrait'] : false;
$tokenDetail = isset($requestData['tokenDetail'])? $requestData['tokenDetail'] : null;
$data = $this->nbDesigner->getDetailProductTagGoogle($request,$idProduct,$qty,$format_id,$rectoverso,$finition,$gramage_id,$typeImpression_id,$isEnveloppe,$plus_expert,$isTrait,$carrierId ,$typeLivraisonNational ,$typeLivraison30min,$tokenDetail,$verification,$bordsArrondis,$plastification);
$response = new Response(json_encode($data));
return $response;
}
/**
* @Route("/get-list-product-tag-google/{idCategory}", name="get_list_products_tag_google",options={"expose"=true})
*/
public function getListProductsTagGoogle(Request $request,$idCategory) : Response
{
$produits = $this->em->getRepository(BesoinProductPage::class)->getAllActiveByCategory($idCategory);
if($produits){
$data = $this->nbDesigner->getListProductsBy($produits);
$response = new Response(json_encode($data));
}else{
$response = new Response(0);
}
return $response;
}
/**
* @Route("/get-list-product-tag-google-cat/{num}", name="get_list_products_tag_google_cat",options={"expose"=true})
*/
public function getListProductsCatTagGoogle(Request $request,$num) : Response
{
if($num == 1){
$produits = $this->em->getRepository(NosCrea::class)->findBy([]);
}else if($num == 2){
$produits = $this->em->getRepository(Product::class)->findBy(['besoinProductIsNew'=>true]);
}else if($num = 3){
$produits = $this->em->getRepository(Product::class)->findBy(['besoinProductIsPromo'=>true]);
}else if($num = 4){
$produits = $this->em->getRepository(Product::class)->findBy(['besoinProductIsLuxe'=>true]);
}else{
$produits = null;
}
if($produits){
$data = $this->nbDesigner->getListProductsBy($produits,$num);
$response = new Response(json_encode($data));
}else{
$response = new Response(0);
}
return $response;
}
/**
* @Route("/block-livraison-product/{idProduct}", name="block_livraison_page_option_product",options={"expose"=true})
*/
public function blockLivraison(Request $request,$idProduct): Response
{
$cart = $this->cart_service->createCart(true);
$requestData = $request->request->all();
if (isset($requestData['codePostalLiv'])) {
$data['lat'] = $requestData['latLiv'];
$data['longi'] = $requestData['longLiv'];
$data['postalcode'] = $requestData['codePostalLiv'];
$data['CountryLiv'] = $requestData['CountryLiv'];
$data['CountryCodeLiv'] = isset($requestData['CountryCodeLiv']) ? $requestData['CountryCodeLiv'] : 'Fr';
} else {
return $this->render('front/product-option/blockLivraison.html.twig', array('latLongiRequired' => 1));
}
$qty = isset($requestData['qty'])? $requestData['qty'] : 1000;
$format_id = isset($requestData['format_id'])? $requestData['format_id'] : null;
$rectoverso = isset($requestData['rectoverso'])? $requestData['rectoverso'] : null;
$gramage_id = isset($requestData['gramage_id'])? $requestData['gramage_id'] : null;
$typeImpression_id = isset($requestData['typeImpression_id'])? $requestData['typeImpression_id'] : null;
$tokenDetail = isset($requestData['tokenDetail'])? $requestData['tokenDetail'] : null;
$product = $this->em->getRepository(Product::class)->find($idProduct);
$productAttribute = $this->nbDesigner->getProductAttributeNewNbDesigner($request,$idProduct,$format_id,$gramage_id,$typeImpression_id,$rectoverso,ProductAttribute::SANS_PLASTIFICATION);
$dataLivrason = $this->checkout_service->getModeLivraisonProductOptionPage($cart,$data,$productAttribute,$qty, $this->getUser(),$tokenDetail);
$dataLivrasonHtml = $this->twig->render('front/product-option/blockLivraison-new.html.twig', $dataLivrason);
$response = new Response(json_encode(array('dataLivrasonHtml'=>$dataLivrasonHtml,'isStock'=>$dataLivrason['is_stock'])));
return $response;
}
/**
* @Route("/get-mode-livraison-possible/{idProduct}", name="get_mode_livraison_possible",options={"expose"=true})
*/
public function getModeLivraisonPossible(Request $request,$idProduct) : Response
{
$cart = $this->cart_service->createCart(true);
$requestData = $request->request->all();
if (isset($requestData['codePostalLiv'])) {
$data['lat'] = $requestData['latLiv'];
$data['longi'] = $requestData['longLiv'];
$data['postalcode'] = $requestData['codePostalLiv'];
$data['CountryLiv'] = $requestData['CountryLiv'];
$data['CountryCodeLiv'] = isset($requestData['CountryCodeLiv']) ? $requestData['CountryCodeLiv'] : 'Fr';
}
$qty = isset($requestData['qty'])? $requestData['qty'] : null;
$tokenDetail = isset($requestData['tokenDetail'])? $requestData['tokenDetail'] : null;
$product = $this->em->getRepository(Product::class)->find($idProduct);
$dataLivrason = $this->checkout_service->getModeLivraisonPossible($cart,$data,$product,$qty, $this->getUser(),$tokenDetail);
$result = $this->cart_service->checkB2bUser($this->getUser());
$abonnement = $result['abonnement'];
$isAbonnementProInCart = $result['isAbonnementProInCart'];
if($abonnement['is_abonnemen_pro'] || $isAbonnementProInCart) {
if ($product && !$product->getIsColorLab() && !in_array($product->getTypeProduct(), [Product::PAPIER, Product::PAPIER_POSTE])) {
return $this->render('front/product-option/blockLivraison-new.html.twig', $dataLivrason);
} else {
return $this->render('front/product-option/blockLivraison.html.twig', $dataLivrason);
}
}else {
if ($product && !$product->getIsColorLab() && !in_array($product->getTypeProduct(), [Product::PAPIER, Product::PAPIER_POSTE])) {
return $this->render('front/product-option/blockLivraison-new.html.twig', $dataLivrason);
} else {
return $this->render('front/product-option/blockLivraison.html.twig', $dataLivrason);
}
}
}
/**
* @Route("/modal-stock/block-livraison-product-check-stock/{idProduct}", name="page_option_product_check_stock",options={"expose"=true})
*/
public function checkiFinStock(Request $request,$idProduct): Response
{
$cart = $this->cart_service->createCart(true);
$requestData = $request->request->all();
if (isset($requestData['codePostalLiv'])) {
$data['lat'] = $requestData['latLiv'];
$data['longi'] = $requestData['longLiv'];
$data['postalcode'] = $requestData['codePostalLiv'];
$data['CountryLiv'] = $requestData['CountryLiv'];
$data['CountryCodeLiv'] = isset($requestData['CountryCodeLiv']) ? $requestData['CountryCodeLiv'] : 'Fr';
}
$qty = isset($requestData['qty'])? $requestData['qty'] : null;
$format_id = isset($requestData['format_id'])? $requestData['format_id'] : null;
$rectoverso = isset($requestData['rectoverso'])? $requestData['rectoverso'] : null;
$gramage_id = isset($requestData['gramage_id'])? $requestData['gramage_id'] : null;
$typeImpression_id = isset($requestData['typeImpression_id'])? $requestData['typeImpression_id'] : null;
$tokenDetail = isset($requestData['tokenDetail'])? $requestData['tokenDetail'] : null;
$productAttribute = $this->nbDesigner->getProductAttributeNewNbDesigner($request,$idProduct,$format_id,$gramage_id,$typeImpression_id,$rectoverso,ProductAttribute::SANS_PLASTIFICATION);
$dataLivrason = $this->checkout_service->getModeLivraisonProductOptionPage($cart,$data,$productAttribute,$qty, $this->getUser(),$tokenDetail);
if(!$dataLivrason['is_stock']){
if($productAttribute){
$dataLivrason['productAttributes'] = $this->checkout_service->getProductAttributes($cart,$data,$productAttribute->getProduct(),$qty, $this->getUser(),$tokenDetail);
}
return $this->render('front/product-option/outOfStockModal.html.twig', $dataLivrason);
}else{
return new Response(1);
}
}
/**
* @Route("/modal-stock/get-btn-and-option-by-product-attribute", name="get_btn_and_option_by_product_attribute",options={"expose"=true})
*/
public function getBtnAndOptionByProductAttribute(Request $request) : Response
{
$btns = $this->nbDesigner->getBtnByProductAttribute($request);
$data = $this->nbDesigner->getOptionByProductAttributeAndFinitionAndQty($request);
$responseInfoTaille = $this->twig->render('front/product-option/info-taille.html.twig',$data);
$responseOption = $this->twig->render('front/product-option/options-global.html.twig',$data);
$responseQty = $this->twig->render('front/product-option/qty-block.html.twig',$data);
$responsePrice = $this->twig->render('front/product-option/getPrice.html.twig',isset($data['price'])?$data['price']:null);
$response = new Response(json_encode(array('responseInfoTaille'=>$responseInfoTaille,'responseoption'=>$responseOption,'responseQty'=>$responseQty,'responsePrice'=>$responsePrice,'btns'=>$btns)));
return $response;
}
/**
* @Route("/get-detail-carrier/{idProduct}", name="get_block_detail_livraison",options={"expose"=true})
*/
public function getPriceCarrier(Request $request,$idProduct) : Response
{
$requestData = $request->request->all();
$qty = isset($requestData['qty'])? $requestData['qty'] : null;
$format_id = isset($requestData['format_id'])? $requestData['format_id'] : null;
$rectoverso = isset($requestData['rectoverso'])? $requestData['rectoverso'] : null;
$finition = isset($requestData['finition'])? $requestData['finition'] : null;
$gramage_id = isset($requestData['gramage_id'])? $requestData['gramage_id'] : null;
$typeImpression_id = isset($requestData['typeImpression_id'])? $requestData['typeImpression_id'] : null;
$isEnveloppe = isset($requestData['isEnveloppe'])? $requestData['isEnveloppe'] : false;
$verification = isset($requestData['verification'])? $requestData['verification'] : false;
$bordsArrondis = isset($requestData['bordsArrondis'])? $requestData['bordsArrondis'] : null;
$plastification = isset($requestData['plastification'])? $requestData['plastification'] : null;
$plus_expert = isset($requestData['plus_expert'])? $requestData['plus_expert'] : false;
$isTrait = isset($requestData['isTrait'])? $requestData['isTrait'] : false;
$adresseCarrier = isset($requestData['adresseCarrier'])? $requestData['adresseCarrier'] : null;
$imprimeurLivraison = isset($requestData['imprimeurLivraison'])? $requestData['imprimeurLivraison'] : null;
$dateLivraison = isset($requestData['dateLivraison'])? $requestData['dateLivraison'] : null;
$timeLivraison = isset($requestData['timeLivraison'])? $requestData['timeLivraison'] : null;
$carrierId = isset($requestData['carrierId'])? $requestData['carrierId'] : null;
$typeLivraisonNational = isset($requestData['typeLivraisonNational'])? $requestData['typeLivraisonNational'] : null;
$typeLivraison30min = isset($requestData['typeLivraison30min'])? $requestData['typeLivraison30min'] : null;
$lat = isset($requestData['latLiv'])? $requestData['latLiv'] : null;
$long = isset($requestData['longLiv'])? $requestData['longLiv'] : null;
$codePostal = isset($requestData['codePostalLiv'])? $requestData['codePostalLiv'] : null;
$data = $this->nbDesigner->getPriceAndQuantity($request,$idProduct,$qty,$format_id,$rectoverso,$finition,$gramage_id,$typeImpression_id,$isEnveloppe,$plus_expert,$isTrait,$carrierId ,$typeLivraisonNational ,$typeLivraison30min,$adresseCarrier,$imprimeurLivraison,$dateLivraison,$timeLivraison,$lat,$long,$codePostal,$verification,$bordsArrondis,$plastification);
$responseQty = $this->twig->render('front/product-option/qty-block.html.twig',$data);
$responsePrice = $this->twig->render('front/product-option/getPrice.html.twig',isset($data['price'])?$data['price']:null);
$response = new Response(json_encode(array('responseQty'=>$responseQty,'responsePrice'=>$responsePrice,'blockLivraison'=>$data['blockLivraison'],'livraisonPrice'=>$data['livraisonPrice'])));
return $response;
}
/**
* @Route("/search/product", name="searchProductOption",options={"expose"=true})
*/
public function searchProduct(Request $request) : Response
{
$requestData = $request->query->get('search');
$data = $this->nbDesigner->searchProductOption($request,$requestData,$this->getUser());
$response = new Response(json_encode($data,true));
return $response;
}
/**
* @Route("/save-category/b2b", name="saveCategoryProductOption",options={"expose"=true})
*/
public function saveCategory(Request $request) : Response
{
$data = $this->nbDesigner->saveCustomCatCrello($this->getUser(),$request->query->all());
$response = new Response($data);
return $response;
}
/**
* @Route("/upload-photos/", name="upload_photos_product_option",options={"expose"=true})
*/
public function uploadPhotos(Request $request) : Response
{
$file = $request->files->get('fileDesignPhoto');
$data = $this->nbDesigner->uploadPhotos($file,$request);
$response = new Response(json_encode(['token'=>$data['token'],'thumb'=>$data['thumb'],'image'=>$data['image']]));
return $response;
}
/**
* @Route("/download-photos/{token}", name="download_photos_product_option" , options={"expose"=true})
*/
public function downloadFile(Request $request,$token): Response
{
$file = $this->em->getRepository(CartDetailPhotos::class)->findOneBy(['token'=>$token]);
$filePath = $this->params->get('uploads_directory')."/tmp/".$file->getFile();
$response = new Response();
$response->setContent(file_get_contents($filePath));
$response->headers->set('Content-Type', 'application/force-download');
$response->headers->set('Content-disposition', 'filename='.$file->getFile());
$response->setStatusCode(200);
return $response;
}
/**
* @Route("/delete-photos/{token}", name="delete_photos_product_option" , options={"expose"=true})
*/
public function deleteFile(Request $request,$token)
{
$file = $this->em->getRepository(CartDetailPhotos::class)->findOneBy(['token'=>$token]);
if(is_object($file)) {
if ($file->getFile() and trim($file->getFile()) != '') {
$filePath = $this->params->get('uploads_directory')."/tmp/".$file->getFile();
if (file_exists($filePath)) unlink($filePath);
}
$this->em->remove($file);
$this->em->flush();
}
$response = new Response(1);
$response->setStatusCode(200);
return $response;
}
/**
* @Route("/get-msg-erreur/{tag}", name="get_msg_erreur_product_option" , options={"expose"=true})
*/
public function getMsgErreur(Request $request,$tag): Response
{
$config = $this->em->getRepository(ConfigProductDescription::class)->findOneBy(array('tagId' => $tag));
$msg = 'erreur !';
if($config) {
$msg = $config->getDescription();
}
$response = new Response();
$response->setContent($msg);
$response->setStatusCode(200);
return $response;
}
/**
* @Route("/download-file-cmd/{id}/order/{token}", name="download_file_order" , options={"expose"=true})
*/
public function downloadFileOrder(Request $request,$id,$token): Response
{
$orderDetail = $this->em->getRepository(OrderDetail::class)->getOrdersDetailByOrderToken($id,$token);
$orderDetail->setDownloadNbr($orderDetail->getDownloadNbr() + 1);
$this->em->persist($orderDetail);
$this->em->flush();
$pdf = $orderDetail->getUrlFile();
if($pdf && trim($pdf) != '' && !empty($pdf)) {
$baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath();
if ($orderDetail->getOrders()->getIsCopeesApi()) {
$baseurl = substr_replace($this->params->get('url_site'), "", -1);
}
if ($orderDetail->getTypeProduct() != Product::SIMPLE and $orderDetail->getTypeProduct() != Product::PAPIER_POSTE and $orderDetail->getTypeProduct() != Product::PAPIER) {
if($orderDetail->getOrders()->getCreatedAt() > new \DateTime('23-10-2023') and $orderDetail->getOrders()->getCreatedAt() <= new \DateTime('10-11-2023')){
$cartDetail = $this->em->getRepository(CartDetail::class)->findOneBy(['token'=>$orderDetail->getToken()]);
if($cartDetail){
$pdf = $cartDetail->getFilePapier();
}
}
$path_pdf = $this->params->get('uploads_directory') . '/tmp/' . $pdf;
$url = $baseurl . '/uploads/tmp/' . $pdf;
} else {
if ($orderDetail->getIsModif()) {
$path_pdf = $this->params->get('pdfModif_directory') . '/' . $pdf;
$url = $baseurl . '/modifPdf/' . $pdf;
} else {
if ($orderDetail->getIsTopImp()) {
$path_pdf = $this->params->get('productPdf_directory') . '/' . $pdf;
$url = $baseurl . '/productPdf/' . $pdf;
} else {
$path_pdf = $this->params->get('uploads_directory') . '/' . $pdf;
$url = $baseurl . '/uploads/' . $pdf;
}
}
}
// Generate response
$response = new Response($pdf);
// Set headers
$response->headers->set('Cache-Control', 'private');
if ($orderDetail->getOrders()->getIsCopeesApi()) {
$result = $this->orderService->get_remote_file_info($url);
$buffer = file_get_contents($url);
$finfo = new \finfo(FILEINFO_MIME_TYPE);
$mime_content_type = $finfo->buffer($buffer);
$response->headers->set('Content-type', $mime_content_type);
$response->headers->set('Content-Disposition', 'attachment; filename="' . basename($path_pdf) . '";');
$response->headers->set('Content-length', $result['fileSize']);
} else {
$response->headers->set('Content-type', mime_content_type($path_pdf));
$response->headers->set('Content-Disposition', 'attachment; filename="' . basename($path_pdf) . '";');
$response->headers->set('Content-length', filesize($path_pdf));
}
// Send headers before outputting anything
$response->sendHeaders();
$response->setContent(file_get_contents(str_replace(' ', '%20', $url)));
return $response;
}
$response = new Response();
$response->setContent('erreur !');
$response->setStatusCode(200);
return $response;
}
}