add price value to my shop in shopify

add price value to my shop in shopify

priceStruggle
Shopify Partner
1 0 0

Hi all,

 

I am creating a product throught my CMS to be added in shopify for the checkout:

 

const mutation = `
  mutation CreateProduct($product:ProductCreateInput) {
  productCreate(product: $product) {
    product {
      id
      title
      descriptionHtml
      productType
      vendor
      handle     
    }
    userErrors {
      field
      message
    }
  }
}`

  const { data, errors } = await getGraphQLClient().request(mutation, {
    variables: {
      product: {
        title: product.title,
        productType: product.productType,
        descriptionHtml: product.descriptionHtml,
        vendor: 'myShop',
        handle: product.handle,
      },
    },
  })

after i need to add the price, I got this from the ai asistant(after a lot of suffering and pain)

if (data) {
    const priceMutation = `
      mutation CreateVariant($input: ProductVariantInput!) {
        productVariantCreate(input: $input) {
          productVariant {
            id
            price
          }
          userErrors {
            field
            message
          }
        }
      }`
    await getGraphQLClient().request(priceMutation, {
      variables: {
        input: {
          productId: data.productCreate.product.id,
          price: product.price.toString(),
        },
      },
    })

then i add an image

 const uploadImageMutation = `
      mutation UploadImage($productId: ID!, $media: [CreateMediaInput!]!) {
        productCreateMedia(productId: $productId, media: $media) {
          media {
            status
            alt
            preview {
              image {
                url
              }
            }
          }
          userErrors {
            field
            message
          }
        }
      }
    `

    await getGraphQLClient().request(uploadImageMutation, {
      variables: {
        productId: data.productCreate.product.id,
        media: [
          {
            originalSource: product.imageUrl,
            mediaContentType: 'IMAGE',
            alt: product.title,
          },
        ],
      },
    })

the problem is that in my shopify store, I am able to see the product created, the image but not the price(it shows '0').


is there something I am missing?

Replies 0 (0)