Unified Discount Function Scaffolding Creates Product-Type Extension by Default

Hey everyone :waving_hand:

I ran into something odd with the new unified discount function scaffolding in Shopify CLI and wanted to check if others have seen this too.

When creating a discount function using the new type = “function” scaffold, the generated shopify.extension.toml automatically sets:

type = “function”

[[extensions.targeting]]
target = “cart.lines.discounts.generate.run”

Even though my code clearly returns an order-level discount using orderDiscountsAdd, any discount created in Admin shows up in GraphQL as:

“discountClass”: “PRODUCT”

That means the function is being registered as a Product Discount Function, even though it behaves like an Order Discount Function.

This causes odd behavior in the Admin (e.g. “combine with order discounts” not working correctly) and inconsistent data in GraphQL.

Has anyone else seen this with the new scaffolding? Should the CLI perhaps default to cart.orderDiscounts.run when creating order-type discount functions?

– Seth

Hello, Seth!

How are you creating the app discount in the Admin? That will be where you need to specify whether the discount class is PRODUCT, ORDER, or both. For example, if you are using the discountAutomaticAppCreate mutation to create the discount, then you will need to specify the discountClasses like: "discountClasses": ["ORDER"]