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 · 2 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
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

3 participants