ProductVariantTarget removed in new discount functions?

Hi,

I’m using 2025-07 rust implementation of discount functions. I was previously using CartLineTarget for applying discounts, but with multiple discounts I’m seeing that behave much differently than the older functions.

I noticed the documentation examples use ProductVariantTarget which is what I was using with the old discount functions so I wanted to see if that kept the same behavior. It looks like ProductVariantTarget isn’t actually in the graphql schema anymore even though it’s listed in the examples.

Is this just a mistake in the documentation? Was ProductVariantTarget removed in the new discount functions?

Example below from the documentation showing the ProductVariantTarget.

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

#[derive(Deserialize, Default, PartialEq)]
pub struct Configuration {
    discount_amount: f64,
    max_quantity: i32,
    product_id: String,
}

#[shopify_function]
fn cart_lines_discounts_generate_run(input: schema::cart_lines_discounts_generate_run::Input) -> Result<schema::CartLinesDiscountsGenerateRunResult> {
    let config: &Configuration = match input.discount().metafield() {
        Some(metafield) => metafield.json_value(),
        None => return Ok(schema::CartLinesDiscountsGenerateRunResult {
            operations: vec![],
        }),
    };

    let mut candidates = vec![];
    let mut remaining_quantity = config.max_quantity;

    for line in input.cart().lines().iter() {
        let variant = match &line.merchandise() {
            schema::cart_lines_discounts_generate_run::input::cart::lines::Merchandise::ProductVariant(variant) => variant,
            _ => continue,
        };

        if *variant.product().id() == config.product_id && remaining_quantity > 0 {
            let line_quantity = line.quantity();
            let discount_quantity = remaining_quantity.min(*line_quantity);
            remaining_quantity -= discount_quantity;

            candidates.push(schema::ProductDiscountCandidate {
                value: schema::ProductDiscountCandidateValue::FixedAmount(schema::FixedAmount {
                    amount: config.discount_amount.into(),
                    applies_to_each_item: Some(true),
                }),
                targets: vec![schema::ProductDiscountCandidateTarget::ProductVariant(schema::ProductVariantTarget {
                    id: variant.id().clone(),
                    quantity: Some(discount_quantity),
                })],
                message: Some("Discount applied".to_string()),
                associated_discount_code: None,
            });
        }
    }

    if candidates.is_empty() {
        return Ok(schema::CartLinesDiscountsGenerateRunResult {
            operations: vec![],
        });
    }

    Ok(schema::CartLinesDiscountsGenerateRunResult {
        operations: vec![
            schema::CartOperation::ProductDiscountsAdd(schema::ProductDiscountsAddOperation {
                selection_strategy: schema::ProductDiscountSelectionStrategy::First,
                candidates,
            }),
        ],
    })
}


The schema is only showing ‘CartLineTarget’ as an option for ProductDiscountCandidateTarget.

  """
  A method for applying a discount to a specific line item in the cart. A cart line is an entry in the
  customer's cart that represents a single unit of a product variant. For example, if a customer adds two
  different sizes of the same t-shirt to their cart, then each size is represented as a separate cart line.
  """
  cartLine: CartLineTarget
}

Thanks for the help.

– Adam

Hi Adam,

Thanks for reaching out about the Discounts Functions API!

ProductVariantTarget was removed in the new Discount Function API. This is because CartLineTarget provides more granular control over which cart lines a discount can apply to. This is especially important for cases where you have the same variant in multiple cart lines due to differences in line item properties, compatibility with bundles, etc.

The merchandise field lets you access variant information, so you can use that to narrow down which cart lines you would like to target in your Function.

The example Function provided in our documentation appears to be out of date. We’ll get that updated as soon as possible. Thanks for bringing that to our attention :slight_smile:

Let me know if you have any more questions about the Discounts API, happy to help!