Skip to content

How to implement BuyNowButton in Hydrogen v2? #559

Closed Answered by wizardlyhel
jgitt asked this question in Help
Discussion options

You must be logged in to vote

There's a couple mistakes in my code example:

Couple things to make sure:

1. In server.ts, make sure to override the cartMutateFragment so that it returns a checkout url. (In hindsight, we probably should make this a default field to return)

      const cart = createCartHandler({
        storefront,
        customerAccount,
        getCartId: cartGetIdDefault(request.headers),
        setCartId: cartSetIdDefault(),
        cartQueryFragment: CART_QUERY_FRAGMENT,
        cartMutateFragment: CART_MUTATE_FRAGMENT,
      });

const CART_MUTATE_FRAGMENT = `#graphql
  fragment CartApiMutation on Cart {
    id
    totalQuantity
    checkoutUrl
  }
` as const;

2. When adding a Buy now button, you…

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
5 replies
@guifangwu
Comment options

@andrijaO
Comment options

@jamalsoueidan
Comment options

@wizardlyhel
Comment options

Answer selected by wizardlyhel
@jamalsoueidan
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
6 participants