src/Controller/BookingApi/ApiCatalogControllerApi.php line 581

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by Elements.at New Media Solutions GmbH
  4.  *
  5.  */
  6. namespace App\Controller\BookingApi;
  7. use App\Ecommerce\OrderManager\Filter\TicketCatalog;
  8. use App\Model\BookingApi\DateRange;
  9. use App\Model\BookingApi\Event;
  10. use App\Model\BookingApi\EventAgeGroupPrice;
  11. use App\Model\BookingApi\Image;
  12. use App\Model\BookingApi\LocalizedText;
  13. use App\Model\BookingApi\PriceInfos;
  14. use App\Model\BookingApi\SimpleIdTextObject;
  15. use App\Model\BookingApi\TextWithHeadline;
  16. use App\Model\BookingApi\TicketCatalogUpgradeRelation;
  17. use App\Model\BookingApi\TicketInsurance;
  18. use App\Model\BookingApi\TicketValidity;
  19. use App\Model\Shop\Event\EventProduct;
  20. use App\Model\Shop\Event\ShopDynamicPrice;
  21. use App\Model\Shop\Ticket\ShopTicketCatalog;
  22. use App\Model\Type\TenantType;
  23. use App\Traits\EnvironmentTrait;
  24. use Carbon\Carbon;
  25. use OpenApi\Annotations as OA;
  26. use Pimcore\Model\DataObject\Data\ObjectMetadata;
  27. use Pimcore\Model\DataObject\Fieldcollection\Data\CustomDescription;
  28. use Pimcore\Model\DataObject\Fieldcollection\Data\PriceInfo;
  29. use Pimcore\Model\DataObject\ShopEvent;
  30. use Symfony\Component\HttpFoundation\JsonResponse;
  31. use Symfony\Component\HttpFoundation\Request;
  32. use Symfony\Component\Routing\Annotation\Route;
  33. /**
  34.  * Class ApiCatalogControllerApi
  35.  *
  36.  * @Route("/bookingAPI/catalog")
  37.  *
  38.  * @OA\Tag(name="Catalog")
  39.  */
  40. class ApiCatalogControllerApi extends ApiAbstractController
  41. {
  42.     use EnvironmentTrait;
  43.     /**
  44.      * Return all relevant ticket catalog data for marketplace
  45.      *
  46.      * @param Request $request
  47.      *
  48.      * @Route("/ticketcatalogs", name="catalog_ticketcatalogs", methods={"POST", "GET"})
  49.      *
  50.      * @OA\Post(
  51.      *     path="/bookingAPI/catalog/ticketcatalogs",
  52.      *     description="Get all relevant ticket catalog data for marketplace",
  53.      *     tags={"Catalog"},
  54.      *
  55.      *     @OA\RequestBody(
  56.      *      required=false,
  57.      *
  58.      *           @OA\JsonContent(
  59.      *
  60.      *              @OA\Property( property="pageSize", type="string", example="10"),
  61.      *              @OA\Property( property="pageNumber", type="string", example="1"),
  62.      *          )
  63.      *      ),
  64.      *
  65.      *      @OA\Response(
  66.      *          response=200,
  67.      *          description="Successful operation",
  68.      *
  69.      *          @OA\MediaType(
  70.      *              mediaType="application/json",
  71.      *
  72.      *              @OA\Schema(
  73.      *                  type = "object",
  74.      *
  75.      *                   @OA\Property(property="success", type="boolean"),
  76.      *                   @OA\Property(property="total", type="int", example=50),
  77.      *                   @OA\Property(property="pageCurrent", type="int", example=1),
  78.      *                   @OA\Property(property="pageSize", type="int", example=10),
  79.      *                   @OA\Property(property="pageLast", type="int", example=5),
  80.      *                   @OA\Property(property="ticketCatalogs", type="array",
  81.      *
  82.      *                      @OA\Items(ref="#/components/schemas/TicketCatalog")
  83.      *                   )
  84.      *              )
  85.      *          )
  86.      *      ),
  87.      *
  88.      *     @OA\Response(
  89.      *          response=500,
  90.      *          description="Error",
  91.      *      ),
  92.      *
  93.      *     @OA\Info (
  94.      *          title="ticket catalog",
  95.      *          version="0.0.1"
  96.      *      )
  97.      *
  98.      *
  99.      * )
  100.      */
  101.     public function ticketcatalogsAction(Request $request): JsonResponse
  102.     {
  103.         $body $request->getContent();
  104.         $requestData json_decode($bodytrue);
  105.         $pageSize $requestData intval($requestData['pageSize']) : 100;
  106.         $pageNumber $requestData intval($requestData['pageNumber']) : 1;
  107.         try {
  108.             $this->setEnvironmentTenant(TenantType::MARKETPLACE);
  109.             $ticketData $this->getTicketCatalogsAsJson($pageSize$pageNumber);
  110.             $returnData['success'] = true;
  111.             $returnData array_merge($returnData$ticketData);
  112.             if ($request->get('debug')) {
  113.                 p_r($returnData);
  114.                 die();
  115.             }
  116.             return new JsonResponse($returnData);
  117.         } catch (\Throwable $throwable) {
  118.             $this->bookingapiLogger->error($throwable->getMessage() . 'Stack Trace: ' $throwable->getTraceAsString());
  119.             return $this->sendErrors([$throwable->getMessage()], 500);
  120.         }
  121.     }
  122.     /**
  123.      * Return all relevant event catalog data for marketplace. Quota gets displayed for each day with the timestamp being the beginning of the day
  124.      *
  125.      * @param Request $request
  126.      *
  127.      * @Route("/events", name="catalog_events", methods={"POST", "GET"})
  128.      *
  129.      * @OA\Post(
  130.      *     path="/bookingAPI/catalog/events",
  131.      *     description="Get all relevant event catalog data for marketplace. Quota gets displayed for each day with the timestamp being the beginning of the day",
  132.      *     tags={"Catalog"},
  133.      *
  134.      *     @OA\RequestBody(
  135.      *      required=false,
  136.      *
  137.      *           @OA\JsonContent(
  138.      *
  139.      *              @OA\Property( property="pageSize", type="string", example="10"),
  140.      *              @OA\Property( property="pageNumber", type="string", example="1"),
  141.      *          )
  142.      *      ),
  143.      *
  144.      *      @OA\Response(
  145.      *          response=200,
  146.      *          description="Successful operation",
  147.      *
  148.      *          @OA\MediaType(
  149.      *              mediaType="application/json",
  150.      *
  151.      *              @OA\Schema(
  152.      *                  type = "object",
  153.      *
  154.      *                   @OA\Property(property="success", type="boolean"),
  155.      *                   @OA\Property(property="total", type="int", example=50),
  156.      *                   @OA\Property(property="pageCurrent", type="int", example=1),
  157.      *                   @OA\Property(property="pageSize", type="int", example=10),
  158.      *                   @OA\Property(property="pageLast", type="int", example=5),
  159.      *                   @OA\Property(property="events", type="array",
  160.      *
  161.      *                      @OA\Items(ref="#/components/schemas/Event")
  162.      *                   )
  163.      *              )
  164.      *          )
  165.      *      ),
  166.      *
  167.      *     @OA\Response(
  168.      *          response=500,
  169.      *          description="Error",
  170.      *      ),
  171.      *
  172.      * )
  173.      */
  174.     public function eventsAction(Request $request): JsonResponse
  175.     {
  176.         $body $request->getContent();
  177.         $requestData json_decode($bodytrue);
  178.         $pageSize $requestData intval($requestData['pageSize']) : 100;
  179.         $pageNumber $requestData intval($requestData['pageNumber']) : 1;
  180.         try {
  181.             $this->setEnvironmentTenant();
  182.             $eventData $this->getEventsAsJson($pageSize$pageNumber);
  183.             $returnData['success'] = true;
  184.             $returnData array_merge($returnData$eventData);
  185.             if ($request->get('debug')) {
  186.                 p_r($returnData);
  187.                 die();
  188.             }
  189.             return new JsonResponse($returnData);
  190.         } catch (\Throwable $throwable) {
  191.             $this->bookingapiLogger->error($throwable->getMessage() . 'Stack Trace: ' $throwable->getTraceAsString());
  192.             return $this->sendErrors([$throwable->getMessage()], 500);
  193.         }
  194.     }
  195.     /**
  196.      * @param int $pageSize
  197.      * @param int $pageNumber
  198.      *
  199.      * @return array<string,mixed>
  200.      */
  201.     private function getTicketCatalogsAsJson(int $pageSizeint $pageNumber): array
  202.     {
  203.         $jsonTicketData = [];
  204.         $listing = new \Pimcore\Model\DataObject\ShopTicketCatalog\Listing();
  205.         $listing->setOrderKey('sort DESC, name ASC'false);
  206.         $listing->addConditionParam('FIND_IN_SET("' TenantType::MARKETPLACE '", tenant)');
  207.         $listing->setOffset($pageNumber == : ($pageSize * ($pageNumber 1) + 1));
  208.         $listing->setLimit($pageSize);
  209.         foreach ($listing->load() as $shopTicketCatalog) {
  210.             /**
  211.              * @var ShopTicketCatalog $shopTicketCatalog
  212.              */
  213.             $catalogId $shopTicketCatalog->getId();
  214.             $teaserPrice $shopTicketCatalog->getTeaserPrice();
  215.             $galleryImages = [];
  216.             if($shopTicketCatalog->getMainImage()){
  217.                 $galleryImages[$shopTicketCatalog->getMainImage()->getId()]=$this->formatImage($shopTicketCatalog->getMainImage());
  218.             }
  219.             foreach($shopTicketCatalog->getGallery() as $galleryImage){
  220.                 $galleryImages[$galleryImage->getImage()->getId()] = $this->formatImage($galleryImage->getImage());
  221.             }
  222.             $galleryImages array_values($galleryImages);
  223.             $ticketCatalogItem = new \App\Model\BookingApi\TicketCatalog();
  224.             $ticketCatalogItem->id $catalogId;
  225.             $ticketCatalogItem->sort $shopTicketCatalog->getSort() ?: 0;
  226.             $ticketCatalogItem->images $galleryImages;
  227.             $ticketCatalogItem->interests $this->getInterests($shopTicketCatalog);
  228.             $ticketCatalogItem->category $this->getCategory($shopTicketCatalog);
  229.             $ticketCatalogItem->bookingDisabled boolval($shopTicketCatalog->getIsNotBookable());
  230.             $ticketCatalogItem->setIsUpgrade(boolval($shopTicketCatalog->getIsUpgrade()));
  231.             if(!$shopTicketCatalog->getIsUpgrade() && count($shopTicketCatalog->getUpgrades())>0){
  232.                 $upgradeInfo = [];
  233.                 foreach($shopTicketCatalog->getUpgrades() as $objectMetadata){
  234.                     $relation = new TicketCatalogUpgradeRelation();
  235.                     $relation->setUpgradeCatalogId($objectMetadata->getObject()->getId());
  236.                     $relation->setUpgradeKey($objectMetadata->getData()['name']);
  237.                     $upgradeInfo[]=$relation;
  238.                 }
  239.                 $ticketCatalogItem->setUpgradeCatalogs($upgradeInfo);
  240.             }
  241.             $ticketCatalogItem->setIsMarketplacePackage(boolval($shopTicketCatalog->getIsMarketplacePackage()));
  242.             $validDates = [];
  243.             foreach ($shopTicketCatalog->getAllValidDateRanges(Carbon::now()->startOfDay(), 'U000') as $dateRange) {
  244.                 $validDates[] = new DateRange($dateRange['from'], $dateRange['to']);
  245.             }
  246.             $ticketCatalogItem->validDates $validDates;
  247.             $ticketCatalogItem->consumerCategories $this->getConsumerCategories($shopTicketCatalog->getTicketConsumerCategories());
  248.             $ticketCatalogItem->ticketProducts $this->getTicketProducts($shopTicketCatalog);
  249.             $ticketCatalogItem->insurances $this->getInsurances($shopTicketCatalog);
  250.             $ticketCatalogItem->createdAt $shopTicketCatalog->getCreationDate() * 1000;
  251.             $ticketCatalogItem->updatedAt $shopTicketCatalog->getModificationDate() * 1000;
  252.             if ($teaserPrice) {
  253.                 $ticketCatalogItem->priceFrom $this->formatPrice($teaserPrice);
  254.             }
  255.             $ticketCatalogItem->setCustomDescriptions($this->getCustomDescriptions($shopTicketCatalog));
  256.             $ticketCatalogItem->setPriceInfos($this->getPriceInfos($shopTicketCatalog));
  257.             $name = new LocalizedText();
  258.             $description = new LocalizedText();
  259.             $topLine = new LocalizedText();
  260.             $priceDescription = new LocalizedText();
  261.             $includeDescription = new LocalizedText();
  262.             $bookingNoteDescription = new LocalizedText();
  263.             $priceInfoNote = new LocalizedText();
  264.             foreach ($this->languages as $language) {
  265.                 $topLine->$language $shopTicketCatalog->getTitleMarketplace($language) ?: '';
  266.                 $name->$language $shopTicketCatalog->getName($language) ?: '';
  267.                 $bookingNoteDescription->$language $shopTicketCatalog->getBookingNoteDescription($language) ?: '';
  268.                 $includeDescription->$language $shopTicketCatalog->getIncludeDescription($language) ?: '';
  269.                 $priceDescription->$language $shopTicketCatalog->getPriceInfoDescription($language) ?: '';
  270.                 $priceInfoNote->$language $shopTicketCatalog->getPriceInfoNote($language) ?: '';
  271.                 $description->$language $shopTicketCatalog->getMarketplaceDescription($language) ?: '';
  272.             }
  273.             $ticketCatalogItem->name $name;
  274.             $ticketCatalogItem->description $description;
  275.             $ticketCatalogItem->topLine $topLine;
  276.             $ticketCatalogItem->priceDescription $priceDescription;
  277.             $ticketCatalogItem->priceInfoNote $priceInfoNote;
  278.             $ticketCatalogItem->includeDescriptions $includeDescription;
  279.             $ticketCatalogItem->bookingNoteDescription $bookingNoteDescription;
  280.             $jsonTicketData[] = $ticketCatalogItem->jsonSerialize();
  281.         }
  282.         return [
  283.             'total' => $listing->getTotalCount(),
  284.             'pageCurrent' => intval($pageNumber),
  285.             'pageSize' => intval($pageSize),
  286.             'pageLast' => intval(ceil($listing->getTotalCount() / $pageSize)),
  287.             'ticketCatalogs' => $jsonTicketData,
  288.         ];
  289.     }
  290.     /**
  291.      * @param int $pageSize
  292.      * @param int $pageNumber
  293.      *
  294.      * @return array<string, mixed>
  295.      */
  296.     public function getEventsAsJson(int $pageSizeint $pageNumber): array
  297.     {
  298.         $listing = new \Pimcore\Model\DataObject\ShopEvent\Listing();
  299.         $listing->setOrderKey('sort ASC, name ASC'false);
  300.         $listing->addConditionParam('FIND_IN_SET("' TenantType::MARKETPLACE '", tenant)');
  301.         $listing->setOffset($pageNumber == : ($pageSize * ($pageNumber 1) + 1));
  302.         $listing->setLimit($pageSize);
  303.         $jsonEventData = [];
  304.         foreach ($listing->load() as $shopEvent) {
  305.             /**
  306.              * @var EventProduct $shopEvent
  307.              */
  308.             $apiEvent = new Event();
  309.             $apiEvent->id $shopEvent->getId();
  310.             $teaserPrice $shopEvent->getTeaserPrice();
  311.             $apiEvent->sort intval($shopEvent->getSort());
  312.             $apiEvent->images $this->getEventImages($shopEvent);
  313.             $apiEvent->bookable $shopEvent->isBookable();
  314.             $apiEvent->stopSale intval($shopEvent->getStopSale());
  315.             $apiEvent->stopSaleEndOfDay boolval($shopEvent->getBookableOnDayOfEvent());
  316.             $apiEvent->maxParticipantPerBooking $shopEvent->getMaxParticipantPerBooking() ?: 0;
  317.             $apiEvent->ageGroups $this->getEventAgeGroups($shopEvent);
  318.             $apiEvent->validDates $this->getValidEventDates($shopEvent);
  319.             $apiEvent->interests $this->getInterests($shopEvent);
  320.             $apiEvent->displayDates $shopEvent->getDisplayDates();
  321.             $apiEvent->createdAt $shopEvent->getCreationDate() * 1000;
  322.             $apiEvent->updatedAt $shopEvent->getModificationDate() * 1000;
  323.             $apiEvent->priceFrom $this->formatPrice($teaserPrice);
  324.             $apiEvent->category $this->getCategory($shopEvent);
  325.             $apiEvent->setCustomDescriptions($this->getCustomDescriptions($shopEvent));
  326.             $apiEvent->setPriceInfos($this->getPriceInfos($shopEvent));
  327.             $name = new LocalizedText();
  328.             $topLine = new LocalizedText();
  329.             $description = new LocalizedText();
  330.             $priceDescription = new LocalizedText();
  331.             $includeDescription = new LocalizedText();
  332.             $priceInfoNote = new LocalizedText();
  333.             foreach ($this->languages as $language) {
  334.                 $name->$language $shopEvent->getName($language) ?: '';
  335.                 $topLine->$language $shopEvent->getTopTitle($language) ?: '';
  336.                 $description->$language $shopEvent->getMarketplaceDescription($language) ?: '';
  337.                 $priceDescription->$language $shopEvent->getPriceInfoDescription($language) ?: '';
  338.                 $priceInfoNote->$language $shopEvent->getPriceInfoNote($language) ?: '';
  339.                 $includeDescription->$language $shopEvent->getIncludeDescription($language) ?: '';
  340.             }
  341.             $apiEvent->setName($name);
  342.             $apiEvent->setTopLine($topLine);
  343.             $apiEvent->setDescription($description);
  344.             $apiEvent->setPriceDescription($priceDescription);
  345.             $apiEvent->setPriceInfoNote($priceInfoNote);
  346.             $apiEvent->setIncludeDescription($includeDescription);
  347.             $jsonEventData[] = $apiEvent->jsonSerialize();
  348.         }
  349.         return [
  350.             'total' => $listing->getTotalCount(),
  351.             'pageCurrent' => intval($pageNumber),
  352.             'pageSize' => intval($pageSize),
  353.             'pageLast' => intval(ceil($listing->getTotalCount() / $pageSize)),
  354.             'events' => $jsonEventData,
  355.         ];
  356.     }
  357.     /**
  358.      * @param ShopTicketCatalog|EventProduct $shopTicketCatalog
  359.      *
  360.      * @return SimpleIdTextObject[]
  361.      */
  362.     private function getInterests(ShopTicketCatalog|EventProduct $shopTicketCatalog): array
  363.     {
  364.         $interests = [];
  365.         foreach ($shopTicketCatalog->getInterestsMarketplace() as $interest) {
  366.             $apiObject = new SimpleIdTextObject();
  367.             $apiObject->id $interest->getId();
  368.             $text = new LocalizedText();
  369.             foreach ($this->languages as $language) {
  370.                 $text->$language $interest->getName($language) ?: '';
  371.             }
  372.             $apiObject->texts $text;
  373.             $interests[] = $apiObject;
  374.         }
  375.         return $interests;
  376.     }
  377.     private function getCategory(ShopTicketCatalog|EventProduct $shopTicketCatalog): SimpleIdTextObject
  378.     {
  379.         $apiObject = new SimpleIdTextObject();
  380.         $category $shopTicketCatalog->getProductCategoryMarketplace();
  381.         if ($category) {
  382.             $apiObject->id $category->getId();
  383.             $texts = new LocalizedText();
  384.             foreach ($this->languages as $language) {
  385.                 $texts->$language $category->getName($language) ?: '';
  386.             }
  387.             $apiObject->texts $texts;
  388.         }
  389.         return $apiObject;
  390.     }
  391.     /**
  392.      * @param ShopTicketCatalog|EventProduct $sourceObject
  393.      *
  394.      * @return PriceInfos[]
  395.      */
  396.     private function getPriceInfos(ShopTicketCatalog|EventProduct $sourceObject): array
  397.     {
  398.         $priceInfos = [];
  399.         if ($sourceObject->getPriceInfos()) {
  400.             foreach ($sourceObject->getPriceInfos() as $priceInfoItem) {
  401.                 /**
  402.                  * @var PriceInfo $priceInfoItem
  403.                  */
  404.                 $priceInfo = new PriceInfos();
  405.                 $title = new LocalizedText();
  406.                 $additionalInfo = new LocalizedText();
  407.                 $ageGroupInfo = new LocalizedText();
  408.                 $priceInfoText = new LocalizedText();
  409.                 foreach ($this->languages as $language) {
  410.                     $title->$language $priceInfoItem->getTitle($language) ?: '';
  411.                     $additionalInfo->$language $priceInfoItem->getAdditionalInfo($language) ?: '';
  412.                     $ageGroupInfo->$language $priceInfoItem->getAgeGroup($language) ?: '';
  413.                     $priceInfoText->$language $priceInfoItem->getPriceInfoText($language) ?: '';
  414.                 }
  415.                 $priceInfo->setTitle($title);
  416.                 $priceInfo->setAdditionalInfo($additionalInfo);
  417.                 $priceInfo->setAgeGroupText($ageGroupInfo);
  418.                 $priceInfo->setPriceInfoText($priceInfoText);
  419.                 $priceInfos[] = $priceInfo;
  420.             }
  421.         }
  422.         return $priceInfos;
  423.     }
  424.     /**
  425.      * @param ShopTicketCatalog|EventProduct $sourceObject
  426.      *
  427.      * @return TextWithHeadline[]
  428.      */
  429.     private function getCustomDescriptions(ShopTicketCatalog|EventProduct $sourceObject): array
  430.     {
  431.         $customDescriptions = [];
  432.         foreach ($sourceObject->getCustomDescriptions() ?: [] as $customDescriptionItem) {
  433.             /**
  434.              * @var CustomDescription $customDescriptionItem
  435.              */
  436.             $localizedHeadine = new LocalizedText();
  437.             $localizedText = new LocalizedText();
  438.             $customDescription = new TextWithHeadline();
  439.             foreach ($this->languages as $language) {
  440.                 $localizedHeadine->$language $customDescriptionItem->getCustomHeadline($language) ?: '';
  441.                 $localizedText->$language $customDescriptionItem->getCustomDescription($language) ?: '';
  442.             }
  443.             $customDescription->headline $localizedHeadine;
  444.             $customDescription->text $localizedText;
  445.             $customDescriptions[] = $customDescription;
  446.         }
  447.         return $customDescriptions;
  448.     }
  449.     /**
  450.      * @param ShopTicketCatalog $ticketCatalog
  451.      *
  452.      * @return \App\Model\BookingApi\TicketProduct[]
  453.      */
  454.     private function getTicketProducts(ShopTicketCatalog $ticketCatalog): array
  455.     {
  456.         $siteConfig $this->siteConfigService->getSiteConfig();
  457.         $ticketData = [];
  458.         foreach ($ticketCatalog->getTicketProducts() as $ticketProduct) {
  459.             /**
  460.              * @var  \Elements\Bundle\TicketShopFrameworkBundle\Model\DataObject\TicketProduct $ticketProduct
  461.              */
  462.             $apiTicketProduct = new \App\Model\BookingApi\TicketProduct();
  463.             $apiTicketProduct->id $ticketProduct->getId();
  464.             $localizedName = new LocalizedText();
  465.             $localizedInfoText = new LocalizedText();
  466.             $localizedCatalogInfoText = new LocalizedText();
  467.             foreach ($this->languages as $language) {
  468.                 $localizedName->$language $ticketProduct->getName($language) ?: '';
  469.                 $localizedCatalogInfoText->$language $ticketCatalog->getInfoBubbleDescription($language) ?: '';
  470.                 $localizedInfoText->$language $ticketProduct->getDescription($language) ?: '';
  471.             }
  472.             $apiTicketProduct->name $localizedName;
  473.             $apiTicketProduct->infoText $localizedInfoText;
  474.             $apiTicketProduct->infoTextCatalog $localizedCatalogInfoText;
  475.             //hide acquisition types if set so in config
  476.             $acquisitionTypes array_diff($ticketProduct->getAllowedAcquisitionTypes(), ($siteConfig->getHideAcquisitionTypes() ?? []));
  477.             $apiTicketProduct->acquisitionTypes $acquisitionTypes ?: [];
  478.             $apiTicketProduct->defaultAcquisitionType $ticketProduct->getDefaultAcquisitionType() ?: '';
  479.             $apiTicketProduct->personalization $ticketProduct->getRequirements() ?: [];
  480.             $validity = new TicketValidity();
  481.             $validity->validityValue $ticketProduct->getValidityValue();
  482.             $validity->validityUnit $ticketProduct->getValidityUnit();
  483.             $apiTicketProduct->validity $validity;
  484.             $ticketData[] = $apiTicketProduct;
  485.         }
  486.         return $ticketData;
  487.     }
  488.     /**
  489.      * @param ShopTicketCatalog $shopTicketCatalog
  490.      *
  491.      * @return TicketInsurance[]
  492.      */
  493.     private function getInsurances(ShopTicketCatalog $shopTicketCatalog): array
  494.     {
  495.         $insurances = [];
  496.         foreach ($shopTicketCatalog->getInsurances() as $insurance) {
  497.             $apiInsurance = new TicketInsurance();
  498.             $apiInsurance->id $insurance->getId();
  499.             $localizedName = new LocalizedText();
  500.             $localizedDescription = new LocalizedText();
  501.             foreach ($this->languages as $language) {
  502.                 $localizedName->$language $insurance->getName($language) ?: '';
  503.                 $localizedDescription->$language $insurance->getDescription($language) ?: '';
  504.             }
  505.             $apiInsurance->name $localizedName;
  506.             $apiInsurance->description $localizedDescription;
  507.             $insurances[] = $apiInsurance;
  508.         }
  509.         return $insurances;
  510.     }
  511.     /**
  512.      * @param ShopEvent $shopEvent
  513.      *
  514.      * @return Image[]
  515.      */
  516.     private function getEventImages(ShopEvent $shopEvent): array
  517.     {
  518.         $imageData = [];
  519.         if($shopEvent->getMainImage()){
  520.             $imageData[$shopEvent->getMainImage()->getId()]= $this->formatImage($shopEvent->getMainImage());
  521.         }
  522.         foreach ($shopEvent->getImages() as $image) {
  523.             if ($image instanceof \Pimcore\Model\DataObject\Data\Hotspotimage) {
  524.                 $image $image->getImage();
  525.             }
  526.             $imageData[$image->getId()] = $this->formatImage($image);
  527.         }
  528.         return array_values($imageData);
  529.     }
  530.     /**
  531.      * @param EventProduct $shopEvent
  532.      *
  533.      * @return array<mixed>
  534.      */
  535.     private function getValidEventDates(EventProduct $shopEvent): array
  536.     {
  537.         $ranges $shopEvent->getAllValidDateRanges(Carbon::now()->startOfDay(), null);
  538.         $dates = [];
  539.         foreach ($ranges as $range) {
  540.             $dates[] = [
  541.                 'from' => $range['from']->getTimestamp() * 1000,
  542.                 'to' => $range['to']->getTimestamp() * 1000,
  543.                 'availability' => $this->getAvailability($range['from'], $range['to'], $shopEvent),
  544.             ];
  545.         }
  546.         return $dates;
  547.     }
  548.     /**
  549.      * @param Carbon $from
  550.      * @param Carbon $to
  551.      * @param EventProduct $shopEvent
  552.      *
  553.      * @return array<int,int>
  554.      */
  555.     private function getAvailability(Carbon $fromCarbon $toEventProduct $shopEvent): array
  556.     {
  557.         $availability = [];
  558.         /**
  559.          * @var \App\Ecommerce\AvailabilitySystem\Event\AvailabilitySystem $availabilitySystem
  560.          */
  561.         $availabilitySystem $shopEvent->getAvailabilitySystemImplementation();
  562.         $items $availabilitySystem->getAvailableList($shopEvent$from$to);
  563.         foreach ($items as $key => $item) {
  564.             $timeStampMs intval($key) * 1000;
  565.             $availability[$timeStampMs] = $item->getAvailableQuota() <= $item->getAvailableQuota();
  566.         }
  567.         return $availability;
  568.     }
  569.     /**
  570.      * @param ShopEvent $shopEvent
  571.      *
  572.      * @return EventAgeGroupPrice[]
  573.      */
  574.     private function getEventAgeGroups(ShopEvent $shopEvent): array
  575.     {
  576.         $eventAgeGroupsData = [];
  577.         $dynamicPrices $shopEvent->getPrices() ?: [];
  578.         foreach ($dynamicPrices as $dynamicPrice) {
  579.             /**
  580.              * @var ObjectMetadata $dynamicPrice
  581.              */
  582.             $groupName '';
  583.             if(in_array('groupname'$dynamicPrice->getColumns())){
  584.                 if(isset($dynamicPrice->getData()['groupname'])){
  585.                     $groupName $dynamicPrice->getData()['groupname'];
  586.                 }
  587.             }
  588.             $dynamicPriceObject $dynamicPrice->getObject();
  589.             if ($dynamicPriceObject instanceof ShopDynamicPrice) {
  590.                 $ageGroupData = new EventAgeGroupPrice();
  591.                 $ageGroupData->setId($dynamicPriceObject->getId());
  592.                 $ageGroupData->setPrice($this->formatPrice($dynamicPriceObject->getDefaultPrice()));
  593.                 $localizedTexts = new LocalizedText();
  594.                 $localizedGroupName = new LocalizedText();
  595.                 foreach ($this->languages as $language) {
  596.                     $localizedTexts->$language $dynamicPriceObject->getPriceLabel($language);
  597.                     if(!empty($groupName)) {
  598.                         $localizedGroupName->$language $this->translator->trans($groupName, [], null$language);
  599.                     }
  600.                 }
  601.                 if(!empty($groupName)){
  602.                     $ageGroupData->setGroupName($groupName);
  603.                     $ageGroupData->setGroupNameTexts($localizedGroupName);
  604.                 }
  605.                 $ageGroupData->setName($localizedTexts);
  606.                 $eventAgeGroupsData[] = $ageGroupData;
  607.             }
  608.         }
  609.         return $eventAgeGroupsData;
  610.     }
  611. }