src/Module/ShortSimpleCheckout/Controller/ShippingPaymentController.php line 51

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Module\ShortSimpleCheckout\Controller;
  4. use App\Module\ShortSimpleCheckout\Controller\Facade\ShippingPaymentControllerFacadeInterface;
  5. use App\Module\ShortSimpleCheckout\Customer\CustomerInterface;
  6. use App\Module\ShortSimpleCheckout\EventListener\Cart\CartFilledInterface;
  7. use Commercetools\Core\Model\Cart\Cart;
  8. use Symfony\Component\HttpFoundation\JsonResponse;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Twig\Environment as TwigEnvironment;
  12. /**
  13. * Simple display of the shipping payment page.
  14. *
  15. * @author Michel Chowanski <chowanski@bestit-online.de>
  16. * @package App\Module\ShortSimpleCheckout\Controller
  17. */
  18. class ShippingPaymentController implements CartFilledInterface
  19. {
  20. private ShippingPaymentControllerFacadeInterface $facade;
  21. private TwigEnvironment $twig;
  22. private string $template;
  23. /**
  24. * @param ShippingPaymentControllerFacadeInterface $facade
  25. * @param TwigEnvironment $twig
  26. * @param string $template
  27. */
  28. public function __construct(
  29. ShippingPaymentControllerFacadeInterface $facade,
  30. TwigEnvironment $twig,
  31. string $template
  32. ) {
  33. $this->facade = $facade;
  34. $this->twig = $twig;
  35. $this->template = $template;
  36. }
  37. /**
  38. * Display the shipping payment page for the given cart.
  39. *
  40. * @param Cart $cart
  41. * @param CustomerInterface $customer
  42. *
  43. * @return Response
  44. */
  45. public function indexAction(Cart $cart, CustomerInterface $customer): Response
  46. {
  47. $content = $this->twig->render(
  48. $this->template,
  49. ['best_it_short_simple_checkout' => $this->facade->getDataForIndexAction($cart, $customer)]
  50. );
  51. return new Response($content);
  52. }
  53. /**
  54. * Sets the payment
  55. *
  56. * @param Cart $cart
  57. * @param CustomerInterface $customer
  58. * @param Request $request
  59. *
  60. * @return JsonResponse
  61. */
  62. public function selectPaymentTypeAction(Cart $cart, CustomerInterface $customer, Request $request): JsonResponse
  63. {
  64. $paymentType = $request->request->get('paymentType');
  65. return $this->facade->selectPaymentType(
  66. $paymentType,
  67. $cart,
  68. $customer
  69. );
  70. }
  71. /**
  72. * Sets the billing address.
  73. *
  74. * @param Cart $cart
  75. * @param CustomerInterface $customer
  76. * @param Request $request
  77. *
  78. * @return JsonResponse
  79. */
  80. public function selectBillingAddressAction(Cart $cart, CustomerInterface $customer, Request $request): JsonResponse
  81. {
  82. return $this->facade->selectBillingAddress(
  83. $request->request->get('billingAddressId'),
  84. $cart,
  85. $customer
  86. );
  87. }
  88. /**
  89. * Sets the shipping address.
  90. *
  91. * @param Cart $cart
  92. * @param CustomerInterface $customer
  93. * @param Request $request
  94. *
  95. * @return JsonResponse
  96. */
  97. public function selectShippingAddressAction(Cart $cart, CustomerInterface $customer, Request $request): JsonResponse
  98. {
  99. return $this->facade->selectShippingAddress(
  100. $request->request->get('shippingAddressId'),
  101. $cart,
  102. $customer
  103. );
  104. }
  105. /**
  106. * Sets the shipping type
  107. *
  108. * @param Cart $cart
  109. * @param CustomerInterface $customer
  110. * @param Request $request
  111. *
  112. * @return JsonResponse
  113. */
  114. public function selectShippingTypeAction(Cart $cart, CustomerInterface $customer, Request $request): JsonResponse
  115. {
  116. //Differne Shipper HQ types
  117. $shippingType = $request->request->get('shippingType');
  118. return $this->facade->selectShippingType(
  119. $shippingType,
  120. $cart,
  121. $customer
  122. );
  123. }
  124. }