Skip to content

Commit 5766095

Browse files
committed
MAGETWO-51504: Storefront Place Order action can not be reused with different payload and serviceUrl
- Decomposed place-order action
1 parent 8e256d4 commit 5766095

File tree

2 files changed

+42
-29
lines changed

2 files changed

+42
-29
lines changed

app/code/Magento/Checkout/view/frontend/web/js/action/place-order.js

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,45 +9,31 @@ define(
99
'mage/storage',
1010
'Magento_Checkout/js/model/error-processor',
1111
'Magento_Customer/js/model/customer',
12-
'Magento_Checkout/js/model/full-screen-loader'
12+
'Magento_Checkout/js/model/full-screen-loader',
13+
'Magento_Checkout/js/model/place-order'
1314
],
14-
function (quote, urlBuilder, storage, errorProcessor, customer, fullScreenLoader) {
15+
function (quote, urlBuilder, storage, errorProcessor, customer, fullScreenLoader, placeOrderService) {
1516
'use strict';
1617

1718
return function (paymentData, messageContainer) {
18-
var serviceUrl,
19-
payload;
19+
var serviceUrl, payload;
2020

21-
/** Checkout for guest and registered customer. */
22-
if (!customer.isLoggedIn()) {
21+
payload = {
22+
cartId: quote.getQuoteId(),
23+
billingAddress: quote.billingAddress(),
24+
paymentMethod: paymentData
25+
};
26+
27+
if (customer.isLoggedIn()) {
28+
serviceUrl = urlBuilder.createUrl('/carts/mine/payment-information', {});
29+
} else {
2330
serviceUrl = urlBuilder.createUrl('/guest-carts/:quoteId/payment-information', {
2431
quoteId: quote.getQuoteId()
2532
});
26-
payload = {
27-
cartId: quote.getQuoteId(),
28-
email: quote.guestEmail,
29-
paymentMethod: paymentData,
30-
billingAddress: quote.billingAddress()
31-
};
32-
} else {
33-
serviceUrl = urlBuilder.createUrl('/carts/mine/payment-information', {});
34-
payload = {
35-
cartId: quote.getQuoteId(),
36-
paymentMethod: paymentData,
37-
billingAddress: quote.billingAddress()
38-
};
33+
payload.email = quote.guestEmail;
3934
}
4035

41-
fullScreenLoader.startLoader();
42-
43-
return storage.post(
44-
serviceUrl, JSON.stringify(payload)
45-
).fail(
46-
function (response) {
47-
errorProcessor.process(response, messageContainer);
48-
fullScreenLoader.stopLoader();
49-
}
50-
);
36+
return placeOrderService(serviceUrl, payload, messageContainer);
5137
};
5238
}
5339
);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Copyright © 2016 Magento. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
define(
6+
[
7+
'mage/storage',
8+
'Magento_Checkout/js/model/error-processor',
9+
'Magento_Checkout/js/model/full-screen-loader'
10+
],
11+
function (storage, errorProcessor, fullScreenLoader) {
12+
'use strict';
13+
14+
return function (serviceUrl, payload, messageContainer) {
15+
fullScreenLoader.startLoader();
16+
17+
return storage.post(
18+
serviceUrl, JSON.stringify(payload)
19+
).fail(
20+
function (response) {
21+
errorProcessor.process(response, messageContainer);
22+
fullScreenLoader.stopLoader();
23+
}
24+
);
25+
};
26+
}
27+
);

0 commit comments

Comments
 (0)