<?php
/**
* @category NetiNextModal
* @author bmueller
*/
namespace NetInventors\NetiNextModal\Storefront\Controller;
use NetInventors\NetiNextModal\Services\ModalCriteriaBuilderInterface;
use NetInventors\NetiNextModal\Services\ModalFilterServiceInterface;
use NetInventors\NetiNextModal\Services\ModalServiceInterface;
use NetInventors\NetiNextModal\Storefront\Controller\Traits\ContentBuilderTrait;
use NetInventors\NetiNextModal\Storefront\Controller\Traits\CriteriaTrait;
use NetInventors\NetiNextModal\Storefront\Controller\Traits\ResultTrait;
use Shopware\Core\Content\Cms\SalesChannel\SalesChannelCmsPageLoaderInterface;
use Shopware\Core\Framework\Routing\Annotation\RouteScope;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Shopware\Storefront\Controller\StorefrontController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
/**
* @RouteScope(scopes={"storefront"})
*/
class NetiModalController extends StorefrontController
{
use ContentBuilderTrait;
use CriteriaTrait;
use ResultTrait;
/**
* @var ModalServiceInterface
*/
protected $modalService;
/**
* @var ModalFilterServiceInterface
*/
protected $filterService;
/**
* NetiModalController constructor.
*
* @param ModalServiceInterface $modalService
* @param ModalCriteriaBuilderInterface $criteriaBuilder
* @param ModalFilterServiceInterface $filterService
* @param SalesChannelCmsPageLoaderInterface $cmsPageLoader
*/
public function __construct(
ModalServiceInterface $modalService,
ModalCriteriaBuilderInterface $criteriaBuilder,
ModalFilterServiceInterface $filterService,
SalesChannelCmsPageLoaderInterface $cmsPageLoader
) {
$this->modalService = $modalService;
$this->criteriaBuilder = $criteriaBuilder;
$this->filterService = $filterService;
$this->cmsPageLoader = $cmsPageLoader;
}
/**
* @Route(
* "/neti_next_modal/get_box",
* name="frontend.neti_next_modal.get_box",
* options={"seo"="false"},
* methods={"GET"},
* defaults={"XmlHttpRequest"=true}
* )
* @param Request $request
* @param SalesChannelContext $salesChannelContext
*
* @return JsonResponse
*/
public function getBox(Request $request, SalesChannelContext $salesChannelContext): JsonResponse
{
$context = $salesChannelContext->getContext();
return $this->handleResult(
$request,
$salesChannelContext,
$this->filterService->filterModals(
$this->modalService->findModals(
$this->buildCriteria(
$request
),
$context
),
$request,
$context
)->last()
);
}
}