Gustavo Luigi 2023-10-21 03:41:57 -03:00
parent b7e316cc34
commit 3ba51c787a
2 changed files with 4 additions and 3 deletions

View File

@ -18,7 +18,7 @@ export async function sync() {
let ids = items.map(obj => obj.id); let ids = items.map(obj => obj.id);


if (ids.length > 0) { if (ids.length > 0) {
let products = await fetch(url("contents/" + ids.join(","))); let products = await fetch(url("/contents/" + ids.join(",")));
products = await products.json(); products = await products.json();


products.contents.forEach(product => { products.contents.forEach(product => {
@ -93,5 +93,6 @@ export async function getTotalPrice() {


export async function getLink() { export async function getLink() {
await sync(); await sync();
return url(btoa(JSON.stringify(items))); let miniItems = items.map(obj => { return { id: obj.id, quantity: obj.quantity } });
return url("/?cart=" + btoa(JSON.stringify(miniItems)));
} }

View File

@ -16,7 +16,7 @@ export function isEncoded(string) {
} }


export function url(path = "") { export function url(path = "") {
const baseUrlElement = document.getElementById("base-url"); const baseUrlElement = document.querySelector('meta[name="url-base"]');
const baseUrl = baseUrlElement ? baseUrlElement.getAttribute("content") : ""; const baseUrl = baseUrlElement ? baseUrlElement.getAttribute("content") : "";
return baseUrl + path; return baseUrl + path;
} }