Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Custom parameters not taking into account for cache invalidation #1771

Open
LucasReyre opened this issue May 2, 2024 · 6 comments
Open
Labels
Acknowledged Team has responded to issue BUG P1 git2gus Label regression

Comments

@LucasReyre
Copy link

Summary

When updating basket (useShopperBasketsMutation('updateBasket') of commerce-sdk) with a custom parameter in the query it seems that the cache is not in invalidated data.
This causes the basket object not to be updated with the data coming from the PATCH basket.

Steps To Reproduce

1 - Create hook to update an attribute in the basket

function basketAfterPATCH(basket, basketInput) {
    try {
        if (basket && basketInput) {
            const basketRequestHelper = require('*/cartridge/scripts/helpers/basketRequestHelper');
            const { updatePrices } = basketRequestHelper.getPatchBasketQueryParameters();
            if (updatePrices) {
                basket.getProductLineItems().toArray().forEach((productLineItem) => {
                    productLineItem.setPriceValue(productLineItem.getPriceValue() - 1);
                });
            }
        }
        basketCalculationHelpers.calculateTotals(basket);
    } catch (e) {
        return new Status(Status.ERROR);
    }
    return new Status(Status.OK);
}

2 - Update the basket

    const {data: basket} = useCurrentBasket()
    const updateBasket = useShopperBasketsMutation('updateBasket')

    const handleUpdateBasket = async (displayedError) => {
        await updateBasket.mutateAsync(
            {
                parameters: {
                    basketId: basket?.basketId,
                    c_updatePrices: true
                },
                body: {}
            },
            {
                onSuccess: (basket) => {
                    console.log('basket updated', basket)
                }
            }
        )
    }

Expected result

I'm supposed to have my basket object updated with the actual values

Actual result

My basket has been well updated but not the cache basket object.
I've test without the custom parameter and everything is working well.

System Information (as applicable)

Node version: 18.17
@salesforce/retail-react-app: 2.4.0

@vmarta vmarta added the BUG P1 git2gus Label regression label May 4, 2024
@vmarta
Copy link
Contributor

vmarta commented May 4, 2024

@LucasReyre I was able to reproduce what you saw. Thanks for reporting this bug.

Copy link

git2gus bot commented May 4, 2024

This issue has been linked to a new work item: W-15678650

@vcua-mobify vcua-mobify added the Acknowledged Team has responded to issue label May 6, 2024
@LucasReyre
Copy link
Author

LucasReyre commented Oct 25, 2024

Hello @vmarta

Is there any news concerning this bug ?
it’s struggling us on our project.
Our do you have any workaround to make it works ?

Thanks

@joeluong-sfcc
Copy link
Collaborator

Hi @LucasReyre unfortunately we have not picked up this work yet, but I'll reach out to the team to see if there's a feasible workaround.

@kevinxh
Copy link
Collaborator

kevinxh commented Nov 6, 2024

@LucasReyre This isn't supported yet and i wonder if there is a workaround... I'm not sure but it may be a way to temporarily unblock the issue.

update your useBasket to include the same custom query parameter, that will make the basket query and mutation to have the same cache key.

useBasket({
    parameters: {
        basketId: basket?.basketId,
        c_updatePrices: true
    }
})

@LucasReyre
Copy link
Author

Thanks @kevinxh for the workaround, it's not ideal but it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Acknowledged Team has responded to issue BUG P1 git2gus Label regression
Projects
None yet
Development

No branches or pull requests

5 participants