Unable to load the specified entity of type commerce_product_variation after upgrade

Created on 7 September 2023, 10 months ago
Updated 19 April 2024, 2 months ago

Problem/Motivation

I was using 2.0.0-beta2 and was running module and security updates. I have updated to now 3.0.0-beta5. When I submit my webform, the form submits fine, however, I get a warning stating:

Exception: Unable to load the specified entity of type commerce_product_variation. in Drupal\commerce_webform_order\Plugin\WebformHandler\CommerceWebformOrderHandler->loadEntityValue() (line 1727 of /modules/contrib/commerce_webform_order/src/Plugin/WebformHandler/CommerceWebformOrderHandler.php).

I've run DB updates after composer updated all my modules. I tried deleting the handler and recreating it, but the issue persists. Any ideas?

πŸ› Bug report
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States rondog469

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @rondog469
  • First commit to issue fork.
  • @facine opened merge request.
  • πŸ‡ͺπŸ‡ΈSpain facine

    The error is that it does not find any variation with that ID.

    Please, could you export the webform and share only the handler part? it usually goes at the end of the file.

  • πŸ‡ΊπŸ‡ΈUnited States rondog469

    Hi @facine that is indeed the entity type It is set to. I didn't change anything from before. Here is the yml from the webform export

    handlers:
      commerce_webform_order_handler:
        id: commerce_webform_order
        handler_id: commerce_webform_order_handler
        label: 'Commerce Webform Order Handler'
        notes: ''
        status: true
        conditions: {  }
        weight: -49
        settings:
          store:
            store_entity: 7d425a50-ed52-4e92-810a-e3957d083cd8
            bypass_access: false
          order_item:
            order_item_id: ''
            purchasable_entity_type: commerce_product_variation
            purchasable_entity: ':input[name="sku"]'
            title: ''
            overwrite_price: false
            amount: ''
            currency: ''
            quantity: ':input[name="number_of_guests"]'
            order_item_bundle: default
            fields: {  }
          checkout:
            new_cart: false
            empty_cart: true
            combine_cart: true
            owner: ':input[name="email"]'
            owner_id: ''
            billing_profile_id: ''
            billing_profile_bypass_access: false
            payment_gateway_id: ''
            payment_method_id: ''
            cancel_url: ''
            hide_add_to_cart_message: true
            redirect: true
            order_state: ''
            order_data: ''
          sync: false
          webform_states:
            - completed
          order_states:
            - _new_order_
            - 'order_default:draft'
          prevent_update: false
          debug: false
    

    In the handler settings, I have "Purchasable entity type" set to "Product Variation" and that appears to be setting it to that "commerce_product_variation" value.

    Also looking at the form on prod (2.0.0-beta2) and my local (3.0.0-beta5), "Purchasable Entity Type" is not available in version 2.

    I am posting pics of my form settings. Basically the hidden SKU field on my webform contains the commerce product value. I onlyhave two products, "public_tour" and "private_tour".

  • πŸ‡ΊπŸ‡ΈUnited States rondog469

    still trying to figure out the problem here. Any ideas?

  • πŸ‡ͺπŸ‡ΈSpain facine

    @rondog469, I think this could be related whith: πŸ› Broken webform configuration after update. Fixed

    Please could you try it with the latest dev version?

    Thanks

  • πŸ‡²πŸ‡ΎMalaysia ckng

    Facing the same issue when upgrading from 2.0.0-beta2 (core D9) to 3.0.0-beta10 (core D10), this should be the same as the current dev copy.

  • πŸ‡²πŸ‡ΎMalaysia ckng

    In 2.x, the purchasable item commerce_product_variation is loading the entity with ['variation_id', 'sku']:

        $prepared_data['product_variation'] = $this->loadEntityValue(
          $data['order_item']['product_variation_entity'],
          'commerce_product_variation',
          ['variation_id', 'sku']
        );
    

    But in 3.x, ['uuid', 'variation_id'] are passed. 'sku' is missing leading to error and unable to load the entity, as the $value queried in CommerceWebformOrderHandler->loadEntityValue() is the 'sku' value. But the source of the issue is the 'sku' key is missing from commerce_product_variation entity keys. Maybe we need a special handling here?

  • πŸ‡ΊπŸ‡ΈUnited States rondog469

    @ckng as I find myself back in this same spot, did you come up with a solution? Our round for security updates are upon us again. If not I am going to look into that loadEntityValue you found and see if I can come up with a patch

  • πŸ‡ΊπŸ‡ΈUnited States rondog469

    Looking at line 1382 of CommerceWebformOrderHandler.php

    foreach (['uuid', 'id', 'sku'] as $key) {
      $entity_keys[] = $entity_type->getKey($key);
    }
    

    'sku' is always false as that key does not exist.

    I think I managed to fix this for my case though. When setting up the webform handler, for "Purchasable entity" I've been using a hidden input field that contains the SKU. That is what was working on 2.x. I have since changed it to "Reference one..." and manually added my two products via the autocomplete field that appears when choose reference one.

    This is by no means the correct solution. I only have 2 products so this was easy. There is definitely something wrong with the way the $prepared_data['purchasable_entity'] is set in 3.x

  • πŸ‡ͺπŸ‡ΈSpain facine

    I think I've found the problem; it's in this update: https://git.drupalcode.org/project/commerce_webform_order/-/blob/3.x/com..., when support for Purchasable Entity was added, the IDs weren't converted to UUIDs. We would need to do the conversion just as we do here: https://git.drupalcode.org/project/commerce_webform_order/-/blob/3.x/src....

    I hope to be able to work on it soon

Production build 0.69.0 2024