I get this ajax when I add an item to cart :
fetch(Spree.routes.api_v2_storefront_cart_add_item, {
method: 'POST',
headers: SpreeAPI.prepareHeaders({ 'X-Spree-Order-Token': SpreeAPI.orderToken }),
body: JSON.stringify({
variant_id: variantId,
quantity: quantity,
options: options
})
}).then(function (response) {
switch (response.status) {
case 422:
response.json().then(function (json) { failureCallback(json.error) })
break
case 500:
SpreeAPI.handle500error()
break
case 200:
response.json().then(function (json) {
//console.log(variantId);
successCallback(json.data)
})
break
}
})
}
Spree.routes.api_v2_storefront_cart_add_item = Spree.pathFor('api/v2/storefront/cart/add_item')
How can I get this variantId on the backend when the button is clicked?
question from:
https://stackoverflow.com/questions/65938604/how-to-properly-pass-variantid-to-the-backend-rails 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…