test-iki-mini-app
Version:
ứng dựng bán hàng trên mini app z a l o
81 lines (73 loc) • 2.1 kB
JSX
import { callApi } from "../api/index.jsx";
import { constants as c } from "../constants/index.jsx";
function getInfoLocal() {
var data = {};
const tokenInfo = JSON.parse(localStorage.getItem("tokenInfo"));
var total_shipping_fee = tokenInfo
? localStorage.getItem("total_shipping_fee")
: 0;
if (total_shipping_fee) {
var total_shipping_fee = JSON.parse(total_shipping_fee);
data = {
total_shipping_fee: total_shipping_fee || 0,
};
}
return data;
}
const getCart = () => {
const body = getInfoLocal();
return callApi(`/customer/${c.STORE_CODE}/carts`, "post", body);
};
const getPaymentMethods = () => {
return callApi(`/customer/${c.STORE_CODE}/payment_methods`, "get", null);
};
const changeQuantityInCart = (product) => {
const body = JSON.stringify(product);
return callApi(`/customer/${c.STORE_CODE}/carts/items`, "put", body);
};
const postListShipperFee = (idAddress, data) => {
const body = data
? JSON.stringify(data)
: JSON.stringify({
id_address_customer: idAddress,
});
return callApi(
`/customer/${c.STORE_CODE}/shipment/list_shipper`,
"post",
body
);
};
const postShipmentFeeForEachService = (idAddress, data, idService) => {
const body = data
? JSON.stringify(data)
: JSON.stringify({
id_address_customer: idAddress,
});
return callApi(
`/customer/${c.STORE_CODE}/carts/calculate_fee/${idService}`,
"post",
body
);
};
const applyDiscount = (info) => {
const body = { ...getInfoLocal(), ...info };
return callApi(`/customer/${c.STORE_CODE}/carts`, "post", body);
};
const orderCart = (orderInfo) => {
const body = JSON.stringify(orderInfo);
return callApi(`/customer/${c.STORE_CODE}/carts/orders`, "post", body);
};
const addCart = (product) => {
const body = JSON.stringify(product);
return callApi(`/customer/${c.STORE_CODE}/carts/items`, "post", body);
};
export const cart = {
getCart,
getPaymentMethods,
changeQuantityInCart,
postListShipperFee,
postShipmentFeeForEachService,
applyDiscount,
orderCart,
addCart,
};