Solved

Shipping Discount Function Not Running in Checkout

minichimi
Shopify Partner
4 1 0

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...

Accepted Solution (1)

minichimi
Shopify Partner
4 1 0

This is an accepted solution.

Missed the part where you have to activate the discount using a GraphQL mutation, got it working 

View solution in original post

Reply 1 (1)

minichimi
Shopify Partner
4 1 0

This is an accepted solution.

Missed the part where you have to activate the discount using a GraphQL mutation, got it working