6
6
*/
7
7
namespace Magento \Authorizenet \Controller \Directpost \Payment ;
8
8
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
10
25
{
11
26
/**
12
- * @var \Magento\Quote\Api\ CartManagementInterface
27
+ * @var CartManagementInterface
13
28
*/
14
29
protected $ cartManagement ;
15
30
16
31
/**
17
- * @var \Magento\Framework\Event\ ManagerInterface
32
+ * @var ManagerInterface
18
33
*/
19
34
protected $ eventManager ;
20
35
21
36
/**
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
26
41
*/
27
42
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
32
47
) {
33
48
$ this ->eventManager = $ context ->getEventManager ();
34
49
$ this ->cartManagement = $ cartManagement ;
@@ -44,10 +59,12 @@ public function execute()
44
59
{
45
60
$ paymentParam = $ this ->getRequest ()->getParam ('payment ' );
46
61
$ controller = $ this ->getRequest ()->getParam ('controller ' );
62
+
47
63
if (isset ($ paymentParam ['method ' ])) {
48
64
$ this ->_getDirectPostSession ()->setQuoteId ($ this ->_getCheckout ()->getQuote ()->getId ());
65
+ $ this ->_getCheckout ()->getQuote ()->setCheckoutMethod ($ this ->getCheckoutMethod ());
49
66
50
- if ($ controller == \ Magento \ Payment \ Model \ IframeConfigProvider::CHECKOUT_IDENTIFIER ) {
67
+ if ($ controller == IframeConfigProvider::CHECKOUT_IDENTIFIER ) {
51
68
return $ this ->placeCheckoutOrder ();
52
69
}
53
70
@@ -64,10 +81,32 @@ public function execute()
64
81
);
65
82
} else {
66
83
$ 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
+ }
70
107
}
108
+
109
+ return $ checkoutMethod ;
71
110
}
72
111
73
112
/**
@@ -77,7 +116,7 @@ public function execute()
77
116
*/
78
117
protected function placeCheckoutOrder ()
79
118
{
80
- $ result = new \ Magento \ Framework \ Object ();
119
+ $ result = new Object ();
81
120
try {
82
121
$ this ->cartManagement ->placeOrder ($ this ->_getCheckout ()->getQuote ()->getId ());
83
122
$ result ->setData ('success ' , true );
@@ -92,8 +131,30 @@ protected function placeCheckoutOrder()
92
131
$ result ->setData ('error ' , true );
93
132
$ result ->setData ('error_messages ' , __ ('Cannot place order. ' ));
94
133
}
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 ' );
98
159
}
99
160
}
0 commit comments