You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
3.0 KiB

5 years ago
import 'slick-slider/slick/slick.min'
5 years ago
window.readyResize = (callback, orientation = false) => {
if ($.isFunction(callback)) {
$(document).ready(()=>{
callback()
})
$(window).resize(()=>{
console.log('Window resize ')
callback()
})
if(orientation) {
window.addEventListener("orientationchange", () => {
const WCO = ($(window).width() > $(window).height()) ? "landscape" : "portrait"
console.log('Change orientation: ' + WCO)
callback()
})
}
}
}
4 years ago
$.ajaxSetup({ async: false })
5 years ago
4 years ago
window.apiUrl = ENV.API_URL
window.siteUrl = ENV.SITE_URL
window.Apis = window.Apis || {}
window.Apis.addToCart = (pid, price, qty) => {
4 years ago
return new Promise((resolve, reject) => {
$.post(apiUrl + `/cart_add.php?buster=${new Date().getTime()}`, {pid: pid, price: price, qty: qty}).done( (data) => {
resolve(data)
}).fail((error, status) => {
reject(error)
})
})
}
window.Apis.removeFromCart = (pid) => {
return new Promise((resolve, reject) => {
$.post(apiUrl + `/cart_del.php?buster=${new Date().getTime()}`, {pid: pid}).done( (data) => {
4 years ago
resolve(data)
}).fail((error, status) => {
reject(error)
})
})
}
5 years ago
window.Apis.getCart = (body) => {
return new Promise((resolve, reject) => {
$.post(apiUrl + `/cart_get.php?buster=${new Date().getTime()}`, {body: body}).done( (data) => {
resolve(data)
}).fail((error, status) => {
reject(error)
})
})
}
4 years ago
window.Apis.addUser = (body) => {
return new Promise((resolve, reject) => {
$.ajax({
type: 'POST',
url: apiUrl + `/user_add.php?buster=${new Date().getTime()}`,
data: JSON.stringify(body),
dataType: 'json',
async: true,
contentType: 'application/json; charset=utf-8',
success: (data) => {
resolve(data)
},
error: (error) => {
reject(error)
}
})
})
}
window.Apis.getToken = () => {
return new Promise((resolve, reject) => {
$.ajax({
type: 'POST',
url: ENV.PP_AUTH_URL,
data: {'grant_type': 'client_credentials'},
dataType: 'json',
async: true,
contentType: 'application/json; charset=utf-8',
headers: {'Authorization': `Basic ${btoa(ENV.PP_CLIENTID + ":" + ENV.PP_SECRET)}`},
success: (data) => {
resolve(data)
},
error: (error) => {
reject(error)
}
})
})
}
window.Apis.placeOrder = (cart, token) => {
const data = {
intent: 'CAPTURE',
application_context: {
brand_name: 'IoLovOlio',
locale: 'it-IT',
return_url: ENV.PP_RETURN,
4 years ago
cancel_url: ENV.PP_CANCEL
},
purchase_units: cart
}
return new Promise((resolve, reject) => {
$.ajax({
type: 'POST',
url: ENV.PP_ORDER_URL,
data: JSON.stringify(data),
dataType: 'json',
async: true,
contentType: 'application/json; charset=utf-8',
headers: {'Authorization': `Bearer ${token}`},
success: (data) => {
resolve(data)
},
error: (error) => {
reject(error)
}
})
})
}