DelegateCreate.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\Checkout\Controller\Account;
  8. use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
  9. use Magento\Framework\App\Action\Action;
  10. use Magento\Framework\App\Action\Context;
  11. use Magento\Checkout\Model\Session;
  12. use Magento\Sales\Api\OrderCustomerDelegateInterface;
  13. /**
  14. * Redirect guest customer for registration.
  15. */
  16. class DelegateCreate extends Action implements HttpGetActionInterface
  17. {
  18. /**
  19. * @var OrderCustomerDelegateInterface
  20. */
  21. private $delegateService;
  22. /**
  23. * @var Session
  24. */
  25. private $session;
  26. /**
  27. * @param Context $context
  28. * @param OrderCustomerDelegateInterface $customerDelegation
  29. * @param Session $session
  30. */
  31. public function __construct(
  32. Context $context,
  33. OrderCustomerDelegateInterface $customerDelegation,
  34. Session $session
  35. ) {
  36. parent::__construct($context);
  37. $this->delegateService = $customerDelegation;
  38. $this->session = $session;
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function execute()
  44. {
  45. /** @var string|null $orderId */
  46. $orderId = $this->session->getLastOrderId();
  47. if (!$orderId) {
  48. return $this->resultRedirectFactory->create()->setPath('/');
  49. }
  50. return $this->delegateService->delegateNew((int)$orderId);
  51. }
  52. }