Skip to content

Commit

Permalink
Merge pull request #488 from magento-mpi/develop
Browse files Browse the repository at this point in the history
[MPI] Bugs
  • Loading branch information
vpelipenko committed Jul 24, 2015
2 parents 57f5ab8 + 12667a7 commit 870291a
Show file tree
Hide file tree
Showing 34 changed files with 727 additions and 268 deletions.
4 changes: 3 additions & 1 deletion app/code/Magento/Authorizenet/Helper/Backend/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public function __construct(
OrderFactory $orderFactory,
UrlInterface $backendUrl
) {
$this->_urlBuilder = $backendUrl;
parent::__construct($context, $storeManager, $orderFactory);
$this->_urlBuilder = $backendUrl;
}

/**
Expand Down Expand Up @@ -85,6 +85,8 @@ public function getRedirectIframeUrl($params)
*
* @param null|int|string $storeId
* @return string
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function getRelayUrl($storeId = null)
{
Expand Down
151 changes: 24 additions & 127 deletions app/code/Magento/Authorizenet/view/adminhtml/web/js/direct-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ directPost.prototype = {
this.headers = [];
this.isValid = true;
this.paymentRequestSent = false;
this.isResponse = false;
this.orderIncrementId = false;
this.successUrl = false;
this.hasError = false;
this.tmpForm = false;

this.onSaveOnepageOrderSuccess = this.saveOnepageOrderSuccess.bindAsEventListener(this);
this.onLoadIframe = this.loadIframe.bindAsEventListener(this);
this.onLoadOrderIframe = this.loadOrderIframe.bindAsEventListener(this);
this.onSubmitAdminOrder = this.submitAdminOrder.bindAsEventListener(this);
Expand Down Expand Up @@ -80,63 +78,30 @@ directPost.prototype = {
.off('submitOrder')
.on('submitOrder', this.submitAdminOrder.bind(this));
if ($(this.iframeId)) {
switch (this.controller) {
case 'onepage':
this.headers = $$('#' + checkout.accordion.container.readAttribute('id') + ' .section');
var button = $('review-buttons-container').down('button');
button.writeAttribute('onclick', '');
button.stopObserving('click');
button.observe('click', function() {
if ($(this.iframeId)) {
if (this.validate()) {
this.saveOnepageOrder();
}
} else {
review.save();
}
}.bind(this));
break;
case 'order_create':
case 'order_edit':
// Temporary solution will be removed after refactoring Authorize.Net (sales) functionality
jQuery('.scalable.save:not(disabled)').removeAttr('onclick');
jQuery(document).off('click.directPost');
jQuery(document).on(
'click.directPost',
'.scalable.save:not(disabled)',
jQuery.proxy(this.onSubmitAdminOrder, this)
);

$('order-' + this.iframeId).observe('load', this.onLoadOrderIframe);
break;
}

// Temporary solution will be removed after refactoring Authorize.Net (sales) functionality
jQuery('.scalable.save:not(disabled)').removeAttr('onclick');
jQuery(document).off('click.directPost');
jQuery(document).on(
'click.directPost',
'.scalable.save:not(disabled)',
jQuery.proxy(this.onSubmitAdminOrder, this)
);
$('order-' + this.iframeId).observe('load', this.onLoadOrderIframe);
$(this.iframeId).observe('load', this.onLoadIframe);
}
},

loadIframe : function() {
if (this.paymentRequestSent) {
switch (this.controller) {
case 'onepage':
this.paymentRequestSent = false;
if (!this.hasError) {
this.returnQuote();
}
break;
case 'order_edit':
case 'order_create':
if (!this.orderRequestSent) {
this.paymentRequestSent = false;
if (!this.hasError) {
this.returnQuote();
} else {
this.changeInputOptions('disabled', false);
jQuery('body').trigger('processStop');
enableElements('save');
}
}
break;
if (!this.orderRequestSent) {
this.paymentRequestSent = false;
if (!this.hasError) {
this.returnQuote();
} else {
this.changeInputOptions('disabled', false);
jQuery('body').trigger('processStop');
enableElements('save');
}
}
if (this.tmpForm) {
document.body.removeChild(this.tmpForm);
Expand Down Expand Up @@ -167,25 +132,17 @@ directPost.prototype = {
new Ajax.Request(url, {
onSuccess : function(transport) {
try {
response = eval('(' + transport.responseText + ')');
response = transport.responseText.evalJSON(true);
} catch (e) {
response = {};
}
if (response.error_message) {
alert(response.error_message);
}
$(this.iframeId).show();
switch (this.controller) {
case 'onepage':
this.resetLoadWaiting();
break;
case 'order_edit':
case 'order_create':
this.changeInputOptions('disabled', false);
jQuery('body').trigger('processStop');
enableElements('save');
break;
}
this.changeInputOptions('disabled', false);
jQuery('body').trigger('processStop');
enableElements('save');
}.bind(this)
});
},
Expand All @@ -204,66 +161,6 @@ directPost.prototype = {
checkout.setLoadWaiting(false);
},

saveOnepageOrder : function() {
this.hasError = false;
this.setLoadWaiting();
var params = Form.serialize(payment.form);
if (review.agreementsForm) {
params += '&' + Form.serialize(review.agreementsForm);
}
params += '&controller=' + this.controller;
new Ajax.Request(this.orderSaveUrl, {
method : 'post',
parameters : params,
onComplete : this.onSaveOnepageOrderSuccess,
onFailure : function(transport) {
this.resetLoadWaiting();
if (transport.status == 403) {
checkout.ajaxFailure();
}
}
});
},

saveOnepageOrderSuccess : function(transport) {
if (transport.status == 403) {
checkout.ajaxFailure();
}
try {
response = eval('(' + transport.responseText + ')');
} catch (e) {
response = {};
}

if (response.success && response.directpost) {
this.orderIncrementId = response.directpost.fields.x_invoice_num;
var paymentData = {};
for ( var key in response.directpost.fields) {
paymentData[key] = response.directpost.fields[key];
}
var preparedData = this.preparePaymentRequest(paymentData);
this.sendPaymentRequest(preparedData);
} else {
var msg = response.error_messages;
if (typeof (msg) == 'object') {
msg = msg.join("\n");
}
if (msg) {
alert(msg);
}

if (response.update_section) {
$('checkout-' + response.update_section.name + '-load').replace(response.update_section.html);
response.update_section.html.evalScripts();
}

if (response.goto_section) {
checkout.gotoSection(response.goto_section);
checkout.reloadProgressBlock();
}
}
},

submitAdminOrder : function() {
// Temporary solution will be removed after refactoring Authorize.Net (sales) functionality
var editForm = jQuery('#edit_form');
Expand Down Expand Up @@ -324,7 +221,7 @@ directPost.prototype = {

saveAdminOrderSuccess : function(data) {
try {
response = eval('(' + data + ')');
response = data.evalJSON(true);
} catch (e) {
response = {};
}
Expand Down Expand Up @@ -423,4 +320,4 @@ directPost.prototype = {
}
}
};
}));
}));
96 changes: 48 additions & 48 deletions app/code/Magento/Checkout/Block/Onepage/Success.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Magento\Checkout\Block\Onepage;

use Magento\Customer\Model\Context;
use Magento\Sales\Model\Order;

/**
* One page checkout success page
Expand All @@ -17,16 +18,6 @@ class Success extends \Magento\Framework\View\Element\Template
*/
protected $_checkoutSession;

