I have a successful Shopify function that has replaced the Script Editor (hooray!) for discounting for logged in members for certain products. The discount looks for tags in both the customer and product. Works great.
Do I need a separate file to do another discount, say logged in customers get X% off certain tagged products, and push to the same “application” in my Partner account and then install via GraphQL?
Or do I need to adapt my current code base (modified from the template) which is not obvious to me?
Here is a snippet of the current code base: (Javy based) –
export function run(input) {
const customer1 = input.cart.buyerIdentity?.customer?.active_sub;
console.error("customer1 value = " + customer1);
const targets = input.cart.lines
// Only include cart lines with a quantity of two or more
// and a targetable product variant
.filter(line => line.quantity >= 1 &&
line.merchandise.__typename == "ProductVariant" && customer1 == true && line.merchandise.product.member_price == true && line.sellingPlanAllocation?.sellingPlan.name != "Delivery every 1 Month" && line.sellingPlanAllocation?.sellingPlan.name != "Delivery every 1 Month, Charge every 3 Months")
.map(line => {
const variant = /** @type {ProductVariant} */ (line.merchandise);
return /** @type {Target} */ ({
// Use the variant ID to create a discount target
productVariant: {
id: variant.id
}
});
});
[I’m filtering out subscription products to discount only one time purchase versions, based on customer tags and product tags set up in the run.graphql file.]
I know its probably obvious, but do I:
A. Adapt the current code base to somehow add more discount types to the discount target array?
B. Create a new template using npm and deploy to my existing Partner App, install new discount function onto my store using Graphql?
Thanks.