如何在shopify Storefront API中获取给定客户的购物车详细信息或购物车ID

问题描述 投票:0回答:1

我正在使用 shopify Storefront API 创建一个电子商务网站。当我使用 cartCreate 突变创建购物车时,我得到一个购物车 id,graphql 突变如下:

 mutation createCart($input: CartInput!) {
    cartCreate(input: $input) {
      cart {
        id
      }
    }
  }

我可以使用购物车 ID 来获取购物车详细信息。 graphql 查询如下:

query {
  cart(
    id: "gid://shopify/Cart/1"
  ) {
    id
    createdAt
    updatedAt
    lines(first: 10) {
      edges {
        node {
          id
          quantity
          merchandise {
            ... on ProductVariant {
              id
            }
          }
          attributes {
            key
            value
          }
        }
      }
    }
    attributes {
      key
      value
    }
    cost {
      totalAmount {
        amount
        currencyCode
      }
    }
    buyerIdentity {
      email
      phone
    }
  }
}

但问题是,当用户注销或更改设备时,有任何方法可以使用客户令牌或其他方式获取购物车 ID,以便我能够获取购物车详细信息。

shopify shopify-app shopify-api shopify-storefront-api
1个回答
0
投票

用户通过身份验证后,您可以使用 Storefront API 的客户查询来获取客户的购物车信息。具体来说,您需要查询购物车的 ID。这是一个 GraphQL 查询示例, (将“YOUR_CUSTOMER_ACCESS_TOKEN”替换为登录用户的实际客户访问令牌):

query {
  customer(customerAccessToken: "YOUR_CUSTOMER_ACCESS_TOKEN") {
    id
    email
    cart {
      id
    }
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.