1
1
<?php
2
2
/**
3
- *
4
3
* Copyright © 2015 Magento. All rights reserved.
5
4
* See COPYING.txt for license details.
6
5
*/
10
9
use Magento \Authorizenet \Helper \DataFactory ;
11
10
use Magento \Checkout \Model \Type \Onepage ;
12
11
use Magento \Framework \App \Action \Context ;
13
- use Magento \Framework \Event \ManagerInterface ;
12
+ use Magento \Framework \App \Response \Http ;
13
+ use Magento \Framework \Json \Helper \Data as JsonHelper ;
14
14
use Magento \Framework \Object ;
15
15
use Magento \Framework \Registry ;
16
16
use Magento \Payment \Model \IframeConfigProvider ;
24
24
class Place extends Payment
25
25
{
26
26
/**
27
- * @var CartManagementInterface
27
+ * @var \Magento\Quote\Api\ CartManagementInterface
28
28
*/
29
29
protected $ cartManagement ;
30
30
31
31
/**
32
- * @var ManagerInterface
32
+ * @var \Magento\Framework\Event\ ManagerInterface
33
33
*/
34
34
protected $ eventManager ;
35
35
36
+ /**
37
+ * @var \Magento\Checkout\Model\Type\Onepage
38
+ */
39
+ protected $ onepageCheckout ;
40
+
41
+ /**
42
+ * @var \Magento\Framework\Json\Helper\Data
43
+ */
44
+ protected $ jsonHelper ;
45
+
36
46
/**
37
47
* @param Context $context
38
48
* @param Registry $coreRegistry
39
49
* @param DataFactory $dataFactory
40
50
* @param CartManagementInterface $cartManagement
51
+ * @param Onepage $onepageCheckout
52
+ * @param JsonHelper $jsonHelper
41
53
*/
42
54
public function __construct (
43
55
Context $ context ,
44
56
Registry $ coreRegistry ,
45
57
DataFactory $ dataFactory ,
46
- CartManagementInterface $ cartManagement
58
+ CartManagementInterface $ cartManagement ,
59
+ Onepage $ onepageCheckout ,
60
+ JsonHelper $ jsonHelper
47
61
) {
48
62
$ this ->eventManager = $ context ->getEventManager ();
49
63
$ this ->cartManagement = $ cartManagement ;
64
+ $ this ->onepageCheckout = $ onepageCheckout ;
65
+ $ this ->jsonHelper = $ jsonHelper ;
50
66
parent ::__construct ($ context , $ coreRegistry , $ dataFactory );
51
67
}
52
68
@@ -59,20 +75,23 @@ public function execute()
59
75
{
60
76
$ paymentParam = $ this ->getRequest ()->getParam ('payment ' );
61
77
$ controller = $ this ->getRequest ()->getParam ('controller ' );
78
+ $ response = $ this ->getResponse ();
62
79
63
80
if (isset ($ paymentParam ['method ' ])) {
64
81
$ this ->_getDirectPostSession ()->setQuoteId ($ this ->_getCheckout ()->getQuote ()->getId ());
65
- $ this ->_getCheckout ()->getQuote ()->setCheckoutMethod ($ this ->getCheckoutMethod ());
82
+ /**
83
+ * Current workaround depends on Onepage checkout model defect
84
+ * Method Onepage::getCheckoutMethod performs setCheckoutMethod
85
+ */
86
+ $ this ->onepageCheckout ->getCheckoutMethod ();
66
87
67
88
if ($ controller == IframeConfigProvider::CHECKOUT_IDENTIFIER ) {
68
89
return $ this ->placeCheckoutOrder ();
69
90
}
70
91
71
- $ params = $ this ->_objectManager ->get (
72
- 'Magento\Authorizenet\Helper\Data '
73
- )->getSaveOrderUrlParams (
74
- $ controller
75
- );
92
+ $ params = $ this ->dataFactory
93
+ ->create (DataFactory::AREA_FRONTEND )
94
+ ->getSaveOrderUrlParams ($ controller );
76
95
$ this ->_forward (
77
96
$ params ['action ' ],
78
97
$ params ['controller ' ],
@@ -81,32 +100,10 @@ public function execute()
81
100
);
82
101
} else {
83
102
$ result = ['error_messages ' => __ ('Please choose a payment method. ' ), 'goto_section ' => 'payment ' ];
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 ;
103
+ if ($ response instanceof Http) {
104
+ $ response ->representJson ($ this ->jsonHelper ->jsonEncode ($ result ));
106
105
}
107
106
}
108
-
109
- return $ checkoutMethod ;
110
107
}
111
108
112
109
/**
@@ -117,6 +114,7 @@ protected function getCheckoutMethod()
117
114
protected function placeCheckoutOrder ()
118
115
{
119
116
$ result = new Object ();
117
+ $ response = $ this ->getResponse ();
120
118
try {
121
119
$ this ->cartManagement ->placeOrder ($ this ->_getCheckout ()->getQuote ()->getId ());
122
120
$ result ->setData ('success ' , true );
@@ -131,30 +129,8 @@ protected function placeCheckoutOrder()
131
129
$ result ->setData ('error ' , true );
132
130
$ result ->setData ('error_messages ' , __ ('Cannot place order. ' ));
133
131
}
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 ' );
132
+ if ($ response instanceof Http) {
133
+ $ response ->representJson ($ this ->jsonHelper ->jsonEncode ($ result ));
134
+ }
159
135
}
160
136
}
0 commit comments