/**
* @var \Magento\Customer\Model\Session
*/
protected $_customerSession;

/**
* @var \Magento\Sales\Model\OrderFactory
*/
protected $_orderFactory;

/**
* @var \Magento\Sales\Model\Order\Config
*/
Expand All @@ -40,40 +31,24 @@ class Success extends \Magento\Framework\View\Element\Template
/**
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Checkout\Model\Session $checkoutSession
* @param \Magento\Customer\Model\Session $customerSession
* @param \Magento\Sales\Model\OrderFactory $orderFactory
* @param \Magento\Sales\Model\Order\Config $orderConfig
* @param \Magento\Framework\App\Http\Context $httpContext
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Customer\Model\Session $customerSession,
\Magento\Sales\Model\OrderFactory $orderFactory,
\Magento\Sales\Model\Order\Config $orderConfig,
\Magento\Framework\App\Http\Context $httpContext,
array $data = []
) {
parent::__construct($context, $data);
$this->_checkoutSession = $checkoutSession;
$this->_customerSession = $customerSession;
$this->_orderFactory = $orderFactory;
$this->_orderConfig = $orderConfig;
$this->_isScopePrivate = true;
$this->httpContext = $httpContext;
}

/**
* See if the order has state, visible on frontend
*
* @return bool
*/
public function isOrderVisible()
{
return (bool)$this->_getData('is_order_visible');
}

/**
* Render additional order information lines and return result html
*
Expand All @@ -91,35 +66,60 @@ public function getAdditionalInfoHtml()
*/
protected function _beforeToHtml()
{
$this->_prepareLastOrder();
$this->prepareBlockData();
return parent::_beforeToHtml();
}

/**
* Get last order ID from session, fetch it and check whether it can be viewed, printed etc
* Prepares block data
*
* @return void
*/
protected function _prepareLastOrder()
protected function prepareBlockData()
{
$order = $this->_checkoutSession->getLastRealOrder();

$this->addData(
[
'is_order_visible' => $this->isVisible($order),
'view_order_url' => $this->getUrl(
'sales/order/view/',
['order_id' => $order->getEntityId()]
),
'print_url' => $this->getUrl(
'sales/order/print',
['order_id' => $order->getEntityId()]
),
'can_print_order' => $this->isVisible($order),
'can_view_order' => $this->canViewOrder($order),
'order_id' => $order->getIncrementId()
]
);
}

/**
* Is order visible
*
* @param Order $order
* @return bool
*/
protected function isVisible(Order $order)
{
return !in_array(
$order->getStatus(),
$this->_orderConfig->getInvisibleOnFrontStatuses()
);
}

/**
* Can view order
*
* @param Order $order
* @return bool
*/
protected function canViewOrder(Order $order)
{
$orderId = $this->_checkoutSession->getLastOrderId();
if ($orderId) {
$incrementId = $this->_checkoutSession->getLastRealOrderId();
$status = $this->_checkoutSession->getLastOrderStatus();
if ($status && $incrementId) {
$isVisible = !in_array($status, $this->_orderConfig->getInvisibleOnFrontStatuses());
$canView = $this->httpContext->getValue(Context::CONTEXT_AUTH) && $isVisible;
$this->addData(
[
'is_order_visible' => $isVisible,
'view_order_url' => $this->getUrl('sales/order/view/', ['order_id' => $orderId]),
'print_url' => $this->getUrl('sales/order/print', ['order_id' => $orderId]),
'can_print_order' => $isVisible,
'can_view_order' => $canView,
'order_id' => $incrementId,
]
);
}
}
return $this->httpContext->getValue(Context::CONTEXT_AUTH)
&& $this->isVisible($order);
}
}
Loading

0 comments on commit 870291a

Please sign in to comment.