Find discounts without specific combines_with

Hi there,

We use discountNodes as below to retrieve all discounts with a specific prefix and then update each of the discounts where Shipping Discount is not enabled.

The problem with this is that it’s inefficient, if you have a lot of discounts and only 3 need updating.

I know you can use combines_with:shipping_discounts to get all discounts where that is enabled but I am looking for all discounts where it is not.

Note: I am using a webhook to update each discount as they are created (Google Shopping Feed does not support combinations) but we also need a fallback just in case to update all of the discounts that haven’t been processed by the webhook.

Does anyone know of a way to get all discounts with a code that contains a string and that either has no combines_with set, or at least combines_with:shipping_discounts not set?

query discounts($cursor: String) {
  discountNodes(query: "prefix-", first: 250, after: $cursor) {
    nodes {
      id
      discount {
        ... on DiscountCodeBasic {
          title
        }
        ... on DiscountCodeBxgy {
          title
        }
        ... on DiscountCodeFreeShipping {
          title
        }
        ... on DiscountAutomaticApp {
          title
        }
        ... on DiscountAutomaticBasic {
          title
        }
        ... on DiscountAutomaticBxgy {
          title
        }
        ... on DiscountAutomaticFreeShipping {
          title
        }
      }
    }
    pageInfo {
      endCursor
      hasNextPage
    }
  }
}

Hey @gRoberts,

as per shopify search syntax modifiers, I guess this is the what you want:

NOT combines_with:shipping_discounts AND NOT combines_with:order_discounts AND NOT combines_with:product_discounts AND title:MYPREFIX*

Please be advised that the *-Wildcard only works for prefixes on discounts, and does not work on the “code” field - yet for most cases the title search should be fine.

Hope this helps,

Kevin :hatching_chick:

Thanks @Kevin_Sieger

I’m still getting used to GraphQL and Shopify in general and knew there would be a negative modifier but hadn’t applied them correctly.

This works perfectly, thank you!

1 Like