我能够成功地访问我的API数据,现在我必须改变它。在我的组件中,我能够用这段代码记录数据。在我的应用程序中,有一个输入字段,在输入字段中,我输入一个名称来更改我的产品的名称,然后在单击某个按钮后选择一个产品。selectedExport是产品的ID,props.inputValue是输入字段。目录是store-test/web/frontend/components/ProductsModal.jsx
const handleSelect = () => {
console.log(selectedExport) // id of the product
console.log(props.inputValue); // inputed name for the product name to be changed to
handleModalChange();
handleSelectedExport([]);
handleSelectedExportAs([]);
};如何将这些数据传递给服务器文件?我在我的服务器文件中使用它来更新API,并且我假设我应该更改/api/2022-10/products/id,以及product.id和product.title的值。目录是store-test/web/index.js。这是index.jsx的一个子组件-test/web/前端/page/index.jsx
app.get(`/api/2022-10/products/id`, async (req, res) => { // how to change ID
const session = await Shopify.Utils.loadCurrentSession(
req,
res,
app.get("use-online-tokens")
);
const { Product } = await import(
`@shopify/shopify-api/dist/rest-resources/${Shopify.Context.API_VERSION}/index.js`
);
const product = new Product({session: session})
product.id = 632910392; // how to pass product id of chosen product
product.title = "New product title"; // how to pass new product name
const saveProduct = await product.save({
update: true,
});
res.status(200).send(saveProduct);
});发布于 2022-11-06 14:05:26
您别无选择,只能在商店注册应用程序,并获得write_products的权限,然后通过您可以设置的App传递您的ID和新标题。有了它,你就可以接受前端的改变,并让它们保持不变。App之所以工作,是因为Shopify拦截了PUT (实际上您会使用POST,但无论如何),并安全地打包它,然后Shopify就会访问您在安装代理时通知Shopify的App端点。因此出现了代理这个词。
https://stackoverflow.com/questions/74334786
复制相似问题