Skip to content

Commit b071d3d

Browse files
author
Sergey Shvets
committed
MAGETWO-89264: Checkout doesn't work when AdBlock extension enabled and Google Analytics is enabled
1 parent 79110b8 commit b071d3d

File tree

2 files changed

+59
-7
lines changed

2 files changed

+59
-7
lines changed

app/code/Magento/Checkout/view/frontend/web/js/checkout-loader.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ define([
2323
* @param {HTMLElement} $loader - Loader DOM element.
2424
*/
2525
function init(config, $loader) {
26-
resolver(hideLoader.bind(null, $loader));
26+
resolver(
27+
hideLoader.bind(null, $loader),
28+
null,
29+
hideLoader.bind(null, $loader)
30+
);
2731
}
2832

2933
return init;

lib/web/mage/requirejs/resolver.js

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ define([
2828
}
2929

3030
/**
31-
* Checks if provided module is registered after load.
31+
* Checks if provided module is rejected during load.
3232
*
3333
* @param {Object} module - Module to be checked.
3434
* @return {Boolean}
3535
*/
36-
function isRegistered(module) {
37-
return registry[module.id];
36+
function isRejected(module) {
37+
return registry[module.id] && registry[module.id].error;
3838
}
3939

4040
/**
@@ -48,7 +48,21 @@ define([
4848
return false;
4949
}
5050

51-
return module.depCount > _.filter(module.depMaps, isRegistered).length;
51+
return module.depCount > _.filter(module.depMaps, isRejected).length;
52+
}
53+
54+
/**
55+
* Checks if provided module has errors.
56+
*
57+
* @param {Object} module - Module to be checked.
58+
* @returns {Boolean}
59+
*/
60+
function isError(module) {
61+
if (!module.depCount) {
62+
return false;
63+
}
64+
65+
return _.filter(module.depMaps, isRejected).length > 0;
5266
}
5367

5468
/**
@@ -60,6 +74,15 @@ define([
6074
return _.some(registry, isPending);
6175
}
6276

77+
/**
78+
* Checks if requirejs's registry object contains errors.
79+
*
80+
* @returns {Boolean}
81+
*/
82+
function hasError() {
83+
return _.some(registry, isError);
84+
}
85+
6386
/**
6487
* Checks if 'resolver' module is in ready
6588
* state and that there are no pending modules.
@@ -79,6 +102,18 @@ define([
79102
callback.handler.call(callback.ctx);
80103
}
81104

105+
/**
106+
* Throws error handler.
107+
*
108+
* @param {Object} callback
109+
*/
110+
function throwError(callback) {
111+
112+
if (callback.error) {
113+
callback.error.call(callback.ctx);
114+
}
115+
}
116+
82117
/**
83118
* Sets 'resolver' module to a ready state
84119
* and invokes pending callbacks.
@@ -89,6 +124,15 @@ define([
89124
callbacks.splice(0).forEach(invoke);
90125
}
91126

127+
/**
128+
* Reject error
129+
*/
130+
function reject() {
131+
ready = true;
132+
133+
callbacks.splice(0).forEach(throwError);
134+
}
135+
92136
/**
93137
* Drops 'ready' flag and runs the update process.
94138
*/
@@ -105,11 +149,13 @@ define([
105149
* @param {Function} handler - 'Ready' event handler function.
106150
* @param {Object} [ctx] - Optional context with which handler
107151
* will be invoked.
152+
* @param {Function} onError - error event handler
108153
*/
109-
function subscribe(handler, ctx) {
154+
function subscribe(handler, ctx, onError) {
110155
var callback = {
111156
handler: handler,
112-
ctx: ctx
157+
ctx: ctx,
158+
error: onError
113159
};
114160

115161
if (!isSubscribed(callback)) {
@@ -132,6 +178,8 @@ define([
132178
update = _.debounce(function (retry) {
133179
if (!hasPending()) {
134180
retry ? update(--retry) : resolve();
181+
} else if (hasError()) {
182+
retry ? update(--retry) : reject();
135183
}
136184
}, updateDelay);
137185

0 commit comments

Comments
 (0)