Written by Anonymous
----------
export async function postAddItemCart(id, quantity) {
const fnc = 'postAddItemCart';
if (id && quantity) {
const url = `${DOMAIN_BUYER}/cart/add.js`;
const headers = {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
'X-Requested-With': 'XMLHttpRequest'
};
var details = {
"id": id,
"quantity": quantity
};
var formBody = [];
for (var property in details) {
var encodedKey = encodeURIComponent(_.toString(property));
var encodedValue = encodeURIComponent(_.toString(details[property]));
formBody.push(encodedKey + "=" + encodedValue);
}
var body = formBody.join("&");
const resultAddCart = await fetch(url, { method: 'POST', headers, body })
.then(response => response.text())
.then(text => {
const jsonFortmat = Service.formatJSON(text);
return jsonFortmat;
})
.then(responseJSON => responseJSON)
.catch(e => console.log('Error: ' + fnc, e));
console.log('123',resultAddCart)
if (resultAddCart && resultAddCart.id) {
return resultAddCart;
} else {
//return 'Error';
return resultAddCart.description
}
} else {
console.log('Error add cart')
}
}
--------------------
--------------------
export async function checkCart() {
try {
const fnc = 'checkCart'
const url = `${DOMAIN_BUYER}/cart.js`
const result = await getAPI(url, fnc);
if (result !== 'Error') {
return result
}
} catch (e) {
console.log('Error', e);
}
}
--------------------