123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Multishipping\Controller\Checkout;
- use Magento\Multishipping\Model\Checkout\Type\Multishipping\State;
- use Magento\Customer\Api\AccountManagementInterface;
- use Magento\Customer\Api\CustomerRepositoryInterface;
- use Magento\Framework\Exception\PaymentException;
- use Magento\Framework\Session\SessionManagerInterface;
- /**
- * Class OverviewPost
- *
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
- class OverviewPost extends \Magento\Multishipping\Controller\Checkout
- {
- /**
- * @var \Magento\Framework\Data\Form\FormKey\Validator
- */
- protected $formKeyValidator;
- /**
- * @var \Psr\Log\LoggerInterface
- */
- protected $logger;
- /**
- * @var \Magento\Checkout\Api\AgreementsValidatorInterface
- */
- protected $agreementsValidator;
- /**
- * @var SessionManagerInterface
- */
- private $session;
- /**
- * @param \Magento\Framework\App\Action\Context $context
- * @param \Magento\Customer\Model\Session $customerSession
- * @param CustomerRepositoryInterface $customerRepository
- * @param AccountManagementInterface $accountManagement
- * @param \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator
- * @param \Psr\Log\LoggerInterface $logger
- * @param \Magento\Checkout\Api\AgreementsValidatorInterface $agreementValidator
- * @param SessionManagerInterface $session
- */
- public function __construct(
- \Magento\Framework\App\Action\Context $context,
- \Magento\Customer\Model\Session $customerSession,
- CustomerRepositoryInterface $customerRepository,
- AccountManagementInterface $accountManagement,
- \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator,
- \Psr\Log\LoggerInterface $logger,
- \Magento\Checkout\Api\AgreementsValidatorInterface $agreementValidator,
- SessionManagerInterface $session
- ) {
- $this->formKeyValidator = $formKeyValidator;
- $this->logger = $logger;
- $this->agreementsValidator = $agreementValidator;
- $this->session = $session;
- parent::__construct(
- $context,
- $customerSession,
- $customerRepository,
- $accountManagement
- );
- }
- /**
- * Overview action
- *
- * @return void
- * @SuppressWarnings(PHPMD.CyclomaticComplexity)
- */
- public function execute()
- {
- if (!$this->formKeyValidator->validate($this->getRequest())) {
- $this->_forward('backToAddresses');
- return;
- }
- if (!$this->_validateMinimumAmount()) {
- return;
- }
- try {
- if (!$this->agreementsValidator->isValid(array_keys($this->getRequest()->getPost('agreement', [])))) {
- $this->messageManager->addError(
- __('Please agree to all Terms and Conditions before placing the order.')
- );
- $this->_redirect('*/*/billing');
- return;
- }
- $payment = $this->getRequest()->getPost('payment');
- $paymentInstance = $this->_getCheckout()->getQuote()->getPayment();
- if (isset($payment['cc_number'])) {
- $paymentInstance->setCcNumber($payment['cc_number']);
- }
- if (isset($payment['cc_cid'])) {
- $paymentInstance->setCcCid($payment['cc_cid']);
- }
- $this->_getCheckout()->createOrders();
- $this->_getState()->setCompleteStep(State::STEP_OVERVIEW);
- if ($this->session->getAddressErrors()) {
- $this->_getState()->setActiveStep(State::STEP_RESULTS);
- $this->_redirect('*/*/results');
- } else {
- $this->_getState()->setActiveStep(State::STEP_SUCCESS);
- $this->_getCheckout()->getCheckoutSession()->clearQuote();
- $this->_getCheckout()->getCheckoutSession()->setDisplaySuccess(true);
- $this->_redirect('*/*/success');
- }
- } catch (PaymentException $e) {
- $message = $e->getMessage();
- if (!empty($message)) {
- $this->messageManager->addError($message);
- }
- $this->_redirect('*/*/billing');
- } catch (\Magento\Checkout\Exception $e) {
- $this->_objectManager->get(
- \Magento\Checkout\Helper\Data::class
- )->sendPaymentFailedEmail(
- $this->_getCheckout()->getQuote(),
- $e->getMessage(),
- 'multi-shipping'
- );
- $this->_getCheckout()->getCheckoutSession()->clearQuote();
- $this->messageManager->addError($e->getMessage());
- $this->_redirect('*/cart');
- } catch (\Magento\Framework\Exception\LocalizedException $e) {
- $this->_objectManager->get(
- \Magento\Checkout\Helper\Data::class
- )->sendPaymentFailedEmail(
- $this->_getCheckout()->getQuote(),
- $e->getMessage(),
- 'multi-shipping'
- );
- $this->messageManager->addError($e->getMessage());
- $this->_redirect('*/*/billing');
- } catch (\Exception $e) {
- $this->logger->critical($e);
- try {
- $this->_objectManager->get(
- \Magento\Checkout\Helper\Data::class
- )->sendPaymentFailedEmail(
- $this->_getCheckout()->getQuote(),
- $e->getMessage(),
- 'multi-shipping'
- );
- } catch (\Exception $e) {
- $this->logger->error($e->getMessage());
- }
- $this->messageManager->addError(__('Order place error'));
- $this->_redirect('*/*/billing');
- }
- }
- }
|