Skip to content

Commit 3a7ec70

Browse files
author
Oleksandr Manchenko
committed
Merge branch 'develop' of https://github.corp.ebay.com/magento2/magento2ce into develop
2 parents 851da3c + 375077a commit 3a7ec70

File tree

31 files changed

+1808
-739
lines changed

31 files changed

+1808
-739
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22
/**
3-
*
43
* Copyright © 2015 Magento. All rights reserved.
54
* See COPYING.txt for license details.
65
*/
@@ -10,7 +9,8 @@
109
use Magento\Authorizenet\Helper\DataFactory;
1110
use Magento\Checkout\Model\Type\Onepage;
1211
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;
1414
use Magento\Framework\Object;
1515
use Magento\Framework\Registry;
1616
use Magento\Payment\Model\IframeConfigProvider;
@@ -24,29 +24,45 @@
2424
class 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
}

app/code/Magento/Authorizenet/Helper/DataFactory.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
*/
1414
class DataFactory
1515
{
16+
const AREA_FRONTEND = 'frontend';
17+
const AREA_BACKEND = 'adminhtml';
1618
/**
1719
* @var ObjectManagerInterface
1820
*/
@@ -22,8 +24,8 @@ class DataFactory
2224
* @var array
2325
*/
2426
protected $helperMap = [
25-
'frontend' => 'Magento\Authorizenet\Helper\Data',
26-
'adminhtml' => 'Magento\Authorizenet\Helper\Backend\Data'
27+
self::AREA_FRONTEND => 'Magento\Authorizenet\Helper\Data',
28+
self::AREA_BACKEND => 'Magento\Authorizenet\Helper\Backend\Data'
2729
];
2830

2931
/**

app/code/Magento/Authorizenet/Model/Directpost/Session.php

+15-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
*/
66
namespace Magento\Authorizenet\Model\Directpost;
77

8+
use Magento\Framework\Session\SessionManager;
9+
810
/**
911
* Authorize.net DirectPost session model
1012
*/
11-
class Session extends \Magento\Framework\Session\SessionManager
13+
class Session extends SessionManager
1214
{
1315
/**
1416
* Add order IncrementId to session
@@ -60,4 +62,16 @@ public function isCheckoutOrderIncrementIdExist($orderIncrementId)
6062
}
6163
return false;
6264
}
65+
66+
/**
67+
* Set quote id to session
68+
*
69+
* @param int|string $id
70+
* @return $this
71+
*/
72+
public function setQuoteId($id)
73+
{
74+
$this->storage->setQuoteId($id);
75+
return $this;
76+
}
6377
}

0 commit comments

Comments
 (0)