简体   繁体   English

在我的 React 应用程序中实现一个功能,用户可以将我的产品添加到他们的 Shopify 商店

[英]Implement a feature in my React app where the users can add my products to their Shopify store

I have a website built with React and Gatsby and NodeJs in backend.我有一个在后端使用 React、Gatsby 和 NodeJs 构建的网站。 For state management I'm using Redux.对于 state 管理,我使用的是 Redux。 In this website I sell products and I'm trying to implement a new feature where each product will have a secondary button which says 'Add to Shopify', near the buy button.在这个网站上,我销售产品,我正在尝试实现一个新功能,每个产品在购买按钮附近都有一个二级按钮,上面写着“添加到 Shopify”。 I can access the product's data easily but the problem is creating a function which uses that data to add the selected product to their Shopify store.我可以轻松访问产品的数据,但问题是创建 function 使用该数据将所选产品添加到他们的 Shopify 商店。 It's kinda like dropshipping.这有点像直销。

One solution that it popped-up in my head was opening a pop-up or redirecting the user to their Shopify store where they can get authenticated (get the store name and accessToken) and make a post request to that store with my product's data.它在我脑海中弹出的一个解决方案是打开一个弹出窗口或将用户重定向到他们的 Shopify 商店,在那里他们可以获得身份验证(获取商店名称和 accessToken)并使用我的产品数据向该商店发出发布请求。

Is this possible to do and if yes, how can I tackle this problem?这可能吗?如果可以,我该如何解决这个问题?

If this is not the right way, can you help with another solution?如果这不是正确的方法,您能提供其他解决方案吗?

Yes, you have figured out the right approach.是的,您已经找到了正确的方法。

To do so, you need to create a public Shopify App .为此,您需要创建一个公共 Shopify App You can make the app listed or unlisted as you choose.您可以根据自己的选择将应用设为列出或不列出

Once a user clicks Add to Shopify , initiate the OAuth flow to get Access Token.一旦用户单击Add to Shopify ,启动OAuth 流程以获取访问令牌。 Once you have the Access Token, create Shopify product using REST API via Node.js Module for Shopify . Once you have the Access Token, create Shopify product using REST API via Node.js Module for Shopify .

To build redirect URL, so that Client can install your app directly, use something like要构建重定向 URL,以便客户端可以直接安装您的应用程序,请使用类似

https://{clien-shop-name}.myshopify.com/admin/oauth/authorize?client_id={api_key}&scope={scopes}&redirect_uri={...}

App Install using URL 使用 URL 安装应用程序

Sample code in your Node.js app would look something like Node.js 应用程序中的示例代码看起来像

const Shopify = require("shopify-api-node");
router.post("/your-end-point", async (req, res) => {
  try {
    const shopify = new Shopify({
      shopName: "your-shop-name",
      accessToken: "your-oauth-token",
    });
    const product = await shopify.product.create(req.body);
    res.status(200).send(product);
  } catch (ex) {
    console.log(ex);
  }
});

Do you want to know where to find the #1 winning products in the world?您想知道在哪里可以找到世界上排名第一的获奖产品吗? Register here and you will get to know all the winning products在这里注册,您将了解所有获奖产品

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

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