Configure the button from the bootstrappers

This should give us the flexibility to overwrite default configuration option on context level
This commit is contained in:
Mészáros Róbert 2020-04-10 10:34:49 +03:00
parent 42fe525a0b
commit 4e0a4b8edb
9 changed files with 86 additions and 78 deletions

View file

@ -1,8 +1,10 @@
import ErrorHandler from './ErrorHandler';
import CartActionHandler from './CartActionHandler';
class MiniCartBootstap {
constructor(gateway, renderer, configurator) {
constructor(gateway, renderer) {
this.gateway = gateway;
this.renderer = renderer;
this.configurator = configurator;
}
init() {
@ -14,20 +16,27 @@ class MiniCartBootstap {
}
shouldRender() {
return document.querySelector(this.gateway.button.mini_cart_wrapper) !== null;
return document.querySelector(this.gateway.button.mini_cart_wrapper) !==
null;
}
render() {
// Compared to the other bootstrapper we need the checker inside the
// renderer because the mini cart is refreshed with AJAX and the
// wrapper DOM might not be there from the start
if (!this.shouldRender()) {
return;
}
const actionHandler = new CartActionHandler(
PayPalCommerceGateway,
new ErrorHandler(),
);
this.renderer.render(
this.gateway.button.mini_cart_wrapper,
this.configurator.configuration(),
{
style: {
shape: 'rect',
}, ...actionHandler.configuration(),
},
);
}
}