Javascript 未捕获类型错误:this.validateHandler不是函数Magento2.3
我正在从Magento 2.2.7升级到Magento 2.3 我在升级代码后检查,我在结帐页面上的“下单”按钮不起作用。当我单击“下单”按钮时,我发现以下错误Javascript 未捕获类型错误:this.validateHandler不是函数Magento2.3,javascript,magento2,Javascript,Magento2,我正在从Magento 2.2.7升级到Magento 2.3 我在升级代码后检查,我在结帐页面上的“下单”按钮不起作用。当我单击“下单”按钮时,我发现以下错误 iframe.js:117 Uncaught TypeError: this.validateHandler is not a function at UiClass.placeOrder (iframe.js:117) at HTMLButtonElement.<anonymous> (knockout.j
iframe.js:117 Uncaught TypeError: this.validateHandler is not a function
at UiClass.placeOrder (iframe.js:117)
at HTMLButtonElement.<anonymous> (knockout.js:4255)
at HTMLButtonElement.dispatch (jquery.js:5226)
at HTMLButtonElement.elemData.handle (jquery.js:4878)
如何解决此问题?从您发布的代码中没有迹象表明存在此函数-但是,由于这似乎是某种事件处理程序,问题可能在于如何将其添加为事件处理程序。。。使用绑定此函数存在于iframe.js文件中。这一行出现了错误:if(This.validateHandler()&&additionalValidators.validate()){如果你有任何想法,请帮助我。我刚刚做了…这是如何调用
placeOrder
的问题-显示如何调用它…如果它像something.AddEventListener('someEvent',This.placeOrder)
您可能需要将其更改为something.AddEventListener('someEvent',this.placeOrder.).bind(this)
…我的第一条注释现在有意义了吗?如果您可以使用此bind()编写我指定的函数,那么很抱歉因为我无法正确编写它。这需要您向我展示如何调用PlaceOrder从您发布的代码中没有迹象表明存在这样一个函数-但是,由于这似乎是某种事件处理程序,问题可能在于如何将其添加为事件处理程序…使用bindIframe.js中存在的此函数这个错误出现在这行:if(This.validateHandler()&&additionalValidators.validate())`{如果你有任何想法,那么请帮助我。我刚刚做了…这是如何调用placeOrder
的问题-显示如何调用它…如果它像something.AddEventListener('someEvent',This.placeOrder)
您可能需要将其更改为something.AddEventListener('someEvent',this.placeOrder.).bind(this)
…我的第一条注释现在有意义吗?很抱歉,如果您可以使用此bind()编写我指定的函数,因为我无法正确编写它。这需要您向我展示如何调用placeOrder
define([
'jquery',
'Magento_Payment/js/view/payment/cc-form',
'Magento_Ui/js/model/messageList',
'mage/translate',
'Magento_Checkout/js/model/full-screen-loader',
'Magento_Checkout/js/action/set-payment-information',
'Magento_Checkout/js/model/payment/additional-validators',
'Magento_Ui/js/modal/alert'
], function (
$,
Component,
messageList,
$t,
fullScreenLoader,
setPaymentInformationAction,
additionalValidators,
alert
) {
'use strict';
return Component.extend({
defaults: {
template: 'Magento_Payment/payment/iframe',
timeoutId: null,
timeoutMessage: 'Sorry, but something went wrong.'
},
/**
* @returns {String}
*/
getSource: function () {
return window.checkoutConfig.payment.iframe.source[this.getCode()];
},
/**
* @returns {String}
*/
getControllerName: function () {
return window.checkoutConfig.payment.iframe.controllerName[this.getCode()];
},
/**
* @returns {String}
*/
getPlaceOrderUrl: function () {
return window.checkoutConfig.payment.iframe.placeOrderUrl[this.getCode()];
},
/**
* @returns {String}
*/
getCgiUrl: function () {
return window.checkoutConfig.payment.iframe.cgiUrl[this.getCode()];
},
/**
* @returns {String}
*/
getSaveOrderUrl: function () {
return window.checkoutConfig.payment.iframe.saveOrderUrl[this.getCode()];
},
/**
* @returns {String}
*/
getDateDelim: function () {
return window.checkoutConfig.payment.iframe.dateDelim[this.getCode()];
},
/**
* @returns {String}
*/
getCardFieldsMap: function () {
return window.checkoutConfig.payment.iframe.cardFieldsMap[this.getCode()];
},
/**
* @returns {String}
*/
getExpireYearLength: function () {
return window.checkoutConfig.payment.iframe.expireYearLength[this.getCode()];
},
/**
* @param {Object} parent
* @returns {Function}
*/
originalPlaceOrder: function (parent) {
return parent.placeOrder.bind(parent);
},
/**
* @returns {Number}
*/
getTimeoutTime: function () {
return window.checkoutConfig.payment.iframe.timeoutTime[this.getCode()];
},
/**
* @returns {String}
*/
getTimeoutMessage: function () {
return $t(this.timeoutMessage);
},
/**
* @override
*/
placeOrder: function () {
if (this.validateHandler() && additionalValidators.validate()) {
fullScreenLoader.startLoader();
this.isPlaceOrderActionAllowed(false);
$.when(
setPaymentInformationAction(
this.messageContainer,
{
method: this.getCode()
}
)
).done(this.done.bind(this))
.fail(this.fail.bind(this));
this.initTimeoutHandler();
}
},
/**
* {Function}
*/
initTimeoutHandler: function () {
this.timeoutId = setTimeout(
this.timeoutHandler.bind(this),
this.getTimeoutTime()
);
$(window).off('clearTimeout')
.on('clearTimeout', this.clearTimeout.bind(this));
},
/**
* {Function}
*/
clearTimeout: function () {
clearTimeout(this.timeoutId);
this.fail();
return this;
},
/**
* {Function}
*/
timeoutHandler: function () {
this.clearTimeout();
alert(
{
content: this.getTimeoutMessage(),
actions: {
/**
* {Function}
*/
always: this.alertActionHandler.bind(this)
}
}
);
this.fail();
},
/**
* {Function}
*/
alertActionHandler: function () {
fullScreenLoader.startLoader();
window.location.reload();
},
/**
* {Function}
*/
fail: function () {
fullScreenLoader.stopLoader();
this.isPlaceOrderActionAllowed(true);
return this;
},
/**
* {Function}
*/
done: function () {
this.placeOrderHandler().fail(function () {
fullScreenLoader.stopLoader();
});
return this;
}
});
});