Skip to content

Question about multiple change request on mutation (change quantity to 0) #93

Discussion options

You must be logged in to vote

@menya-TIS
I guess I didn't read the Shopify docs carefully.
The item keys shouldn't be the root props of the object.
It should be like this:

{
  updates: {
    cart_item_key1: 0,
    cart_item_key2: 0
  }
}

So the code should be the following:

const removeCrossProductsWithoutMain = () => {
  // ...
  const cart = window?.liquidAjaxCart?.cart

  const updates = {}
  cart.items.forEach(item => {
    if (!hasMainInCart) {
      updates[item.key] = 0;
    }
  });

  if (Object.values(updates).length > 0) {
    return {
      requests: [
        {
          type: 'update',
          body: { updates }
        }
      ]
    }
  }
  return null;
}

Could you try one more time and let me know pls…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@menya-TIS
Comment options

@EvgeniyMukhamedjanov
Comment options

Answer selected by menya-TIS
@menya-TIS
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants