Function Discount Order not working

Topic summary

A developer is experiencing issues with a Shopify Function extension for order discounts that implements a “buy 3, get 4” promotion on products priced at $15.

Core Problem:

  • The function installs successfully on a local dev store but produces no logs or errors
  • The discount logic isn’t executing at all
  • Debug statements (eprintln!) aren’t appearing in logs

Technical Details:

  • Written in Rust using the shopify_function crate
  • Filters cart lines by unit price ($15), calculates complete promotion groups, and applies discounts to the order subtotal
  • Includes run.rs (main logic), run.graphql (cart query), and main.rs files
  • Uses DiscountApplicationStrategy::FIRST

Current Status:
The discussion remains open with no responses or solutions provided. The developer cannot diagnose the issue due to the complete absence of logging output, making it unclear whether the function is being triggered at all.

Summarized with AI on November 1. AI used: claude-sonnet-4-5-20250929.

Hi, the following Shopify app extension is not working:

use shopify_function::prelude::*;
use shopify_function::Result;

use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Default, PartialEq)]
#[serde(rename_all(deserialize = "camelCase"))]
struct Configuration {}

#[shopify_function_target(query_path = "src/run.graphql", schema_path = "schema.graphql")]
fn run(input: input::ResponseData) -> Result<output::FunctionRunResult> {

    eprintln!("Is getting into the cart line discount");

    let precio_unitario = 15.0; // Precio unitario del producto
    let productos_en_promocion = 4; // Lleva 4 productos
    let productos_a_pagar = 3; // Paga 3 productos

    // Obtener la cantidad total de productos en el carrito
    let cantidad_total = input.cart.lines.iter()
        .filter(|line| line.cost.amount_per_quantity.amount == shopify_function::prelude::Decimal(precio_unitario))
        .fold(0, |acc, line| acc + line.quantity);

    let grupos_completos = cantidad_total / productos_en_promocion;
    let productos_restantes = cantidad_total % productos_en_promocion;

    // Calcular el precio total con la promoción
    let precio_total = (grupos_completos as f64 * productos_a_pagar as f64 * precio_unitario) + (productos_restantes as f64 * precio_unitario);

    // Calcular el descuento aplicado
    let precio_original = cantidad_total as f64 * precio_unitario;
    let descuento = Decimal::from(precio_original - precio_total);
 

    if precio_original > precio_total {

        eprintln!("Is getting into the target one");

        Ok(output::FunctionRunResult {
            discounts: vec![output::Discount {
                message: Some("Special Promo: Pay 3 and take 4!".to_string()),
                value: run::run::output::Value::FixedAmount (output::FixedAmount {
                    amount: descuento,
                }),
                conditions: None,
                targets: vec![output::Target::OrderSubtotal(   
                    crate::run::run::output::OrderSubtotalTarget {
                        excluded_variant_ids: vec![],
                    }
                )],
            }],
            discount_application_strategy: output::DiscountApplicationStrategy::FIRST,
        })
    } else {

        Ok(output::FunctionRunResult {
            discounts: vec![],
            discount_application_strategy: output::DiscountApplicationStrategy::FIRST,
        })
    }

  
}

that’s my run.rs and here’s my
run.graphql

query Input {
  cart {
    lines {
      id
      quantity
      cost {
        amountPerQuantity {
          amount
          currencyCode
        }
      }
    }
  }
}

main.rs

use std::process;
pub mod run;

fn main() {
    eprintln!("Please invoke a named export.");
    process::exit(1);
}

I’m able to install the function extension into my local dev store. Still, it’s just not logging anything, or working at all, is a pay 3 take 4 function on products costing 15$ but is just not working at all, it doesn’t show anything on logs, and I can’t see what the issue is is because isn’t giving me any log/error.