Skip to content

Commit

Permalink
Merge remote-tracking branch 'mainline/develop' into MAGETWO-35379
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrii Lugovyi committed Jul 14, 2015
2 parents f954ca1 + 8892f35 commit 80effc4
Show file tree
Hide file tree
Showing 600 changed files with 10,714 additions and 14,986 deletions.
@@ -1,6 +1,5 @@
<?php
/**
*
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
Expand All @@ -10,7 +9,8 @@
use Magento\Authorizenet\Helper\DataFactory;
use Magento\Checkout\Model\Type\Onepage;
use Magento\Framework\App\Action\Context;
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\App\Response\Http;
use Magento\Framework\Json\Helper\Data as JsonHelper;
use Magento\Framework\Object;
use Magento\Framework\Registry;
use Magento\Payment\Model\IframeConfigProvider;
Expand All @@ -24,29 +24,45 @@
class Place extends Payment
{
/**
* @var CartManagementInterface
* @var \Magento\Quote\Api\CartManagementInterface
*/
protected $cartManagement;

/**
* @var ManagerInterface
* @var \Magento\Framework\Event\ManagerInterface
*/
protected $eventManager;

/**
* @var \Magento\Checkout\Model\Type\Onepage
*/
protected $onepageCheckout;

/**
* @var \Magento\Framework\Json\Helper\Data
*/
protected $jsonHelper;

/**
* @param Context $context
* @param Registry $coreRegistry
* @param DataFactory $dataFactory
* @param CartManagementInterface $cartManagement
* @param Onepage $onepageCheckout
* @param JsonHelper $jsonHelper
*/
public function __construct(
Context $context,
Registry $coreRegistry,
DataFactory $dataFactory,
CartManagementInterface $cartManagement
CartManagementInterface $cartManagement,
Onepage $onepageCheckout,
JsonHelper $jsonHelper
) {
$this->eventManager = $context->getEventManager();
$this->cartManagement = $cartManagement;
$this->onepageCheckout = $onepageCheckout;
$this->jsonHelper = $jsonHelper;
parent::__construct($context, $coreRegistry, $dataFactory);
}

Expand All @@ -59,20 +75,23 @@ public function execute()
{
$paymentParam = $this->getRequest()->getParam('payment');
$controller = $this->getRequest()->getParam('controller');
$response = $this->getResponse();

if (isset($paymentParam['method'])) {
$this->_getDirectPostSession()->setQuoteId($this->_getCheckout()->getQuote()->getId());
$this->_getCheckout()->getQuote()->setCheckoutMethod($this->getCheckoutMethod());
/**
* Current workaround depends on Onepage checkout model defect
* Method Onepage::getCheckoutMethod performs setCheckoutMethod
*/
$this->onepageCheckout->getCheckoutMethod();

if ($controller == IframeConfigProvider::CHECKOUT_IDENTIFIER) {
return $this->placeCheckoutOrder();
}

$params = $this->_objectManager->get(
'Magento\Authorizenet\Helper\Data'
)->getSaveOrderUrlParams(
$controller
);
$params = $this->dataFactory
->create(DataFactory::AREA_FRONTEND)
->getSaveOrderUrlParams($controller);
$this->_forward(
$params['action'],
$params['controller'],
Expand All @@ -81,32 +100,10 @@ public function execute()
);
} else {
$result = ['error_messages' => __('Please choose a payment method.'), 'goto_section' => 'payment'];
$this->getResponse()->representJson($this->getJsonHelper()->jsonEncode($result));
}
}

/**
* Get quote checkout method
*
* @return string
*/
protected function getCheckoutMethod()
{
$checkoutMethod = $this->_getCheckout()->getQuote()->getCheckoutMethod();

if ($this->getCustomerSession()->isLoggedIn()) {
$checkoutMethod = Onepage::METHOD_CUSTOMER;
}

if (!$checkoutMethod) {
if ($this->getCheckoutHelper()->isAllowedGuestCheckout($this->_getCheckout()->getQuote())) {
$checkoutMethod = Onepage::METHOD_GUEST;
} else {
$checkoutMethod = Onepage::METHOD_REGISTER;
if ($response instanceof Http) {
$response->representJson($this->jsonHelper->jsonEncode($result));
}
}

return $checkoutMethod;
}

/**
Expand All @@ -117,6 +114,7 @@ protected function getCheckoutMethod()
protected function placeCheckoutOrder()
{
$result = new Object();
$response = $this->getResponse();
try {
$this->cartManagement->placeOrder($this->_getCheckout()->getQuote()->getId());
$result->setData('success', true);
Expand All @@ -131,30 +129,8 @@ protected function placeCheckoutOrder()
$result->setData('error', true);
$result->setData('error_messages', __('Cannot place order.'));
}
$this->getResponse()->representJson($this->getJsonHelper()->jsonEncode($result));
}

/**
* @return \Magento\Customer\Model\Session
*/
protected function getCustomerSession()
{
return $this->_objectManager->get('Magento\Checkout\Model\Cart')->getCustomerSession();
}

/**
* @return \Magento\Checkout\Helper\Data
*/
protected function getCheckoutHelper()
{
return $this->_objectManager->get('Magento\Checkout\Helper\Data');
}

/**
* @return \Magento\Framework\Json\Helper\Data
*/
protected function getJsonHelper()
{
return $this->_objectManager->get('Magento\Framework\Json\Helper\Data');
if ($response instanceof Http) {
$response->representJson($this->jsonHelper->jsonEncode($result));
}
}
}
6 changes: 4 additions & 2 deletions app/code/Magento/Authorizenet/Helper/DataFactory.php
Expand Up @@ -13,6 +13,8 @@
*/
class DataFactory
{
const AREA_FRONTEND = 'frontend';
const AREA_BACKEND = 'adminhtml';
/**
* @var ObjectManagerInterface
*/
Expand All @@ -22,8 +24,8 @@ class DataFactory
* @var array
*/
protected $helperMap = [
'frontend' => 'Magento\Authorizenet\Helper\Data',
'adminhtml' => 'Magento\Authorizenet\Helper\Backend\Data'
self::AREA_FRONTEND => 'Magento\Authorizenet\Helper\Data',
self::AREA_BACKEND => 'Magento\Authorizenet\Helper\Backend\Data'
];

/**
Expand Down
16 changes: 15 additions & 1 deletion app/code/Magento/Authorizenet/Model/Directpost/Session.php
Expand Up @@ -5,10 +5,12 @@
*/
namespace Magento\Authorizenet\Model\Directpost;

use Magento\Framework\Session\SessionManager;

/**
* Authorize.net DirectPost session model
*/
class Session extends \Magento\Framework\Session\SessionManager
class Session extends SessionManager
{
/**
* Add order IncrementId to session
Expand Down Expand Up @@ -60,4 +62,16 @@ public function isCheckoutOrderIncrementIdExist($orderIncrementId)
}
return false;
}

/**
* Set quote id to session
*
* @param int|string $id
* @return $this
*/
public function setQuoteId($id)
{
$this->storage->setQuoteId($id);
return $this;
}
}

0 comments on commit 80effc4

Please sign in to comment.