src/Flexy/Apps/POSBundle/Controller/POSApiController.php line 80

  1. <?php
  2. namespace App\Flexy\Apps\POSBundle\Controller;
  3. use App\Flexy\ShopBundle\Entity\Order\Order;
  4. use App\Flexy\ShopBundle\Entity\Shipping\ShippingMethod;
  5. use App\Flexy\ShopBundle\Service\FlexyShopProvider;
  6. use Doctrine\Persistence\ManagerRegistry;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. class POSApiController extends AbstractController
  12. {
  13.     #[Route('/api/calculate-shipping-slots'name'calculateShippingSlots',methods:["POST","GET"])]
  14.     public function calculateShippingSlots(FlexyShopProvider $flexyShopProvider,Request $request)
  15.     {
  16.         $contentJsonRequest = [];
  17.         $result = [];
  18.         
  19.         if ($request->getContentType() == 'json' and $request->getContent()) {
  20.             $contentJsonRequest json_decode($request->getContent(),true512JSON_THROW_ON_ERROR);
  21.             if($contentJsonRequest){
  22.                 $request->request->replace($contentJsonRequest);
  23.             }else{
  24.                 return $this->json([
  25.                     "status"=>"error","message"=>"Content is not well formated"
  26.                 ]);
  27.             }
  28.             
  29.         }
  30.         
  31.         
  32.          
  33.         //  $result = [
  34.         //    "showSlots" => $endDatetime->format('Y-m-d H:i') . ' - ' . $maxEndDateTime->format('H:i'),
  35.         //     "showEndTime" => $endDatetime->format('H:i'),
  36.         //     "showMaxEndTime" => $maxEndDateTime->format('H:i'),
  37.         //     "endDateTime"=> $endDatetime,
  38.         //     "maxEndDateTime"=> $maxEndDateTime,
  39.         //     "originalDateTime" => $datetime,
  40.         //     "roundedDateTime"=>$roundedDatetime
  41.         // ];
  42.         
  43.         if($request->request->get("deliveryType") != "on-store"){
  44.             return $this->json($flexyShopProvider->calculateShippingSlots(
  45.                 new \DateTime($request->request->get("datetime")),
  46.                 (float)$request->request->get("interval"),
  47.                 (float)$request->request->get("duration"),
  48.                 (float)$request->request->get("deliveryType"),
  49.             ));
  50.         }
  51.         
  52.        return $this->json($flexyShopProvider->calculateShippingSlots(
  53.         new \DateTime($request->request->get("datetime")),
  54.         (float)$request->request->get("interval"),
  55.         (float)$request->request->get("duration")
  56.     ));
  57.     }
  58.     #[Route('/api/calculate-shipping-fees'name'calculateShippingFees',methods:["POST","GET"])]
  59.     public function calculateShippingFees(FlexyShopProvider $flexyShopProvider,Request $request,ManagerRegistry $doctrine)
  60.     {
  61.         $contentJsonRequest = [];
  62.         $result = [];
  63.         
  64.         if ($request->getContentType() == 'json' and $request->getContent()) {
  65.             $contentJsonRequest json_decode($request->getContent(),true512JSON_THROW_ON_ERROR);
  66.             if($contentJsonRequest){
  67.                 $request->request->replace($contentJsonRequest);
  68.             }else{
  69.                 return $this->json([
  70.                     "status"=>"error","message"=>"Content is not well formated"
  71.                 ]);
  72.             }
  73.             
  74.         }
  75.         $shippingMethod $doctrine->getManager()->getRepository(ShippingMethod::class)->find((int)$request->request->get("shippingMethodId"));
  76.         $deliveryType $request->request->get("deliveryType");
  77.         if($deliveryType == "on-store"){
  78.             return $this->json([
  79.                 "fees"=>0
  80.             ]);
  81.         }
  82.         return $this->json([
  83.             "fees"=>$flexyShopProvider->calculateShippingFees(
  84.                 $shippingMethod,
  85.                 (float)$request->request->get("price"),
  86.                 true
  87.             )
  88.         ]);
  89.     }
  90.     
  91. }