How to Update Default Product Image

Solved

How to Update Default Product Image

knot44
Visitor
2 0 0

I used the `productCreate` and `productVariantsBulkCreate` mutation to create the product and its variants. Is there a mutation available to update the default product image? I looked up the `productUpdate` mutation and couldn't find a property that can help me acheive this. Any advice on how I can do this?

Accepted Solution (1)

tlombardo
Shopify Staff
1 1 1

This is an accepted solution.

Thanks for posting your question. The productReorderMedia mutation serves this purpose. Once a media on a product is set to the 0th position, its the default product image.

 

   mutation ReorderProductMedia {
     productReorderMedia(
       id: PRODUCT_GID,
       moves: [
         {
           id: MEDIA_ID, # ID of the image you want to set as default
           newPosition: 0
         }
       ]
     ) {...response fields...}
   }

 

Please let us know if you run into any issues using this approach.

View solution in original post

Replies 3 (3)

tlombardo
Shopify Staff
1 1 1

This is an accepted solution.

Thanks for posting your question. The productReorderMedia mutation serves this purpose. Once a media on a product is set to the 0th position, its the default product image.

 

   mutation ReorderProductMedia {
     productReorderMedia(
       id: PRODUCT_GID,
       moves: [
         {
           id: MEDIA_ID, # ID of the image you want to set as default
           newPosition: 0
         }
       ]
     ) {...response fields...}
   }

 

Please let us know if you run into any issues using this approach.

knot44
Visitor
2 0 0

Is it enough if I just set the newPosition of just one element or do I need to change the positioning of all the other images on the product as well?

Kyle_liu
Shopify Partner
178 26 29

@knot44 

Just adjust the product images you need, the other images will be automatically arranged

If this is helpful, please Like and Accept the solution.
Want to modify or custom changes on store? Let me help.
- Feel free to contact me on (liushuaicc@shinetechsoftware.com)