I’m trying to build a function so that if a customer adds a product with a specific tag, that will add a free gift to their cart. I’m using the expand operation to add the gift and set it’s price to 0 - this works fine.
expandedCartItems: [
{
merchandiseId: line.merchandise.id,
quantity: 1,
price: {
adjustment: {
fixedPricePerUnit: {
amount: (line.cost.totalAmount.amount / line.quantity).toFixed(2),
}
}
}
},
{
merchandiseId: FREE_GIFT_VARIANT_ID,
quantity: 1,
price: {
adjustment: {
fixedPricePerUnit: {
amount: 0,
}
}
}
},
]
The issue is, if the customer increases the quantity, the gift also increases. I want to limit the gift to a maximum of 1 in their cart, is this not possible using expand? If so, what is the alternative?
I’m ripping my hair out with 100 tabs open, and a hateful conversation with chat GPT - any help would be much appreciated, thanks!