如何在 Shopify 中清除购物车的属性?
How to clear a cart's attributes in Shopify?
以前,当我访问 /cart/clear
或执行以下操作时,它会清除我的购物车及其属性。现在,当我执行其中任何一项操作时,它会清除产品,但购物车属性仍然存在。我不确定这是最近的更改还是 Shopify 错误?
知道如何清除购物车的属性吗?
$.ajax({
type: "POST",
url: '/cart/clear.js',
success: function(){
alert('You cleared the cart!');
},
dataType: 'json'
});
我已经找到了一种方法,可以通过这样做将它们全部删除,这似乎过于复杂,但它确实有效。
$.ajax({
type: "GET",
url: '/cart.js',
dataType: 'json',
success: function(resp) {
var nullHash = {};
for ([key, value] of Object.entries(resp.attributes)) {
nullHash[key] = null;
}
$.ajax({
type: "POST",
url: '/cart/update.js',
data: {attributes:nullHash},
dataType: 'json'
});
}
});
或者如果你想按名称删除它们,你可以这样做:
var nullHash = {
'someAtt1': null,
'someAtt2': null,
'someAtt3': null
};
$.ajax({
type: "POST",
url: '/cart/update.js',
data: {attributes:nullHash},
dataType: 'json'
});
以前,当我访问 /cart/clear
或执行以下操作时,它会清除我的购物车及其属性。现在,当我执行其中任何一项操作时,它会清除产品,但购物车属性仍然存在。我不确定这是最近的更改还是 Shopify 错误?
知道如何清除购物车的属性吗?
$.ajax({
type: "POST",
url: '/cart/clear.js',
success: function(){
alert('You cleared the cart!');
},
dataType: 'json'
});
我已经找到了一种方法,可以通过这样做将它们全部删除,这似乎过于复杂,但它确实有效。
$.ajax({
type: "GET",
url: '/cart.js',
dataType: 'json',
success: function(resp) {
var nullHash = {};
for ([key, value] of Object.entries(resp.attributes)) {
nullHash[key] = null;
}
$.ajax({
type: "POST",
url: '/cart/update.js',
data: {attributes:nullHash},
dataType: 'json'
});
}
});
或者如果你想按名称删除它们,你可以这样做:
var nullHash = {
'someAtt1': null,
'someAtt2': null,
'someAtt3': null
};
$.ajax({
type: "POST",
url: '/cart/update.js',
data: {attributes:nullHash},
dataType: 'json'
});