Discussing Shopify Functions development, deployment, and usage in Shopify apps.
I've created a couple cart validation extensions with no issues, but when trying to test a Shipping Discount function, it will not run after entering Shipping details on Checkout pages.
Steps to reproduce, create a new extension:
➜ dev-checkout git:(main) ✗ npm init @shopify/app@latest ➜ dev-checkout git:(main) ✗ shopify app generate extension Before proceeding, your project needs to be associated with an app. ? Create this project as a new app on Shopify? ✔ Yes, create it as a new app ? App name: ✔ dev-checkout│ │ │ Using shopify.app.toml: │ │ │ │ • Org: xxx. │ │ • App: dev-checkout │ │ │ │ You can pass `--reset` to your command to reset your app configuration. │ │ │ ? Type of extension? ✔ Discount shipping - Function ? Name your extension: ✔ shipping-discount ? What would you like to work in? ✔ JavaScript
Simple RunInput:
query RunInput { cart { buyerIdentity { email phone } } }
Simple run.js:
/** * @typedef {import("../generated/api").RunInput} RunInput * @typedef {import("../generated/api").FunctionRunResult} FunctionRunResult */ /** * @type {FunctionRunResult} */ const EMPTY_DISCOUNT = { discounts: [], }; /** * @param {RunInput} input * @returns {FunctionRunResult} */ export function run(input) { console.log("runnning shipping discount extension with input", input); return EMPTY_DISCOUNT; };
Ran typegen, dev install, and then deploy, and no runs show under the extensions monitoring in the partner dashboard.
Any idea what's wrong?
Found one other post with a similar issue https://community.shopify.com/c/extensions/shipping-discount-functions-is-not-running/m-p/2550792#M2...
Solved! Go to the solution
This is an accepted solution.
Missed the part where you have to activate the discount using a GraphQL mutation, got it working
This is an accepted solution.
Missed the part where you have to activate the discount using a GraphQL mutation, got it working