简体   繁体   English

我可以在 Tapcart 应用程序上使用 Shopify Ajax API 吗?

[英]Can I use Shopify Ajax API on Tapcart app?

I'm currently exploring making some updates to the product detail page on my mobile app on Tapcart .我目前正在探索对Tapcart上我的移动应用程序的产品详细信息页面进行一些更新。 I would have to make use of Tapcart custom blocks and the Shopify AJAX api to retrieve a list of products and their tags.我将不得不使用 Tapcart 自定义块和 Shopify AJAX api 来检索产品列表及其标签。

I have read the Shopify ajax documentation which says:我已阅读Shopify ajax 文档,其中说:

You can't use the Ajax API on a Shopify custom storefront.您不能在 Shopify 自定义店面中使用 Ajax API。

Does Tapcart count as a custom storefront? Tapcart 算作自定义店面吗? I'm guessing the answer is yes and that means I would have to look for alternatives, or most likely abandon my ideas but I was hoping someone would be able to confirm or deny my suspicion.我猜答案是肯定的,这意味着我将不得不寻找替代方案,或者很可能放弃我的想法,但我希望有人能够证实或否认我的怀疑。

Yes you can do this, here's a boilerplate example:是的,你可以这样做,这是一个样板示例:

(You can go here for other examples too - https://github.com/Tapcart-Templates ) (您也可以在此处 go 获取其他示例 - https://github.com/Tapcart-Templates

const STOREFRONT_ACCESS_TOKEN = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
const GRAPHQL_URL = "https://tapcart-boutique.myshopify.com/api/2022-10/graphql.json";
const productIds = `["gid://shopify/Product/7444358463640"]`;
const productQuery = () => `
  query {
    nodes(ids: ${productIds}) { 
      ... on Product {
        id
        title
        handle
        tags
      }
    }
  }
`;

const GRAPHQL_BODY = () => {
  return {
    async: true,
    crossDomain: true,
    method: "POST",
    headers: {
      "X-Shopify-Storefront-Access-Token": STOREFRONT_ACCESS_TOKEN,
      "Content-Type": "application/graphql",
    },
    body: productQuery(),
  };
};

fetch(GRAPHQL_URL, GRAPHQL_BODY())
  .then((res) => res.json())
  .then((productResponse) => {
    console.log(productResponse);
  });

When you've retrieved all the needed product IDs from Shopify, you can use the openProduct app action to switch to different PDPs.从 Shopify 检索到所有需要的产品 ID 后,您可以使用openProduct应用操作切换到不同的 PDP。 Make sure to use the isRelatedProduct boolean (set it to true ) to ensure the transition is smooth as butter.确保使用isRelatedProduct boolean(将其设置为true )以确保过渡顺畅。

https://docs.tapcart.com/docs/app-actions https://docs.tapcart.com/docs/app-actions

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM