Storefront API Custom field for checkout

Solved
Aichnerc
New Member
2 1 2

Good day,

I am currently developing a React application and connected your graphql Storefront API.

I have unauthenticated_write_checkouts, unauthenticated_read_checkouts enabled.

 

I require some custom values sent with the order which can be seen on the order overview page.

For example, I require to know if a customer chose the physical or digital version of a given, dynamic product. Adding variants is not an option.

 

I have seen that there is a customAttributes parameter you can give. I've tried it, but the values do not seem to show up.

Is there any way to send tags with the checkout?

 

My current code:

fragment CheckoutFragment on Checkout {
    id
    webUrl
    totalTax
    subtotalPrice
    customAttributes{
      key
      value
    }
    totalPrice
    lineItems (first: 250) {
      edges {
        node {
          id
          title
          variant {
            id
            title
            image {
              src
            }
            price
          }
          quantity
        }
      }
    }
  }
export const checkoutAttributesUpdateInput = gql`
  mutation checkoutAttributesUpdateInput ($key: String!, $value: String!) {
    checkoutAttributesUpdateInput(key: $key, value: $value) {
      userErrors {
        message
        field
      }
      checkout {
        ...CheckoutFragment
      }
    }
  }
  ${CheckoutFragment}
`;

Any hints are welcome. Thanks guys!

BenjB
New Member
2 0 0

@Aichnerc We need to do the exact same thing on our website, with the same technical stack.

Did you find any solution to your problem ? 

It could be great to know !  

Thanks !  

 

0 Likes
Aichnerc
New Member
2 1 2

This is an accepted solution.

Hey!

In the end we've decided to go with storing such information in the notes that you pass to the checkout.

Check out the repository for more information.

Best regards, Chris.

BenjB
New Member
2 0 0

Thanks @Aichnerc for sharing. Actually, I misunderstood your issue. In fact we just need to send customAttributes per lineItem, and we only need to see it in the Shopify Admin, not in the overview page as you do.

Anyway, your answer gave me informations about how to solve your issue and we could have to customize the overview page one day or another..!

For those how use Storefront API via shopify-buy library, this is how to deal with it adding custom attributes: https://www.npmjs.com/package/shopify-buy#adding-line-items, but it can also work when dealing with storefront API directly, without any wrapper like shopify-buy...

 

Thanks!

 

 

 

 

 

0 Likes