Hi Shopify Folks! I am facing an issue in applying discount based on variant properties through Shopify functions.
So what I wanted is that e.g if I have a variant A in the cart with property deal, the shopify discount should applied on this item. But if then I add the same variant A without the property deal the discount should not apply.
Right now I have written the logic based on property but it apply discount on the variant irrespective of whether it has that property or not.
So my understanding is that the shopify functions apply discount based on variant id only.
Is there a way I can achieve this?
Here is my shopify function logic
let items = input.cart.lines.filter((line) => line.att3?.value != null && line.quantity == 1 );
let firstItemDealId = items[0].att3.value;
if(firstItemDealId !== null ) {
targets = items
// Only include cart lines with a quantity of two or more
// and a targetable product variant
.filter(line => line.att3.value == firstItemDealId &&
line.merchandise.__typename == "ProductVariant")
.map(line => {
discount = line.att2.value.replace('%', '');
totalProducts = line.att1.value;
const variant = /** @type {ProductVariant} */ (line.merchandise);
//discount = line.properties.discount;
//console.log(discount);
return /** @type {Target} */ ({
// Use the variant ID to create a discount target
productVariant: {
id: variant.id
}
});
});
}
where line.att3.value is that property based on which I need to apply discount.
Here you can see the discount applied on first 2 line items. Variant is same but property is different.
Any help would be appreciated, Thanks.
