<?php
declare(strict_types=1);
namespace Slivki\Controller\OnlineOrder\Vendor;
use Slivki\Controller\SiteController;
use Slivki\Services\ImageService;
use Slivki\Services\Offer\CustomProductOfferSorter;
use Slivki\Services\Offer\OfferCacheService;
use Slivki\Util\Iiko\AbstractDelivery;
use Slivki\Util\Iiko\SushiVesla;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Routing\Annotation\Route;
final class GetDishOptionsAction extends SiteController
{
private ImageService $imageService;
private OfferCacheService $offerCacheService;
private CustomProductOfferSorter $customProductOfferSorter;
public function __construct(
ImageService $imageService,
OfferCacheService $offerCacheService,
CustomProductOfferSorter $customProductOfferSorter,
KernelInterface $kernel
) {
parent::__construct($kernel);
$this->imageService = $imageService;
$this->offerCacheService = $offerCacheService;
$this->customProductOfferSorter = $customProductOfferSorter;
}
/**
* @Route("/delivery/online-order/offer/{offerId}/dish-options",
* name="delviery_online_order_offer_dish_options",
* requirements={"offerId"="\d+"},
* methods={"GET"}
* )
*/
public function __invoke(int $offerId): Response
{
$offer = $this->offerCacheService->getOffer($offerId, true, true);
$util = AbstractDelivery::instance($offer);
$util->setContainer($this->kernel->getContainer());
$options = $util instanceof SushiVesla
? $util->getOptionsDB($this->imageService)
: $this->getOptions($this->imageService, $offer, $util, 0);
return $this->render('Slivki/delivery/dish/bill_dish_options.html.twig', [
'options' => $this->customProductOfferSorter->sort($options, CustomProductOfferSorter::DEFAULT_CUSTOM_PRODUCT_SORT),
]);
}
}