Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Can't create discountAutomaticBxgyCreate with customerBuys all items

Can't create discountAutomaticBxgyCreate with customerBuys all items

nnthuanspf
Shopify Partner
5 0 2

API: 2023-07

Use graphql

 

Query

mutation discountAutomaticBxgyCreate($automaticBxgyDiscount: DiscountAutomaticBxgyInput!) { discountAutomaticBxgyCreate(automaticBxgyDiscount: $automaticBxgyDiscount) { automaticDiscountNode { id automaticDiscount { ... on DiscountAutomaticBxgy { id createdAt startsAt endsAt status summary title usesPerOrderLimit customerGets { items { ... on DiscountProducts { products(first: 2) { nodes { id } } } } value { ... on DiscountOnQuantity { quantity { quantity } } } } customerBuys { items { ... on AllDiscountItems { allItems } } value { ... on DiscountQuantity { quantity } } } } } } userErrors { field code message } } }

Variables

{
  "automaticBxgyDiscount": {
    "usesPerOrderLimit": "1",
    "startsAt": "2023-06-08T04:52:53-04:00",
    "title": "Minium 2tr get 1 A auto",
    "customerGets": {
      "value": {
        "discountOnQuantity": {
          "quantity": "2",
          "effect": {
            "percentage": 1.0
          }
        }
      },
      "items": {
        "products": {
          "productVariantsToAdd": ["gid://shopify/ProductVariant/45002547069218"]
        }
      }
    },
    "customerBuys": {
      "value": {
        "amount": "2000000"
      },
      "items": {
        "all": true
      }
    }
  }
}

Response

{
    "data": {
        "discountAutomaticBxgyCreate": {
            "automaticDiscountNode": null,
            "userErrors": [
                {
                    "field": [
                        "automaticBxgyDiscount",
                        "customerBuys",
                        "items"
                    ],
                    "code": "BLANK",
                    "message": "Items in 'customer buys' must be defined"
                }
            ]
        }
    },
    "extensions": {
        "cost": {
            "requestedQueryCost": 22,
            "actualQueryCost": 10,
            "throttleStatus": {
                "maximumAvailable": 1000.0,
                "currentlyAvailable": 990,
                "restoreRate": 50.0
            }
        }
    }
}
Replies 3 (3)

Liam
Community Manager
3108 344 889

Hi Nnthuanspf,

 

Thanks for flagging this - will get in touch with the product team and see if this is expected behaviour and what the best process would be. What is the exact use case you are trying to achieve here?

 

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

nnthuanspf
Shopify Partner
5 0 2

Hi, @Liam, thanks for your feedback

 

I want to create a discount that applies to all products (buy), if the minimum price is reached, the customer will get a discount for a special product.

Thomas_MacLean
Shopify Partner
1 0 0

Hi,

 

I was having the same problem. The documentation does make it look like this should work, but if you try and do it in the admin UI you will also see that this is not possible.

The workaround is to create an "all products" collection (use automatic collection and where price > 0 for example), and then use this id in the collection.add 

 

 items: {
    all:false,
    collections:{
          add:["gid://shopify/Collection/ALL_COLLECTION_ID"]
   }
}