Skip to content

Instantly share code, notes, and snippets.

@boldsupport
Created February 28, 2018 06:42
Show Gist options
  • Save boldsupport/5e705c02de3adf933053511a7fd58c84 to your computer and use it in GitHub Desktop.
Save boldsupport/5e705c02de3adf933053511a7fd58c84 to your computer and use it in GitHub Desktop.
Snippet used to integrate Zapiet with Recurring Orders (include before the closing body)
window.ZapietRO = {};
ZapietRO.CartIntegration = function() {
this.init();
}
ZapietRO.CartIntegration.prototype.init = function() {
this.addListeners();
}
ZapietRO.CartIntegration.prototype.addListeners = function() {
window.ZapietEvent.listen('selected_method', function(method) {
switch(method) {
case 'shipping':
BOLD.recurring_orders.app.cartWidget.pickupEnabled = false;
break;
case 'pickup':
BOLD.recurring_orders.app.cartWidget.pickupEnabled = true;
break;
}
});
window.ZapietEvent.listen('disableCheckout', function(response) {
BOLD.recurring_orders.app.cartWidget.checkoutEnabled = false;
});
window.ZapietEvent.listen('activateCheckout', function(response) {
BOLD.recurring_orders.app.cartWidget.checkoutEnabled = true;
if(response && response.method && response.method === 'pickup' && response.location) {
BOLD.customer.address1 = response.location.address_line_1 || "";
BOLD.customer.address2 = response.location.address_line_2 || "";
BOLD.customer.city = response.location.city || "";
BOLD.customer.company = response.location.company_name || "";
BOLD.customer.country = response.location.country || "";
BOLD.customer.province = response.location.region || "";
BOLD.customer.zip = response.location.postal_code || "";
BOLD.recurring_orders.app.cartWidget.loadCustomerData();
}
});
}
if(typeof window.Zapiet !== 'undefined' &&
typeof window.ZapietEvent !== 'undefined' &&
typeof BOLD !== 'undefined' &&
typeof BOLD.recurring_orders !== 'undefined' &&
typeof BOLD.recurring_orders.app !== 'undefined' &&
typeof BOLD.customer !== 'undefined') {
ZapietRO.cart = new ZapietRO.CartIntegration();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment