I’m having trouble with
I’m having trouble with a shopping cart I created; it’s not showing any of the discounts I requested using merchantDiscounts in createCart.
Working in
Wix Editor, Dev Mode, CMS
What I’m trying to do
Shopping cart via createCart from wix-ecom-backend
What I’ve tried so far
I’ve checked, and I’m aware that ‘merchantDiscounts’ might not work for the entire cart, but I’m testing it item by item, and it still doesn’t work. I tested with DiscountRules, but the scope only covers products from Wix Stores. I also tested with the customLineItems array object from CreateCart, but it doesn’t work either.
Extra context
The code is below.
import { orders, cart, checkout } from "wix-ecom-backend";
export const createNewCart = webMethod(
Permissions.Anyone,
async (projectId, selectedOptions) => {
const lineItems = [{
catalogReference: {
appId: appIdcatalog,
catalogItemId: projectId,
options: {
options: {
project: 'option1'
}
}
},
quantity: 1,
}];
[...]
const options = {
lineItems
};
try {
const newCart = await cart.createCart(options);
return newCart;
} catch (error) {
console.error(error);
}
},
);
// code page
import wixEcomFrontend from "wix-ecom-frontend";
import { updateCart, createNewCart } from 'backend/ecom.web';
[...]
$w('#btnsubmitOrder').onClick(async () => {
[...]
const newCartresult = await createNewCart(projectinfo._id, selectedOptions);
const { lineItems } = newCartresult
const updateCartresult = await updateCart(newCartresult._id, {
cartInfo: {},
merchantDiscounts: [
{
amount: "230.00",
lineItemIds: lineItems.map(item=>(item._id))
}
]
});
await wixEcomFrontend.refreshCart();
console.log(updateCartresult)
});
response updateCartresult:
[...]
discount: {
“amount”: “0”,
“convertedAmount”: “0”,
“formattedAmount”: “R$0,00”,
“formattedConvertedAmount”: “R$0,00”
},
[...]
appliedDiscounts:[]
[...]

