Skip to content

Commit bd5ac74

Browse files
author
Maksym Savich
committed
Merge remote-tracking branch 'upstream/develop' into MAGETWO-39988-cache-refresh
2 parents f2ae226 + ec6d4e6 commit bd5ac74

File tree

597 files changed

+38331
-7871
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

597 files changed

+38331
-7871
lines changed

app/code/Magento/Authorizenet/Controller/Directpost/Payment/Place.php

Lines changed: 80 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,44 @@
66
*/
77
namespace Magento\Authorizenet\Controller\Directpost\Payment;
88

9-
class Place extends \Magento\Authorizenet\Controller\Directpost\Payment
9+
use Magento\Authorizenet\Controller\Directpost\Payment;
10+
use Magento\Authorizenet\Helper\DataFactory;
11+
use Magento\Checkout\Model\Type\Onepage;
12+
use Magento\Framework\App\Action\Context;
13+
use Magento\Framework\Event\ManagerInterface;
14+
use Magento\Framework\Object;
15+
use Magento\Framework\Registry;
16+
use Magento\Payment\Model\IframeConfigProvider;
17+
use Magento\Quote\Api\CartManagementInterface;
18+
19+
/**
20+
* Class Place
21+
*
22+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
23+
*/
24+
class Place extends Payment
1025
{
1126
/**
12-
* @var \Magento\Quote\Api\CartManagementInterface
27+
* @var CartManagementInterface
1328
*/
1429
protected $cartManagement;
1530

1631
/**
17-
* @var \Magento\Framework\Event\ManagerInterface
32+
* @var ManagerInterface
1833
*/
1934
protected $eventManager;
2035

2136
/**
22-
* @param \Magento\Framework\App\Action\Context $context
23-
* @param \Magento\Framework\Registry $coreRegistry
24-
* @param \Magento\Authorizenet\Helper\DataFactory $dataFactory
25-
* @param \Magento\Quote\Api\CartManagementInterface $cartManagement
37+
* @param Context $context
38+
* @param Registry $coreRegistry
39+
* @param DataFactory $dataFactory
40+
* @param CartManagementInterface $cartManagement
2641
*/
2742
public function __construct(
28-
\Magento\Framework\App\Action\Context $context,
29-
\Magento\Framework\Registry $coreRegistry,
30-
\Magento\Authorizenet\Helper\DataFactory $dataFactory,
31-
\Magento\Quote\Api\CartManagementInterface $cartManagement
43+
Context $context,
44+
Registry $coreRegistry,
45+
DataFactory $dataFactory,
46+
CartManagementInterface $cartManagement
3247
) {
3348
$this->eventManager = $context->getEventManager();
3449
$this->cartManagement = $cartManagement;
@@ -44,10 +59,12 @@ public function execute()
4459
{
4560
$paymentParam = $this->getRequest()->getParam('payment');
4661
$controller = $this->getRequest()->getParam('controller');
62+
4763
if (isset($paymentParam['method'])) {
4864
$this->_getDirectPostSession()->setQuoteId($this->_getCheckout()->getQuote()->getId());
65+
$this->_getCheckout()->getQuote()->setCheckoutMethod($this->getCheckoutMethod());
4966

50-
if ($controller == \Magento\Payment\Model\IframeConfigProvider::CHECKOUT_IDENTIFIER) {
67+
if ($controller == IframeConfigProvider::CHECKOUT_IDENTIFIER) {
5168
return $this->placeCheckoutOrder();
5269
}
5370

@@ -64,10 +81,32 @@ public function execute()
6481
);
6582
} else {
6683
$result = ['error_messages' => __('Please choose a payment method.'), 'goto_section' => 'payment'];
67-
$this->getResponse()->representJson(
68-
$this->_objectManager->get('Magento\Framework\Json\Helper\Data')->jsonEncode($result)
69-
);
84+
$this->getResponse()->representJson($this->getJsonHelper()->jsonEncode($result));
85+
}
86+
}
87+
88+
/**
89+
* Get quote checkout method
90+
*
91+
* @return string
92+
*/
93+
protected function getCheckoutMethod()
94+
{
95+
$checkoutMethod = $this->_getCheckout()->getQuote()->getCheckoutMethod();
96+
97+
if ($this->getCustomerSession()->isLoggedIn()) {
98+
$checkoutMethod = Onepage::METHOD_CUSTOMER;
99+
}
100+
101+
if (!$checkoutMethod) {
102+
if ($this->getCheckoutHelper()->isAllowedGuestCheckout($this->_getCheckout()->getQuote())) {
103+
$checkoutMethod = Onepage::METHOD_GUEST;
104+
} else {
105+
$checkoutMethod = Onepage::METHOD_REGISTER;
106+
}
70107
}
108+
109+
return $checkoutMethod;
71110
}
72111

73112
/**
@@ -77,7 +116,7 @@ public function execute()
77116
*/
78117
protected function placeCheckoutOrder()
79118
{
80-
$result = new \Magento\Framework\Object();
119+
$result = new Object();
81120
try {
82121
$this->cartManagement->placeOrder($this->_getCheckout()->getQuote()->getId());
83122
$result->setData('success', true);
@@ -92,8 +131,30 @@ protected function placeCheckoutOrder()
92131
$result->setData('error', true);
93132
$result->setData('error_messages', __('Cannot place order.'));
94133
}
95-
$this->getResponse()->representJson(
96-
$this->_objectManager->get('Magento\Framework\Json\Helper\Data')->jsonEncode($result)
97-
);
134+
$this->getResponse()->representJson($this->getJsonHelper()->jsonEncode($result));
135+
}
136+
137+
/**
138+
* @return \Magento\Customer\Model\Session
139+
*/
140+
protected function getCustomerSession()
141+
{
142+
return $this->_objectManager->get('Magento\Checkout\Model\Cart')->getCustomerSession();
143+
}
144+
145+
/**
146+
* @return \Magento\Checkout\Helper\Data
147+
*/
148+
protected function getCheckoutHelper()
149+
{
150+
return $this->_objectManager->get('Magento\Checkout\Helper\Data');
151+
}
152+
153+
/**
154+
* @return \Magento\Framework\Json\Helper\Data
155+
*/
156+
protected function getJsonHelper()
157+
{
158+
return $this->_objectManager->get('Magento\Framework\Json\Helper\Data');
98159
}
99160
}

0 commit comments

Comments
 (0)