Attempted to patch an order entity in Commerce and received an exception. The \Drupal\jsonapi\ParamConverter\EntityUuidConverter::convert fails due to the default language being und.

URL https://commerce2x-api.ddev.local/jsonapi/commerce_order/physical/667805...

{
  "jsonapi": {
    "version": "1.0",
    "meta": {
      "links": {
        "self": {
          "href": "http://jsonapi.org/format/1.0/"
        }
      }
    }
  },
  "errors": [
    {
      "title": "Method Not Allowed",
      "status": "405",
      "detail": "The requested translation of the resource object does not exist, instead modify one of the translations that do exist: und.",
      "links": {
        "via": {
          "href": "https://commerce2x-api.ddev.local/jsonapi/commerce_order/physical/667805a1-eb4d-4c3b-a821-2f135be4f5d4"
        },
        "info": {
          "href": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.6"
        }
      }
    }
  ]
}

The problem:


if ($method === 'PATCH' && $entity->language()->getId() !== $current_content_language) {
$available_translations = implode(', ', array_keys($entity->getTranslationLanguages()));
throw new MethodNotAllowedHttpException(['GET'], sprintf('The requested translation of the resource object does not exist, instead modify one of the translations that do exist: %s.', $available_translations));
}

The order's language is und but the current language is en.

The entire logic around if (in_array($method, ['PATCH', 'DELETE'], TRUE)) { should be ignored if the language for the entity is und.

CommentFileSizeAuthor
#3 3067405-3.patch1.24 KBmglaman

Comments

mglaman created an issue. See original summary.

mglaman’s picture

This conditional update fixed it, to ensure the entity is translatable:

if (in_array($method, ['PATCH', 'DELETE'], TRUE) && $entity instanceof \Drupal\Core\Entity\TranslatableInterface && $entity->isTranslatable()) {
mglaman’s picture

Status: Active » Needs review
StatusFileSize
new1.24 KB

Here is a patch to see if this breaks anything. Allowed me to PATCH an order.

Status: Needs review » Needs work

The last submitted patch, 3: 3067405-3.patch, failed testing. View results

mglaman’s picture

Status: Needs work » Closed (duplicate)

Yes, yes it is.