2020-04-30 15:28:48 +03:00
|
|
|
import ErrorHandler from '../ErrorHandler';
|
|
|
|
import CartActionHandler from '../ActionHandler/CartActionHandler';
|
2020-04-10 10:34:49 +03:00
|
|
|
|
2020-04-08 18:50:29 +03:00
|
|
|
class MiniCartBootstap {
|
2020-04-10 10:34:49 +03:00
|
|
|
constructor(gateway, renderer) {
|
2020-04-09 12:56:05 +03:00
|
|
|
this.gateway = gateway;
|
2020-04-09 12:23:44 +03:00
|
|
|
this.renderer = renderer;
|
2020-04-08 18:50:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
init() {
|
2020-04-09 18:45:49 +03:00
|
|
|
this.render();
|
|
|
|
|
|
|
|
jQuery(document.body).on('wc_fragments_loaded wc_fragments_refreshed', () => {
|
|
|
|
this.render();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
shouldRender() {
|
2020-04-10 10:34:49 +03:00
|
|
|
return document.querySelector(this.gateway.button.mini_cart_wrapper) !==
|
|
|
|
null;
|
2020-04-09 18:45:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2020-04-09 10:49:37 +03:00
|
|
|
if (!this.shouldRender()) {
|
2020-04-08 18:50:29 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-10 10:34:49 +03:00
|
|
|
const actionHandler = new CartActionHandler(
|
|
|
|
PayPalCommerceGateway,
|
|
|
|
new ErrorHandler(),
|
|
|
|
);
|
|
|
|
|
2020-04-09 12:23:44 +03:00
|
|
|
this.renderer.render(
|
2020-04-09 12:56:05 +03:00
|
|
|
this.gateway.button.mini_cart_wrapper,
|
2020-04-30 15:28:48 +03:00
|
|
|
null,
|
2020-04-10 12:54:01 +03:00
|
|
|
actionHandler.configuration()
|
2020-04-09 12:23:44 +03:00
|
|
|
);
|
2020-04-08 18:50:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default MiniCartBootstap;
|