<?php
namespace App\Action;
use App\Module\Inquiry\Business\Builder\InquiryDataBuilder;
use App\Module\ShortSimpleCheckout\Controller\CartController as BaseCartController;
use App\Module\ShortSimpleCheckout\Controller\Facade\CartControllerFacadeInterface;
use App\Module\ShortSimpleCheckout\Customer\CustomerInterface;
use App\Module\ShortSimpleCheckout\Normalizer\CartNormalizerInterface;
use App\Module\ShortSimpleCheckout\EventListener\Cart\CartValidateInterface;
use App\Module\ShortSimpleCheckout\Resolver\SkuResolver;
use Commercetools\Core\Model\Cart\Cart;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment as TwigEnvironment;
/**
* Class CartController
*
* @package App\Action
*/
class CartController extends BaseCartController implements CartValidateInterface
{
private InquiryDataBuilder $inquiryDataBuilder;
protected CartNormalizerInterface $cartNormalizer;
/**
* CartController constructor.
*
* @param CartControllerFacadeInterface $facade
* @param TwigEnvironment $twig
* @param string $template
* @param SkuResolver $skuResolver
* @param TranslatorInterface $translator
*/
public function __construct(
CartControllerFacadeInterface $facade,
TwigEnvironment $twig,
string $template,
SkuResolver $skuResolver,
InquiryDataBuilder $inquiryDataBuilder,
CartNormalizerInterface $cartNormalizer,
TranslatorInterface $translator
) {
parent::__construct($facade, $twig, $template, $skuResolver, $translator);
$this->cartNormalizer = $cartNormalizer;
$this->inquiryDataBuilder = $inquiryDataBuilder;
}
/**
* @param Cart $cart
* @param CustomerInterface $customer
* @return Response
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
public function indexAction(Cart $cart, CustomerInterface $customer): Response
{
$content = $this->twig->render(
$this->template,
[
'best_it_short_simple_checkout' => $this->facade->getDataForIndexAction($cart, $customer),
'products' => $this->inquiryDataBuilder->buildFromCart($cart)
]
);
return new Response($content);
}
/**
* Get cart
*
* @param Cart $cart
* @param CustomerInterface $customer
*
* @return JsonResponse
*/
public function getCartAction(Cart $cart, CustomerInterface $customer): JsonResponse
{
return $this->facade->getCart($cart, $customer);
}
}