I’ve script that provide discount to the customer that has tagged with “Employee” tag and based on product tag specific tag like “OFF50”, “OFF30” and “OFF20” . Like if customer has Employee tag then it check if products on cart has “OFF50”, “OFF30” and “OFF20” tag and provide the 50%, 30% and 20% off based on product tag . Now we want to migrate it to Shopify function.
I am not sure how to check multiple product tag using one function using DiscountApplicationStrategy.ALL . anyone have idea how can I do that?
Here is code:
query RunInput {
cart {
buyerIdentity {
customer {
hasTags(tags: ["Employee"]) {
tag
hasTag
}
}
}
lines {
id
merchandise {
...on ProductVariant {
id
product {
hasAnyTag(tags: ["OFF20","OFF30","OFF50"])
}
}
__typename
}
}
}
}
run.js:
// -check
import { DiscountApplicationStrategy } from "../generated/api";
/**
* @typedef {import("../generated/api").RunInput} RunInput
* @typedef {import("../generated/api").FunctionRunResult} FunctionRunResult
*/
/**
* {FunctionRunResult}
*/
const EMPTY_DISCOUNT = {
discountApplicationStrategy: DiscountApplicationStrategy.All,
discounts: [],
};
/**
* @param {RunInput} input
* @returns {FunctionRunResult}
*/
export function run(input) {
// Check if the customer has the "employee" tag
const customerTags = input.cart.buyerIdentity?.customer?.hasTags || [];
console.error("customer value = " + customerTags);
// how to check product tags here
return EMPTY_DISCOUNT;
};
Thanks !