The code I am using seems to bee working but it doesn’t show it in the frontend. What can I do?
Here the code:
import { cart } from ‘wix-ecom-backend’;
export function calculateAdditionalFees(context) {
console.log(“PFAND: context keys:”, Object.keys(context));
if (context.lineItems && context.lineItems.length > 0) {
console.log("PFAND: Items aus context:", context.lineItems.length);
return { additionalFees: berechnePfand(context.lineItems) };
} else {
console.log("PFAND: Keine Items im context, hole Warenkorb...");
return cart.getCurrentCart()
.then(currentCart => {
if (currentCart.lineItems && currentCart.lineItems.length > 0) {
console.log("PFAND: Items aus getCurrentCart():", currentCart.lineItems.length);
return { additionalFees: berechnePfand(currentCart.lineItems) };
} else {
console.log("PFAND: Warenkorb leer, keine Zusatzgebühr");
return { additionalFees: [] };
}
});
}
}
function berechnePfand(lineItems) {
const pfandKeyword = “PANEDA”;
const pfandBetragProStück = 0.25;
const pfandItems = lineItems.filter(item =>
(item.productName || "").toLowerCase().includes(pfandKeyword.toLowerCase())
);
console.log(`PFAND: Gefundene Pfand-Produkte: ${pfandItems.length}`);
if (pfandItems.length === 0) {
return [];
}
const totalPfand = pfandItems.reduce((sum, item) => {
const qty = item.quantity || 1;
return sum + (qty * pfandBetragProStück);
}, 0);
console.log(`PFAND: Berechneter Pfandbetrag: ${totalPfand.toFixed(2)} €`);
// price als String (korrektes Format für Wix additionalFees)
return [
{
name: "Dosenpfand",
price: totalPfand.toFixed(2) // String, z.B. "0.75"
}
];
}
Working in
Wix Studio Editor
What I’m trying to do
is add an additional fee for refund for cans.
**What do I need to do in order to see the additional fee in the cart in the frontend?
Thanks in advance!**