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.

Not able to get selling plan allocation for product variant

Not able to get selling plan allocation for product variant

Snehal64
Shopify Partner
2 0 0

Hi there, I want to get which selling plan associate with the product variants using storefront graphql API, I have already gotten the selling plan groups for the product, but not able to get which plan is associated with product variants. also, I have tried the "sellingPlanAllocations" (Ref :- https://shopify.dev/api/storefront/2022-04/objects/SellingPlanAllocation) connection but it gives me an error "Field 'sellingPlanAllocations' doesn't exist on type 'ProductVariant'".

Here is my storefront graphql code (i am not able to put whole code here so i add shorter version)

product(id: "gid://shopify/Product/'.$prd_list.'") {

 variants(first: 10){

  edges{

    node{

      id

      sellingPlanAllocations{

         edges{

           node{

             id

         }

     }

   }

}

and the code gives me an error: message: "Field 'sellingPlanAllocations' doesn't exist on type 'ProductVariant'" please provide me a way to fix this. Thanks

selling_plan_issue.png

Replies 3 (3)

JamesG
Shopify Staff
42 10 11

Hey @Snehal64 

What version of the storefront API are you using? 

In the 2022-04 version you linked there is a ProductVariant.sellingPlanAllocations connection, but it requires an argument, and there's no id field on the SellingPlanAllocation.

The sellingPlanAllocations also are not included on the admin API's ProductVariant, which uses the SellingPlanGroups instead. Is it possible you have the wrong endpoint? 

 
Hopefully that helps, but if you continue to see an unexpected result could you share the endpoint, your full query, and the X-Request-ID value from the response's headers so I can take a closer look?
 

Cheers,

JamesG | API Support @ 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

Snehal64
Shopify Partner
2 0 0

Hi JamesG,
Thanks for reply.
I am using 2022-04 API Version.
Can you please send me example of the "sellingPlanAllocations" query with product variant?
Thanks.

JamesG
Shopify Staff
42 10 11

Hey @Snehal64 

 

To find a selling plan id for the variant's on a product I used this with the storefront API :

 

endpoint: 

 

https://{{store}}.myshopify.com/api/2022-04/graphql.json

 

query:

 

query productSellingPlans($product: ID!) {
	product(id: $product) {
		variants(first: 3) {
			edges {
				node {
					id
					title
					sellingPlanAllocations(first: 1) {
						edges {
							node {
								sellingPlan{
									id
								}
							}
						}
					}
				}
			}
		}
	}
}

 

 

hope that helps

JamesG | API Support @ 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