src/Controller/CartController.php line 286

Open in your IDE?
  1. <?php 
  2. declare(strict_types=1);
  3. namespace App\Controller;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Twig\Environment;
  7. use Symfony\Component\DependencyInjection\ContainerInterface;
  8. use Symfony\Component\HttpFoundation\JsonResponse;
  9. use Sylius\Component\Product\Repository\ProductVariantRepositoryInterface;
  10. use Sylius\Component\Channel\Context\ChannelContextInterface;
  11. use App\Services\PPMCErpSynchroService;
  12. use Symfony\Component\Process\Process;
  13. use Symfony\Component\Process\Exception\ProcessTimedOutException;
  14. use Carbon\Carbon;
  15. use Symfony\Component\Messenger\MessageBusInterface;
  16. use App\Message\SyncCustomer;
  17. // use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  18. class CartController /*extends AbstractController*/
  19. {
  20.     protected $twigEnvironment;
  21.     protected $container;
  22.     protected $productVariantRepository;
  23.     protected $ppmcErpSynchroService;
  24.     protected $bus;
  25.     public function __construct(
  26.         Environment $twigEnvironment,
  27.         ContainerInterface $container,
  28.         ProductVariantRepositoryInterface $productVariantRepository,
  29.         PPMCErpSynchroService $ppmcErpSynchroService,
  30.         MessageBusInterface $bus
  31.     ){
  32.         $this->twigEnvironment $twigEnvironment;
  33.         $this->container $container;
  34.         $this->productVariantRepository $productVariantRepository;
  35.         $this->ppmcErpSynchroService $ppmcErpSynchroService;
  36.         $this->bus $bus;
  37.         
  38.     }
  39.     public function popupAction(Request $request): Response
  40.     {        
  41.         // $this->payLog($request, "");
  42.         $cart =  $this->container->get('sylius.context.cart')->getCart();  
  43.         $amount 0;
  44.         $total 0;
  45.         $diff 0;
  46.         $progress 0;
  47.         $cdts $this->container->get('sylius.repository.promotion')->findOneByCode('FREE_DELIVERY')->getRules();
  48.         foreach ($cdts as $cdt){
  49.             if ($cdt->getType() == 'item_total') {
  50.                 $amount $cdt->getConfiguration()['ppmc']['amount'];
  51.                 $total $cart->getItemsTotal();   
  52.                 $diff $amount-$total;   
  53.                 $progress $total $amount 100;        
  54.             }
  55.         }
  56.         // Produits dans "Je craque aussi pour"
  57.         // Des accessoires cheveux 
  58.         // de nouvelles collections uniquement
  59.         // 7 produits max aleatoire
  60.         // et 1 chouchou aléatoire peu importe la collection
  61.         $moreVariants $this->container->get('sylius.repository.product_variant')
  62.         ->findVariantsForCartPageIWantThisToo(
  63.             $this->container->get('sylius.context.channel')->getChannel(),
  64.             $this->container->get('sylius.context.locale')->getLocaleCode()
  65.         );
  66.         //On vinet associé une adresse si la personne est connectée
  67.         // if(null != $cart->getCustomer() && null != $cart->getCustomer()->getId() && $cart->getBillingAddress() == null) {
  68.         //     // dump($cart->getCustomer());
  69.         //     $addresses = $cart->getCustomer()->getAddresses();
  70.         //     $this->container->get('doctrine')->getManager()->initializeObject($addresses);
  71.         //     dump($addresses);
  72.         // //     $cart->setBillingAddress($cart->getCustomer()->getAddresses()[0]);
  73.         // //     $cart->setShippingAddress($cart->getCustomer()->getAddresses()[0]);
  74.         // //     $cartManager = $this->container->get('sylius.manager.order');
  75.         // //     $cartManager->persist($cart);
  76.         // //     $cartManager->flush();
  77.         // }
  78.         // $this->container->get('doctrine')->getManager()->initializeObject($cart);
  79.         // dump($cart);
  80.        
  81.         
  82.         return new Response(
  83.             $this->twigEnvironment->render('@SyliusShop/Webapic/panier.html.twig', [
  84.                 'cart' => $cart,
  85.                 'amount' => $amount,
  86.                 'total' => $total,
  87.                 'diff' => $diff,
  88.                 'progress' => $progress,
  89.                 'moreVariants' => $moreVariants
  90.             ])
  91.         );
  92.     }
  93.     public function addToCartAjax(ChannelContextInterface $channelCtxRequest $request)
  94.     {
  95.         // POST : 
  96.         // data[<id product variant>] = <quantity>
  97.         // data[<id product variant>] = <quantity>
  98.         // etc.
  99.         $data = (array) $request->request->all();
  100.         if (empty($data) == true) {
  101.             return new JsonResponse([
  102.                 'success' => true
  103.             ]);
  104.         }
  105.         // Selectionne le canal pour calculer le prix
  106.         $channel $channelCtx->getChannel();
  107.         //gestion champ carte kdo
  108.         $kdoFields = [];
  109.         if(isset($data['kdo_mail'])) {
  110.             $kdoFields['kdo_mail'] = $data['kdo_mail'];
  111.             $kdoFields['kdo_lastname'] = $data['kdo_lastname'];
  112.             $kdoFields['kdo_firstname'] = $data['kdo_firstname'];
  113.             $kdoFields['kdo_message'] = $data['kdo_message'];
  114.             unset($data['kdo_mail']);
  115.             unset($data['kdo_lastname']);
  116.             unset($data['kdo_firstname']);
  117.             unset($data['kdo_message']);
  118.         }
  119.         // Ajout au panier
  120.         $cart $this->container->get('sylius.context.cart')->getCart();
  121.         foreach ($data as $variantId => $quantity) {
  122.             $quantity round(floatval($quantity), 1);
  123.             $variant $this->productVariantRepository->findOneById($variantId);
  124.             if (is_null($variant) == false && $quantity 0) {
  125.                 if($variant->countItemStock() <= || $variant->getIsBlocked()){
  126.                 // if($variant->getOnHand() - $variant->getOnHold() <= 5){
  127.                     return new JsonResponse([
  128.                         'stock' => 0
  129.                     ]);
  130.                 }
  131.                 
  132.                 $orderItem $this->container->get('sylius.repository.order_item')->findOneBy([
  133.                     'variant' => $variant,
  134.                     'order' => $cart
  135.                 ]);
  136.     
  137.                 if (!empty($orderItem) && $variant->getProduct()->getConditioning() != 'per_meter_each_0_5_meter' && $variant->getProduct()->getConditioning() != 'card_kdo_per_euros_each_10_euros') {
  138.                    $quantity  $orderItem->getQuantity() + $quantity;
  139.                    if($quantity 10){                       
  140.                         $quantity 10;
  141.                     }
  142.                     $this->container->get('sylius.order_item_quantity_modifier')->modify($orderItem, (int) $quantity);
  143.                     
  144.                 }else{                    
  145.                     // if(!empty($orderItem) &&  $variant->getProduct()->getConditioning() == 'per_meter_each_0_5_meter'){
  146.                     //     // $this->container->get('sylius.order_modifier')->removeFromOrder($cart, $orderItem);                        
  147.                     //     // $this->container->get('sylius.order_item_quantity_modifier')->modify($orderItem, 0);
  148.                     // }
  149.                     if($variant->getProduct()->getConditioning() == 'per_meter_each_0_5_meter') {
  150.                         if($quantity 10){
  151.                             $quantity 10;
  152.                         }   
  153.                     }
  154.                    
  155.                     $this->addOrderItemToCart($channel$cart$variant$quantitynull$kdoFields);
  156.                 }
  157.                
  158.             }
  159.         }
  160.     
  161.         $cartManager $this->container->get('sylius.manager.order');
  162.         $cartManager->persist($cart);
  163.         $cartManager->flush();
  164.         $isFine true;
  165.         // $isFine =$this->stockVerification($cart, $request);
  166.         // Valorisation du panier côté Generix
  167.         $this->applyReducedPricesToCart($channel$cart);
  168.         $cart $this->container->get('sylius.context.cart')->getCart();
  169.         // dump($cart);
  170.         
  171.         $amount 0;
  172.         $total 0;
  173.         $diff 0;
  174.         $progress 0;
  175.         $cdts $this->container->get('sylius.repository.promotion')->findOneByCode('FREE_DELIVERY')->getRules();
  176.         foreach($cdts as $cdt){
  177.            
  178.             if( $cdt->getType() == 'item_total'){
  179.                 $amount $cdt->getConfiguration()['ppmc']['amount'];
  180.                 $total $cart->getItemsTotal();   
  181.                 $diff $amount-$total;   
  182.                 $progress $total $amount 100;        
  183.             }
  184.         }       
  185.         $items = [];
  186.         foreach($cart->getItems() as $item) {
  187.             $items[] = [
  188.                 'id' => $item->getId(),
  189.                 'quantity' => $item->getQuantity(),
  190.                 'variant' => [
  191.                     'id' => $item->getVariant()->getId(),
  192.                     'name' => $item->getVariant()->getName(),
  193.                     'code' => $item->getVariant()->getCode(),
  194.                     'price' => $item->getUnitPrice(),
  195.                 ],
  196.             ];
  197.         }
  198.         $fromPagepanier $request->query->get('pagepanier''');
  199.         if(!empty($fromPagepanier)){
  200.             return new JsonResponse([
  201.                 'produits' => $this->twigEnvironment->render('@SyliusShop/Webapic/panier/pagepanier-produits.html.twig', [
  202.                     'cart' => $cart,
  203.                 ]),
  204.                 'total' => $this->twigEnvironment->render('@SyliusShop/Cart/Summary/_totals.html.twig', [
  205.                      'cart' => $cart,
  206.                 ]),
  207.                 'livraison' => $this->twigEnvironment->render('@SyliusShop/Webapic/panier/panier-livraison.html.twig', [
  208.                     'cart' => $cart,
  209.                     'amount' => $amount,
  210.                     'total' => $total,
  211.                     'diff' => $diff,
  212.                     'progress' => $progress,
  213.                 ]),
  214.                 'widgettop' => $this->twigEnvironment->render('@SyliusShop/Cart/_widget.html.twig', [
  215.                     'cart' => $cart,
  216.                 ]),
  217.                 'data' => [
  218.                     "total" => $total,
  219.                     "items"    => $items
  220.                 ],
  221.                 // 'isFine' => true
  222.                 'isFine' => $isFine
  223.             ]);
  224.         }
  225.         
  226.         return new JsonResponse([
  227.             'produits' => $this->twigEnvironment->render('@SyliusShop/Webapic/panier/panier-produits.html.twig', [
  228.                 'cart' => $cart,
  229.             ]),
  230.             'total' => $this->twigEnvironment->render('@SyliusShop/Webapic/panier/panier-total.html.twig', [
  231.                  'cart' => $cart,
  232.             ]),
  233.             'top' => $this->twigEnvironment->render('@SyliusShop/Webapic/panier/panier-top.html.twig', [
  234.                 'cart' => $cart,
  235.             ]),
  236.             'livraison' => $this->twigEnvironment->render('@SyliusShop/Webapic/panier/panier-livraison.html.twig', [
  237.                 'cart' => $cart,
  238.                 'amount' => $amount,
  239.                 'total' => $total,
  240.                 'diff' => $diff,
  241.                 'progress' => $progress,
  242.             ]),
  243.             'widgettop' => $this->twigEnvironment->render('@SyliusShop/Cart/_widget.html.twig', [
  244.                 'cart' => $cart,
  245.             ]),
  246.             'data' => [
  247.                 "total" => $total,
  248.                 "items"    => $items
  249.             ],
  250.             // 'isFine' => true
  251.             'isFine' => $isFine
  252.         ]);
  253.     }
  254.     public function updateCartAction(ChannelContextInterface $channelCtxRequest $request$id)
  255.     {
  256.         
  257.         $cart $this->container->get('sylius.context.cart')->getCart();
  258.         $repository $this->container->get('sylius.repository.order_item');
  259.         $orderItem $repository->findOneByIdAndCartId($id$cart->getId());
  260.         // dump($orderItem);
  261.         if (!empty($orderItem)) {
  262.             $quantity min(99max(0intval($request->request->get('quantity'1))));
  263.             if($quantity 10){
  264.                 $quantity 10;
  265.             }
  266.             if($quantity == 0){
  267.                 $this->container->get('sylius.order_modifier')->removeFromOrder($cart$orderItem);
  268.             }else{
  269.                
  270.                 $this->container->get('sylius.order_item_quantity_modifier')->modify($orderItem$quantity);
  271.             }
  272.             $this->container->get('sylius.order_item_quantity_modifier')->modify($orderItem$quantity);
  273.            
  274.         }else{
  275.             $orderItem $this->container->get('sylius.factory.order_item')->createNew();
  276.             $orderItem->setVariant($this->productVariantRepository->find($id));
  277.             $this->container->get('sylius.order_item_quantity_modifier')->modify($orderItem1);
  278.             $this->container->get('sylius.order_modifier')->addToOrder($cart$orderItem);
  279.             $cart->addItem($orderItem);
  280.             
  281.         }
  282.         $cartManager $this->container->get('sylius.manager.order');
  283.         $cartManager->persist($cart);
  284.         $cartManager->flush();
  285.         // echo 'coucou';
  286.         // dump($orderItem);
  287.         // exit();
  288.         // Selectionne le canal pour calculer le prix
  289.         $channel $channelCtx->getChannel();
  290.         $isFine true;
  291.         // $isFine =$this->stockVerification($cart, $request);
  292.         // Valorisation du panier côté Generix
  293.         $this->applyReducedPricesToCart($channel$cart);
  294.         $cart $this->container->get('sylius.repository.order')->findOneBy([
  295.             'id' => $cart->getId()
  296.         ]);
  297.         // $this->container->get('sylius.context.cart')->getCart();
  298.         // $this->container->get('sylius.context.cart')->setCart($cart);
  299.         // $cartManager = $this->container->get('sylius.manager.order');
  300.         // $cartManager->persist($cart);
  301.         // $cartManager->flush();
  302.         // $cart = $this->container->get('sylius.context.cart')->getCart();
  303.         $amount 0;
  304.         $total 0;
  305.         $diff 0;
  306.         $progress 0;
  307.         $cdts $this->container->get('sylius.repository.promotion')->findOneByCode('FREE_DELIVERY')->getRules();
  308.         foreach($cdts as $cdt){
  309.            
  310.             if( $cdt->getType() == 'item_total'){
  311.                 $amount $cdt->getConfiguration()['ppmc']['amount'];
  312.                 $total $cart->getItemsTotal();   
  313.                 $diff $amount-$total;   
  314.                 $progress $total $amount 100;        
  315.             }
  316.         }       
  317.         if($request->request->get('pagepanier')){      
  318.             $configuration $this->requestConfigurationFactory->create($this->metadata$request);
  319.             if (!$configuration->isHtmlRequest()) {
  320.                 return $this->viewHandler->handle($configurationView::create($cart));
  321.             }
  322.             $form $this->resourceFormFactory->create($configuration$cart);
  323.             
  324.             return new JsonResponse([
  325.                 'pagepaniertotal' => $this->twigEnvironment->render('@SyliusShop/Webapic/panier/pagepanier-right.html.twig', [
  326.                     'cart' => $cart,
  327.                     'form' => $form->createView(),
  328.                     'amount' => $amount,
  329.                     'total' => $total,
  330.                     'diff' => $diff,
  331.                     'progress' => $progress,
  332.                 ]),
  333.             ]);
  334.         }else{
  335.             return new JsonResponse([
  336.                 'produits' => $this->twigEnvironment->render('@SyliusShop/Webapic/panier/panier-produits.html.twig', [
  337.                     'cart' => $cart,
  338.                 ]),
  339.                 'total' => $this->twigEnvironment->render('@SyliusShop/Webapic/panier/panier-total.html.twig', [
  340.                     'cart' => $cart,
  341.                 ]),
  342.                 'top' => $this->twigEnvironment->render('@SyliusShop/Webapic/panier/panier-top.html.twig', [
  343.                     'cart' => $cart,
  344.                 ]),
  345.                 'livraison' => $this->twigEnvironment->render('@SyliusShop/Webapic/panier/panier-livraison.html.twig', [
  346.                     'cart' => $cart,
  347.                     'amount' => $amount,
  348.                     'total' => $total,
  349.                     'diff' => $diff,
  350.                     'progress' => $progress,
  351.                 ]),
  352.                 'widgettop' => $this->twigEnvironment->render('@SyliusShop/Cart/_widget.html.twig', [
  353.                     'cart' => $cart,
  354.                 ]),
  355.                 // 'isFine' => true
  356.                 'isFine' => $isFine
  357.             ]);            
  358.         }       
  359.     }
  360.     public function meaAction(Request $request): Response
  361.     {        
  362.         return new Response(
  363.             $this->twigEnvironment->render('@SyliusShop/Webapic/panier/mea.html.twig', [
  364.                 // 'cart' => $cart
  365.             ])
  366.         );
  367.     }
  368.     private function addOrderItemToCart($channel$cart$variant$quantity, ?int $customPrice null, ?array $kdoFields): void
  369.     {
  370.         if($variant->getIsBlocked()) {
  371.             return;
  372.         }
  373.         if ($variant->getProduct()->getConditioning() == 'per_meter_each_0_5_meter') {
  374.             // Ajout d'un tissu au mètre (0,5m etc)
  375.             // On ajoute une ligne à chaque fois avec une quantité de "1"
  376.             $basePrice is_null($customPrice) ? $variant->getChannelPricingForChannel($channel)->getPrice() : $customPrice;
  377.             $price = (int) round($basePrice $quantity0);
  378.             $orderItem $this->container->get('sylius.factory.order_item')->createNew();
  379.             $orderItem->setVariant($variant);
  380.             $orderItem->setVariantName($variant->getName() . ' - ' $quantity 'm');
  381.             $orderItem->setOriginalUnitPrice($price);
  382.             $orderItem->setUnitPrice($price);
  383.             $orderItem->setImmutable(true);
  384.             $orderItem->setConditioning($variant->getProduct()->getConditioning());
  385.             $orderItem->setConditioningValue($quantity);
  386.             $this->container->get('sylius.order_item_quantity_modifier')->modify($orderItem1);
  387.             $this->container->get('sylius.order_modifier')->addToOrder($cart$orderItem);
  388.         } else if ($variant->getProduct()->getConditioning() == 'card_kdo_per_euros_each_10_euros' && !empty($kdoFields)) {
  389.             // Ajout d'une carte cadeau
  390.             // On ajoute une ligne à chaque fois avec une quantité de "1"
  391.             
  392.             $basePrice is_null($customPrice) ? $variant->getChannelPricingForChannel($channel)->getPrice() : $customPrice;
  393.             $price = (int) round($basePrice $quantity0);
  394.             // dump($cart);
  395.             // dump($variant);
  396.             // dump($quantity);
  397.             // dump($price);
  398.             // exit();
  399.             $orderItem $this->container->get('sylius.factory.order_item')->createNew();
  400.             $orderItem->setVariant($variant);
  401.             $orderItem->setVariantName($variant->getName() . ' - ' $quantity '€');
  402.             $orderItem->setOriginalUnitPrice((int) round($quantity 1000));
  403.             $orderItem->setUnitPrice((int) round($quantity 1000));
  404.             $orderItem->setImmutable(true);
  405.             $orderItem->setConditioning($variant->getProduct()->getConditioning());
  406.             $orderItem->setConditioningValue($quantity);
  407.             $orderItem->setKdoEmail($kdoFields['kdo_mail']);
  408.             $orderItem->setKdoLastname($kdoFields['kdo_lastname']);
  409.             $orderItem->setKdoFirstname($kdoFields['kdo_firstname']);
  410.             $orderItem->setKdoMessage($kdoFields['kdo_message']);
  411.             $this->container->get('sylius.order_item_quantity_modifier')->modify($orderItem1);
  412.             $this->container->get('sylius.order_modifier')->addToOrder($cart$orderItem);
  413.         } else {
  414.             $quantity intval($quantity);
  415.             $orderItem $this->container->get('sylius.repository.order_item')->findOneBy([
  416.                 'variant' => $variant,
  417.                 'order' => $cart
  418.             ]);
  419.             // dump($orderItem);
  420.             if (empty($orderItem) == true) {
  421.                 $orderItem $this->container->get('sylius.factory.order_item')->createNew();
  422.                 $orderItem->setVariant($variant);
  423.                 if (is_null($customPrice) == false) {
  424.                     $orderItem->setOriginalUnitPrice($customPrice);
  425.                     $orderItem->setUnitPrice($customPrice);
  426.                     $orderItem->setImmutable(true);
  427.                 }
  428.                 if(($orderItem->getQuantity() + $quantity) > 10){
  429.                     $this->container->get('sylius.order_item_quantity_modifier')->modify($orderItem10);
  430.                 }else{
  431.                     
  432.                     $this->container->get('sylius.order_item_quantity_modifier')->modify($orderItem$orderItem->getQuantity() + $quantity);
  433.                 }
  434.                
  435.                 $this->container->get('sylius.order_modifier')->addToOrder($cart$orderItem);
  436.             } else {
  437.                 if (is_null($customPrice) == false) {
  438.                     $orderItem->setOriginalUnitPrice($customPrice);
  439.                     $orderItem->setUnitPrice($customPrice);
  440.                     $orderItem->setImmutable(true);
  441.                 }
  442.                
  443.                 $this->container->get('sylius.order_item_quantity_modifier')->modify($orderItem$orderItem->getQuantity() + $quantity);
  444.             }
  445.         }
  446.     }
  447.     public function applyReducedPricesToCart($channel$cart): void
  448.     {
  449.         
  450.         if (isset($_GET['frommail']) ) {
  451.             return;
  452.         }
  453.         // echo $webPath = $this->container->get('kernel')->getProjectDir();
  454.         $process = new Process(['/usr/bin/php'$this->container->get('kernel')->getProjectDir().'/bin/console',  'ppmc:valorize-cart''--cartId='.$cart->getId()]);
  455.         $process->setTimeout(4);
  456.         try {
  457.         
  458.             $process->start();
  459.             $process->wait();
  460.             // echo $process->getOutput();
  461.             $em $this->container->get('doctrine.orm.entity_manager');
  462.             $em->refresh($cart);
  463.             $cartItems $cart->getItems();
  464.             foreach ($cartItems as $cartRow) {
  465.                 $em->refresh($cartRow);
  466.             }
  467.         } catch (ProcessTimedOutException $exception) {
  468.             // echo 'bofbof';
  469.         }
  470.     }
  471.     public function convertFideliteAction(
  472.         Request $request): JsonResponse
  473.     {
  474.         $customer $this->container->get('sylius.context.customer')->getCustomer();
  475.         $this->bus->dispatch(new SyncCustomer((int)$customer->getId()));
  476.         $fidelity $request->query->get('fidelity'0);        
  477.     
  478.         $cart $this->container->get('sylius.context.cart')->getCart();       
  479.         $cart->setHasLoyalty($fidelity);       
  480.         // $this->applyReducedPricesToCart($channel, $cart);
  481.         $cartManager $this->container->get('sylius.manager.order');
  482.         $cartManager->persist($cart);
  483.         $cartManager->flush();
  484.         return new JsonResponse([
  485.             'success' => true
  486.         ]);
  487.     }
  488.     public static function stockVerification($cart$request): bool
  489.     {
  490.         
  491.       
  492.         $isFine true;
  493.         $cartItems $cart->getItems();
  494.         foreach ($cartItems as $cartRow) {
  495.             // si panier > 30mn et stock insuffisant
  496.             if($cart->getCompteur() == 0){ 
  497.                                     
  498.                 if(!$cartRow->canAddItem()){
  499.                     $isFine false;
  500.                     $quantity $cartRow->nbItemStock();
  501.                     if($quantity == 0){
  502.                         $this->container->get('sylius.order_modifier')->removeFromOrder($cart$cartRow);
  503.                         $request->getSession()->getFlashBag()->add(
  504.                             'error',
  505.                             "Le produit ".$cartRow->getVariant()->getName()." n'est plus disponible "
  506.                         );
  507.                     }else{
  508.                         $this->container->get('sylius.order_item_quantity_modifier')->modify($cartRow$quantity);
  509.                         $request->getSession()->getFlashBag()->add(
  510.                             'info',
  511.                             "Le produit ".$cartRow->getVariant()->getName()." n'est plus disponible dans la quantité demandée "
  512.                         );
  513.                     }
  514.                     $this->container->get('sylius.order_processing.order_processor')->process($cart);
  515.                     $cartManager $this->container->get('sylius.manager.order');
  516.                     $cartManager->persist($cart);
  517.                     $cartManager->flush();
  518.                 }
  519.             }            
  520.         }
  521.         return $isFine;
  522.     }
  523.     public function addMessageToCart(Request $request) {
  524.         $cart $this->container->get('sylius.context.cart')->getCart();
  525.         $data = (array) $request->request->all();        
  526.         if(!empty($data['message'])) {
  527.             $cart->setGiftMessage($data['message']);
  528.             $cartManager $this->container->get('sylius.manager.order');
  529.             $cartManager->persist($cart);
  530.             $cartManager->flush();
  531.         }
  532.         return new JsonResponse([
  533.             'success' => true
  534.         ]);
  535.     }
  536.     
  537.     
  538. }