Last active
November 10, 2020 10:08
-
-
Save jlnarvaez/eb1543ce6c9f5f3ef656cadfc377e1c2 to your computer and use it in GitHub Desktop.
[MAGENTO 2] Mixin JS for place-order action
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Jlnarvaez/Checkout/view/frontend/web/js/action/place-order-mixin | |
define([ | |
'mage/utils/wrapper' | |
], function (wrapper) { | |
'use strict'; | |
return function (placeOrderFunction) { | |
return wrapper.wrap(placeOrderFunction, function (originalPlaceOrder, paymentData, messageContainer) { | |
originalPlaceOrder(paymentData, messageContainer); | |
// add extended functionality here | |
}); | |
}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* ORIGINAL place-order.js FROM CORE (Magento_Checkout) v2.4 | |
* Copyright © Magento, Inc. All rights reserved. | |
* See COPYING.txt for license details. | |
*/ | |
/** | |
* @api | |
*/ | |
define([ | |
'Magento_Checkout/js/model/quote', | |
'Magento_Checkout/js/model/url-builder', | |
'Magento_Customer/js/model/customer', | |
'Magento_Checkout/js/model/place-order' | |
], function (quote, urlBuilder, customer, placeOrderService) { | |
'use strict'; | |
return function (paymentData, messageContainer) { | |
var serviceUrl, payload; | |
payload = { | |
cartId: quote.getQuoteId(), | |
billingAddress: quote.billingAddress(), | |
paymentMethod: paymentData | |
}; | |
if (customer.isLoggedIn()) { | |
serviceUrl = urlBuilder.createUrl('/carts/mine/payment-information', {}); | |
} else { | |
serviceUrl = urlBuilder.createUrl('/guest-carts/:quoteId/payment-information', { | |
quoteId: quote.getQuoteId() | |
}); | |
payload.email = quote.guestEmail; | |
} | |
return placeOrderService(serviceUrl, payload, messageContainer); | |
}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Jlnarvaez/Checkout/view/frontend/requirejs-config.js | |
var config = { | |
config: { | |
mixins: { | |
'Magento_Checkout/js/action/place-order': { | |
'Jlnarvaez_Checkout/js/action/place-order-mixin': true | |
}, | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment