11<?php
22/**
3- *
43 * Copyright © 2015 Magento. All rights reserved.
54 * See COPYING.txt for license details.
65 */
109use Magento \Authorizenet \Helper \DataFactory ;
1110use Magento \Checkout \Model \Type \Onepage ;
1211use 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 ;
1414use Magento \Framework \Object ;
1515use Magento \Framework \Registry ;
1616use Magento \Payment \Model \IframeConfigProvider ;
2424class Place extends Payment
2525{
2626 /**
27- * @var CartManagementInterface
27+ * @var \Magento\Quote\Api\ CartManagementInterface
2828 */
2929 protected $ cartManagement ;
3030
3131 /**
32- * @var ManagerInterface
32+ * @var \Magento\Framework\Event\ ManagerInterface
3333 */
3434 protected $ eventManager ;
3535
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+
3646 /**
3747 * @param Context $context
3848 * @param Registry $coreRegistry
3949 * @param DataFactory $dataFactory
4050 * @param CartManagementInterface $cartManagement
51+ * @param Onepage $onepageCheckout
52+ * @param JsonHelper $jsonHelper
4153 */
4254 public function __construct (
4355 Context $ context ,
4456 Registry $ coreRegistry ,
4557 DataFactory $ dataFactory ,
46- CartManagementInterface $ cartManagement
58+ CartManagementInterface $ cartManagement ,
59+ Onepage $ onepageCheckout ,
60+ JsonHelper $ jsonHelper
4761 ) {
4862 $ this ->eventManager = $ context ->getEventManager ();
4963 $ this ->cartManagement = $ cartManagement ;
64+ $ this ->onepageCheckout = $ onepageCheckout ;
65+ $ this ->jsonHelper = $ jsonHelper ;
5066 parent ::__construct ($ context , $ coreRegistry , $ dataFactory );
5167 }
5268
@@ -59,20 +75,23 @@ public function execute()
5975 {
6076 $ paymentParam = $ this ->getRequest ()->getParam ('payment ' );
6177 $ controller = $ this ->getRequest ()->getParam ('controller ' );
78+ $ response = $ this ->getResponse ();
6279
6380 if (isset ($ paymentParam ['method ' ])) {
6481 $ 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 ();
6687
6788 if ($ controller == IframeConfigProvider::CHECKOUT_IDENTIFIER ) {
6889 return $ this ->placeCheckoutOrder ();
6990 }
7091
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 );
7695 $ this ->_forward (
7796 $ params ['action ' ],
7897 $ params ['controller ' ],
@@ -81,32 +100,10 @@ public function execute()
81100 );
82101 } else {
83102 $ 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 ));
106105 }
107106 }
108-
109- return $ checkoutMethod ;
110107 }
111108
112109 /**
@@ -117,6 +114,7 @@ protected function getCheckoutMethod()
117114 protected function placeCheckoutOrder ()
118115 {
119116 $ result = new Object ();
117+ $ response = $ this ->getResponse ();
120118 try {
121119 $ this ->cartManagement ->placeOrder ($ this ->_getCheckout ()->getQuote ()->getId ());
122120 $ result ->setData ('success ' , true );
@@ -131,30 +129,8 @@ protected function placeCheckoutOrder()
131129 $ result ->setData ('error ' , true );
132130 $ result ->setData ('error_messages ' , __ ('Cannot place order. ' ));
133131 }
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+ }
159135 }
160136}
0 commit comments