Skip to content

The addToCart mutation now uses merchandiseId instead of variantId #30

@endigo9740

Description

@endigo9740

First off I appreciate that you've shared this template. It's helped me greatly in setting up a Sveltekit-powered Shopify storefront. That said, it could probably stand for an update soon. The API is still defaulting to /2021-10/ version of the API from October 2021.

Most of the API I've touched has remained the same, but I've been roadblocked the last few days because one key name has changed...

In shopify.js the addToCart mutation key variantId is now merchandiseId.

Here's the full modification to the function:

export async function addToCart({ cartId, merchandiseId }) {
    return shopifyFetch({
        query: `
      mutation addToCart($cartId: ID!, $lines: [CartLineInput!]!) {
        cartLinesAdd(cartId: $cartId, lines: $lines) {
          cart {
            lines(first: 100) {
              edges {
                node {
                  id
                  quantity
                  merchandise {
                    ... on ProductVariant {
                      product {
                        title
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    `,
        variables: {
            cartId: cartId,
            lines: [
                {
                    merchandiseId: merchandiseId,
                    quantity: 1
                }
            ]
        }
    });
}

Just thought I'd share to help other folks beating their head against a wall like I have the last few days :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions