Question

I have a simple product with custom options

while adding to cart i getting error

add a simple product to cart

  mutation {
  addSimpleProductsToCart(
    input: {
      cart_id: "jw7wY66RevjvCOzLMwZr71sj8aRA10gi"
      cart_items: [
        {
          data: {
            quantity: 1
            sku: "Custom option product 2"

          }
          customizable_options:[
          {
            id:2
            value_string:"new"
          }
        ]
        }
      ]
    }
  ) {
    cart {
      items {
        id
        product {
          sku
          stock_status

        }

        quantity
        ... on SimpleCartItem {
          customizable_options {
            label
            values {
              value
            }
          }
        }
      }
    }
  }
}

Response:

{
  "errors": [
    {
      "debugMessage": "Call to a member function getPriceType() on null",
      "message": "Internal server error",
      "category": "internal",
      "locations": [
        {
          "line": 33,
          "column": 11
        }
      ],
      "path": [
        "addSimpleProductsToCart",
        "cart",
        "items",
        0,
        "customizable_options"
      ]
    }
  ],
  "data": {
    "addSimpleProductsToCart": {
      "cart": {
        "items": [
          {
            "id": "34",
            "product": {
              "sku": "Custom option product 2",
              "stock_status": "IN_STOCK"
            },
            "quantity": 1,
            "customizable_options": null
          }
        ]
      }
    }
  }
}

Call to a member function getPriceType() on null

I searched but I couldn't find any idea about that?

does any one have an idea about that?enter image description here

Was it helpful?

Solution

finally, I found that

we need to give options id in - value_String

that it.

Request:

mutation {
  addSimpleProductsToCart(
    input: {
      cart_id: "6hWAcSEEIRC8Sofumlw0gEXZPkb5Z2QF"
      cart_items: [
        {
          data: {
            quantity: 1
            sku: "Custom option product 2"
          }
            customizable_options:[
          {
            id:2
            value_string:"3"
          }
        ]

        }
      ]
    }
  ) {
    cart {
      items {
        id
        product {
          sku
          stock_status

        }

        quantity
        ... on SimpleCartItem {
          customizable_options {
            label
            values {
              value
            }
          }
        }
      }
    }
  }
}

Response:

{
  "data": {
    "addSimpleProductsToCart": {
      "cart": {
        "items": [
          {
            "id": "37",
            "product": {
              "sku": "Custom option product 2",
              "stock_status": "IN_STOCK"
            },
            "quantity": 3,
            "customizable_options": [
              {
                "label": "Option 1",
                "values": [
                  {
                    "value": "3"
                  }
                ]
              }
            ]
          }
        ]
      }
    }
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top