src/Action/CartController.php line 59

Open in your IDE?
  1. <?php
  2. namespace App\Action;
  3. use App\Module\Inquiry\Business\Builder\InquiryDataBuilder;
  4. use App\Module\ShortSimpleCheckout\Controller\CartController as BaseCartController;
  5. use App\Module\ShortSimpleCheckout\Controller\Facade\CartControllerFacadeInterface;
  6. use App\Module\ShortSimpleCheckout\Customer\CustomerInterface;
  7. use App\Module\ShortSimpleCheckout\Normalizer\CartNormalizerInterface;
  8. use App\Module\ShortSimpleCheckout\EventListener\Cart\CartValidateInterface;
  9. use App\Module\ShortSimpleCheckout\Resolver\SkuResolver;
  10. use Commercetools\Core\Model\Cart\Cart;
  11. use Symfony\Component\HttpFoundation\JsonResponse;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Contracts\Translation\TranslatorInterface;
  14. use Twig\Environment as TwigEnvironment;
  15. /**
  16. * Class CartController
  17. *
  18. * @package App\Action
  19. */
  20. class CartController extends BaseCartController implements CartValidateInterface
  21. {
  22. private InquiryDataBuilder $inquiryDataBuilder;
  23. protected CartNormalizerInterface $cartNormalizer;
  24. /**
  25. * CartController constructor.
  26. *
  27. * @param CartControllerFacadeInterface $facade
  28. * @param TwigEnvironment $twig
  29. * @param string $template
  30. * @param SkuResolver $skuResolver
  31. * @param TranslatorInterface $translator
  32. */
  33. public function __construct(
  34. CartControllerFacadeInterface $facade,
  35. TwigEnvironment $twig,
  36. string $template,
  37. SkuResolver $skuResolver,
  38. InquiryDataBuilder $inquiryDataBuilder,
  39. CartNormalizerInterface $cartNormalizer,
  40. TranslatorInterface $translator
  41. ) {
  42. parent::__construct($facade, $twig, $template, $skuResolver, $translator);
  43. $this->cartNormalizer = $cartNormalizer;
  44. $this->inquiryDataBuilder = $inquiryDataBuilder;
  45. }
  46. /**
  47. * @param Cart $cart
  48. * @param CustomerInterface $customer
  49. * @return Response
  50. * @throws \Twig\Error\LoaderError
  51. * @throws \Twig\Error\RuntimeError
  52. * @throws \Twig\Error\SyntaxError
  53. */
  54. public function indexAction(Cart $cart, CustomerInterface $customer): Response
  55. {
  56. $content = $this->twig->render(
  57. $this->template,
  58. [
  59. 'best_it_short_simple_checkout' => $this->facade->getDataForIndexAction($cart, $customer),
  60. 'products' => $this->inquiryDataBuilder->buildFromCart($cart)
  61. ]
  62. );
  63. return new Response($content);
  64. }
  65. /**
  66. * Get cart
  67. *
  68. * @param Cart $cart
  69. * @param CustomerInterface $customer
  70. *
  71. * @return JsonResponse
  72. */
  73. public function getCartAction(Cart $cart, CustomerInterface $customer): JsonResponse
  74. {
  75. return $this->facade->getCart($cart, $customer);
  76. }
  77. }