[英]Using Shopify JS Buy SDK, unable to remove variant item from cart
I have a button to remove an item from the cart on my cart page, but I'm receiving this error: Variable $lineItemIds of type [ID!]!在我的购物车页面上,我有一个按钮可以从购物车中删除商品,但我收到此错误:类型为 [ID!] 的变量 $lineItemIds! was provided invalid value .
提供的值无效。
I've gone through the GraphQL list and tried every single ID, title, and variant, but it still gives me this error.我浏览了 GraphQL 列表并尝试了每一个 ID、标题和变体,但它仍然给我这个错误。 Which ID should I be using and how should I format the ID correctly?
我应该使用哪个 ID,我应该如何正确格式化 ID?
$('.remove-item').on('click', function() {
const lineItems = checkout.attrs.lineItems;
const checkoutId = 'gid://shopify/Checkout/xxxxxxxxxxx';
var dataid = this.getAttribute('data-id');
var varid = btoa(lineItems[dataid].variant.id);
var lineItemsToRemove = [{
variantId: varid,
quantity: 1
}];
client.checkout.removeLineItems(checkoutId, lineItemsToRemove).then((checkout) => {
});
});
After reviewing the documentation, I realized I was adding an id attribute.查看文档后,我意识到我正在添加一个 id 属性。 It should just pass the plain ID.
它应该只传递普通 ID。
var lineItemsToRemove = [
varid2
];
instead of代替
var lineItemsToRemove = [{
id:varid2
}];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.