请耐心等待,因为我不是 Shopify 开发人员,并且构建的代码最初不是由我自己创建的。我正在与一个客户合作,该客户需要使用 Shopify 的无头应用程序创建单个产品,并且该产品创建一个变体,其中包含描述产品配置的行项目,我遇到的问题是行项目值我我传递的内容似乎太长了(无法从 Shopify 找到有关字符限制的文档)。
为了提供视觉效果,结帐如下所示(“此处的选项”是行项目选项值,当它太长时会造成严重破坏):
这是当订单项选项值太长时我的代码无法创建产品的地方:
const addProduct = async (req, res) => {
const { variants } = req.body;
console.log("Product create");
const query = `mutation {
productCreate(input: {
bodyHtml: "Just another custom product",
handle: "custom-product",
productType: "Custom Products",
title: "Custom Product",
vendor: "Client",
variants: ${JSON.stringify(variants).replace(/"([^"]+)":/g, "$1:")}
}){
product{
id
title
variants (first: 50) {
edges {
node {
id
title
price
sku
}
}
}
}
}
}`;
try {
const response = await shopify.graphql(query);
const published = await publishProduct(response.productCreate.product.id);
const parsedResponse = cleanGraphQLResponse(response);
return res.status(200).send({
message: "Product created",
product: { ...parsedResponse.productCreate.product, published },
});
} catch (error) {
console.log(error);
return res.status(501).send({ message: "Error", error });
}
};
在前端,信息是这样发送的:
const createCheckout = () => {
const report = obtainReport();
let totalPrice = 0;
let lineItemsConcat = '';
report.map((item, index) => {
const [title, value, price] = item;
totalPrice = totalPrice + (+price); //unary operator
lineItemsConcat = `${title}: ${value}; ${lineItemsConcat}`;
});
const lineItems = {
title: lineItemsConcat,
options: lineItemsConcat,
price: totalPrice,
sku: `Item-0`,
};
createShopifyProduct([lineItems]);
};
知道如何克服这个障碍吗?要么找到一种方法来传递单个订单项选项值中的所有信息,要么在 Shopify 的结帐中显示自定义信息。
感谢您的宝贵时间!
选项值的字符限制似乎是 255 个字符。我的有点有效的解决方案是在结帐中包含截断版本,并在订单确认电子邮件中包含完整版本。
在创建订单时,我添加了包含完整行项目的注释,然后编辑了订单确认电子邮件的 Liquid 模板,其中包含
note
变量。