Discounts don't work in the shopping cart via API/Velo for custom catalog items

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:[]
[...]

Thanks for posting this question!

I also encountered this issue yesterday.

I was attempting to use marchantDiscounts via the updateCart and same results as you. No error. No anything.

Excecpt in the documention I looked at it says that it can be applied to the entire cart if the line items are left empty.

So the documentation is unclear, possibly outdated or probably incomplete.

I am commenting here to follow this thread in hopes that a Wix Dev (actual Wix employee) replies to this topic.

1 Like

Hi!
Interestingly, in the REST/SDK API Reference, this merchantDiscounts array parameter also appears, but it is deprecated.

My only remaining hope is a solution to this bug, obviously, and also the DiscountRules, which currently do not support custom catalog items. Therefore, I need someone from the Wix development team to explain the reason for this bug and for not detailing the scope options in discount rules for catalog items via SPI, even if it’s just as a future improvement.

Regards,

I have bad news!

Wix devs sent email saying this merchantDiscounts API is not valid. That it was exposed by accident.

So it is not a viable API to use.

Hi, thank you so much for getting back to me!

I imagine that’s it. But have you tried using the automatic discounts (DiscountRules)? I was testing it here, so that it’s possible to change at least the scope of the item catalog, updating the discount through custom admin dashboard pages, but it always gives an invalid patch error. I would appreciate it if you could test it and tell me if it’s in the API or just an error on my part.

Regards,