Cart transform / discount functions not triggering?

My question is:

  • What triggers the cart transform or discount shopify function?

Problem: right now whenever I add an item or update an item in cart, I dont see any response or logs from shopify functions

My steps were:

  1. shopify app extensions generate (pick cart transform or discount
  2. add println!(“test cart transform run”) statement
  3. shopify app deploy
  4. shopify app dev
  5. add an item to cart

But I saw no logs

For test app purposes, I created two shopify function extensions. I just use the default shopify app extensions generate and i wanted cart transform or discount with all default code + println

Did you register the functions in the backend? If no UI, you have to do this via API (just use GraphiQL or the app graphql explorer).

The following is just an example for discount functions specific.

query {
  shopifyFunctions(first: 25) {
    nodes {
      app {
        title
      }
      apiType
      title
      id
    }
  }
}
mutation {
  discountAutomaticAppCreate(
    automaticAppDiscount: {
      title: "Cart line, Order, Shipping discount"
      functionId: "YOUR_FUNCTION_ID_HERE"
      discountClasses: [PRODUCT, ORDER, SHIPPING]
      startsAt: "2025-01-01T00:00:00"
    }
  ) {
    automaticAppDiscount {
      discountId
    }
    userErrors {
      field
      message
    }
  }
}
1 Like

Hi Curzey,

Yes you’re right! I did not register for discountApp. that’s the reason for discount but what about the cart transform? I also created cart transform but nothing was triggered?

Here’s the cart_transform_run.rs and graphql file (they’re the default code)

use super::schema;
use shopify_function::prelude::*;
use shopify_function::Result;

#[shopify_function]
fn cart_transform_run(
    _input: schema::cart_transform_run::CartTransformRunInput,
) -> Result<schema::CartTransformRunResult> {
    let _ = _input;
    println!("cart_transform_run");
    let no_changes = schema::CartTransformRunResult { operations: vec![] };

    Ok(no_changes)
}

query CartTransformRunInput {

  cart {

lines {

id

quantity

merchandise {

__typename

        ... on ProductVariant {

id

title

        }

      }

    }

  }

}

I dont really know much rust, so can’t really tell.

Do you see your CartTransform in the settings?


https://admin.shopify.com/settings/checkout

Cart Transforms would need to use cartTransformCreate:

Full tutorial:

1 Like

Oh yeah of course. Forgot to mention that explicitly.