Problem/Motivation
The Commerce Webform Order webform handler allows to reference different entity types with different identifiers (either UUID, variation_id, SKU). The query in \Drupal\commerce_webform_order\Plugin\WebformHandler\CommerceWebformOrderHandler::loadEntityValue() then tries to load the referenced entity by all these different properties. This may result in the incorrect product added to the cart, since MySQL casts a UUID string to an INT.
Steps to reproduce
Assume the following data:
commerce_product_variation:
| variation_id | uuid |
|---|---|
| 214 | d53c146e-e420-42b5-bef5-d344682acd96 |
| 1080 | 214abdb0-cc1e-4f67-bbb9-3e6e2a604bdf |
commerce_product_variation__field_data:
| variation_id |
|---|
| 214 |
| 1080 |
and execute the query:
SELECT commerce_product_variation.variation_id
FROM
commerce_product_variation base_table
LEFT JOIN commerce_product_variation ON commerce_product_variation.variation_id = base_table.variation_id
LEFT JOIN commerce_product_variation_field_data commerce_product_variation_field_data ON commerce_product_variation_field_data.variation_id = base_table.variation_id
WHERE (commerce_product_variation.uuid LIKE "214abdb0-cc1e-4f67-bbb9-3e6e2a604bdf" ESCAPE '\\') or (commerce_product_variation_field_data.variation_id = "214abdb0-cc1e-4f67-bbb9-3e6e2a604bdf")
This will find the product with variation_id 214 instead of 1080:

Proposed resolution
Apply the conditional entity loading from the configuration form to \Drupal\commerce_webform_order\Plugin\WebformHandler\CommerceWebformOrderHandler::loadEntityValue() :
Check if the value is a valid UUID: assume it is a UUID
Check if the value is numeric: assume it is a variation_id
Else: assume it is a SKU
Remaining tasks
- Write a patch
- Review
- Commit
User interface changes
None
API changes
None
Data model changes
None
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | Screenshot 2024-05-23 at 13.37.26.png | 16.82 KB | idebr |
Issue fork commerce_webform_order-3449355
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
idebr commentedComment #4
idebr commentedComment #5
facine commented@idebr, thanks for debugging and working on this issue.
I've added a comment on the PR itself; I think we should address the issue from there.
Comment #7
facine commentedComment #8
facine commentedFixed, thanks!