Troubleshooting · Developer docs

Troubleshooting

Grouped by symptom, never by module, because the person with the problem does not know which module has it. One hundred questions across ten pages, each answered with the causes in the order they usually turn out to be true.

Answer Commerce

Add to cart says the item has variants, or a line shows as unavailable with a quantity message

Adding to the cart answers 200 either way, so the reason is in the cart's messages, as an error. There are three causes, most likely first:

  1. The form sends the product's own code, but the product has variants. Once a product has variants, only a variant can go in the cart, and the add answers "Item could not be added to cart as it has variants, one of them has to be chosen instead". Send the chosen variant's SKU, as the product page on Catalogue pages does. A line for that product that is already in the cart stays unavailable with "Item has variants, one of them has to be chosen instead"; remove it.
  2. The quantity breaks one of the product's purchase controls. The line stays in the cart at the quantity asked for, marked available: false, with a message that names the rule, such as "At least 4 of Gift card is required; the cart has 3". It stays unavailable until the quantity is changed. Lines with the same product code count together, so two lines of one product with different attributes add up, and changing one line can make the others available again.
  3. The overall quantity counts past orders. "At most 5 of Gift card can be purchased in total; 3 already purchased, the cart has 3" counts the orders the customer has already placed, within the overall period when one is set. A guest cart with no customer record counts the cart only, so a returning customer can be refused a quantity a guest is allowed. A message without the purchased part is the same rule, shown to anyone who is not signed in as that customer.

A line held back by a purchase control looks like this in the cart's answer:

JSON
{
  "result": "success",
  "data": {
    "cart": {
      "messages": [
        {"id": 312, "status": "error", "text": "At least 4 of Gift card is required; the cart has 3"},
        {"id": 313, "status": "info", "text": "Item has been added"}
      ],
      "items": [
        {"id": 27, "productCode": "GIFT-CARD", "quantity": 3, "available": false}
      ]
    }
  }
}

The "Item has been added" info comes with the error, so check each line's available as well as the messages. An unavailable line is left out of the total and out of the checkout until the quantity fits.

The rules are set on the product's or variant's Purchase controls tab (Products Entity). Changing the cart lists every cart message and how unavailable lines behave.

More in Commerce

  1. The cart empties between pages
  2. The cart count is wrong or stale
  3. A discount code is rejected for no visible reason
  4. Shipping rates do not appear at checkout
  5. Checkout says some items cannot be fulfilled

Was this page helpful?

Your answer goes to the docs team.