<?php
/**
* Created by Elements.at New Media Solutions GmbH
*
*/
namespace App\Controller\Shop\Json;
use App\Controller\AbstractController;
use App\Model\Shop\Event\EventProduct;
use App\Service\Shop\JsonDataService;
use Carbon\Carbon;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* @Route("/{_locale}/shop/event")
*/
class EventJsonController extends AbstractController
{
/**
* @Route("/calendar-dates", name="json_event_calendar_dates", methods={"GET"})
*/
public function calendarDatesJson(Request $request, JsonDataService $jsonDataService): Response
{
return $this->json($jsonDataService->getCalendarDates($request));
}
/**
* @Route("/b2b-calendar-dates", name="json_b2b_event_calendar_dates", methods={"GET"})
*/
public function b2bCalendarDatesJson(Request $request, JsonDataService $jsonDataService): Response
{
$this->setEnvironmentTenant('b2b');
return $this->json($jsonDataService->getCalendarDates($request));
}
/**
* @Route("/list-dates", name="json_event_list_dates", methods={"GET"})
*/
public function listDatesJson(Request $request, JsonDataService $jsonDataService): Response
{
return $this->json($jsonDataService->getListDatesJson(intval($request->get('activityId'))));
}
/**
* @Route("/b2b-list-dates", name="json_b2b_event_list_dates", methods={"GET"})
*/
public function b2bListDatesJson(Request $request, JsonDataService $jsonDataService): Response
{
$this->setEnvironmentTenant('b2b');
return $this->json($jsonDataService->getListDatesJson(intval($request->get('activityId'))));
}
/**
* @Route("/time-list-dates", name="json_event_time_list_dates", methods={"GET"})
*/
public function timeListDatesJson(Request $request, JsonDataService $jsonDataService): Response
{
return $this->json($jsonDataService->getTimeListDatesJson(intval($request->get('activityId')), $request->get('selectedDateEnd')));
}
/**
* @Route("/b2b-time-list-dates", name="json_b2b_event_time_list_dates", methods={"GET"})
*/
public function b2bTimeListDatesJson(Request $request, JsonDataService $jsonDataService): Response
{
$this->setEnvironmentTenant('b2b');
return $this->json($jsonDataService->getTimeListDatesJson(intval($request->get('activityId')), $request->get('selectedDateEnd')));
}
/**
* @Route("/base_price", name="json_event_base_price", methods={"GET"})
*/
public function basePriceJson(Request $request, TranslatorInterface $trans): Response
{
$json = [];
if ($product = EventProduct::getById(intval($request->get('activityId')))) {
$selectedDate = null;
if ($date = $request->get('selectedDate')) {
$selectedDate = Carbon::createFromDate($date);
}
$priceInfo = $product->getOSPriceInfo(1, null, $selectedDate);
/** @phpstan-ignore-next-line */
$price = $priceInfo ? $priceInfo->getOriginalPriceInfo()->getBaseAmount() : 0;
$json = [
'success' => true,
'id' => (string)$request->get('activityId'),
'basePriceInfo' => [
'label' => $trans->trans('shop.configuration.adult-price'),
'price' => $price,
],
];
}
return $this->json($json);
}
}