Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
LeadBI ECommerce JavaScript API
// LeadBI Shop API
// Shop.identify(user, callback)
window.$leadbi_website.getCurrentUser(function (err, user) {
return user.getShop(function (err, shop) {
return shop.identify({
first_name: '', // optional
last_name: '', // optional
email: '', // required
company: '', // optional
phone: '',
role: '', // optional
attributes: { // other attributes to be associated with the user
example_attribute: 'test'
}
}, function (err) {
console.log(err);
})
});
});
// Shop.viewProduct(product, callback)
window.$leadbi_website.getCurrentUser(function (err, user) {
return user.getShop(function (err, shop) {
return shop.viewProduct({
id: '6',
name: 'Example Product',
url: 'http://test.com/product/6',
img: 'http://test.com/img.jpg',
price: 99,
promo_price: 80,
available_inventory: 1,
category_id: 22,
category_name: 'test'
}, function (err) {
console.log(err);
});
});
});
// Shop.trackPurchase(purchase, callback)
window.$leadbi_website.getCurrentUser(function (err, user) {
return user.getShop(function (err, shop) {
return shop.trackPurchase({
id: '6',
name: 'Example Product 1',
url: 'http://test.com/product/6',
img: 'http://test.com/img.jpg',
price: 80,
promo_price: 80,
available_inventory: true,
quantity: 1,
category_id: 22,
category_name: 'test'
}, function (err) {
console.log(err);
});
});
});
// Shop.clickImage(product_id, callback)
window.$leadbi_website.getCurrentUser(function (err, user) {
return user.getShop(function (err, shop) {
var product_id = 22;
return shop.clickImage(product_id, function (err) {
console.log(err);
})
});
});
// Shop.Cart.addProduct(product, callback)
window.$leadbi_website.getCurrentUser(function (err, user) {
return user.getShop(function (err, shop) {
return shop.getCart('default', function (err, cart) {
return cart.addProduct({
id: '6',
name: 'Example Product 1',
url: 'http://test.com/product/6',
img: 'http://test.com/img.jpg',
price: 80,
promo_price: 80,
available_inventory: true,
quantity: 1,
category_id: 22,
category_name: 'test'
}, function (err) {
console.log(err);
});
});
});
});
// Shop.Cart.removeProduct(product_id, callback)
window.$leadbi_website.getCurrentUser(function (err, user) {
return user.getShop(function (err, shop) {
return shop.getCart('default', function (err, cart) {
var product_id = 22;
return cart.removeProduct(product_id, function (err) {
console.log(err);
});
});
});
});
// Shop.Cart.createOrder(order, callback)
window.$leadbi_website.getCurrentUser(function (err, user) {
return user.getShop(function (err, shop) {
return shop.getCart('default', function (err, cart) {
return cart.createOrder({
order_no: '232',
last_name: 'John',
first_name: 'Doe',
email: 'jd@example.com',
phone: '+40879826392',
state: 'NY',
city: 'New York',
address: '1st Av.',
discount_code: 'None',
discount: 'None',
shipping: 'Mail',
total: 80
}, function (err) {
console.log(err);
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.