src/Flexy/Apps/POSBundle/Controller/POSApiController.php line 80
<?php
namespace App\Flexy\Apps\POSBundle\Controller;
use App\Flexy\ShopBundle\Entity\Order\Order;
use App\Flexy\ShopBundle\Entity\Shipping\ShippingMethod;
use App\Flexy\ShopBundle\Service\FlexyShopProvider;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class POSApiController extends AbstractController
{
#[Route('/api/calculate-shipping-slots', name: 'calculateShippingSlots',methods:["POST","GET"])]
public function calculateShippingSlots(FlexyShopProvider $flexyShopProvider,Request $request)
{
$contentJsonRequest = [];
$result = [];
if ($request->getContentType() == 'json' and $request->getContent()) {
$contentJsonRequest = json_decode($request->getContent(),true, 512, JSON_THROW_ON_ERROR);
if($contentJsonRequest){
$request->request->replace($contentJsonRequest);
}else{
return $this->json([
"status"=>"error","message"=>"Content is not well formated"
]);
}
}
// $result = [
// "showSlots" => $endDatetime->format('Y-m-d H:i') . ' - ' . $maxEndDateTime->format('H:i'),
// "showEndTime" => $endDatetime->format('H:i'),
// "showMaxEndTime" => $maxEndDateTime->format('H:i'),
// "endDateTime"=> $endDatetime,
// "maxEndDateTime"=> $maxEndDateTime,
// "originalDateTime" => $datetime,
// "roundedDateTime"=>$roundedDatetime
// ];
if($request->request->get("deliveryType") != "on-store"){
return $this->json($flexyShopProvider->calculateShippingSlots(
new \DateTime($request->request->get("datetime")),
(float)$request->request->get("interval"),
(float)$request->request->get("duration"),
(float)$request->request->get("deliveryType"),
));
}
return $this->json($flexyShopProvider->calculateShippingSlots(
new \DateTime($request->request->get("datetime")),
(float)$request->request->get("interval"),
(float)$request->request->get("duration")
));
}
#[Route('/api/calculate-shipping-fees', name: 'calculateShippingFees',methods:["POST","GET"])]
public function calculateShippingFees(FlexyShopProvider $flexyShopProvider,Request $request,ManagerRegistry $doctrine)
{
$contentJsonRequest = [];
$result = [];
if ($request->getContentType() == 'json' and $request->getContent()) {
$contentJsonRequest = json_decode($request->getContent(),true, 512, JSON_THROW_ON_ERROR);
if($contentJsonRequest){
$request->request->replace($contentJsonRequest);
}else{
return $this->json([
"status"=>"error","message"=>"Content is not well formated"
]);
}
}
$shippingMethod = $doctrine->getManager()->getRepository(ShippingMethod::class)->find((int)$request->request->get("shippingMethodId"));
$deliveryType = $request->request->get("deliveryType");
if($deliveryType == "on-store"){
return $this->json([
"fees"=>0
]);
}
return $this->json([
"fees"=>$flexyShopProvider->calculateShippingFees(
$shippingMethod,
(float)$request->request->get("price"),
true
)
]);
}
}