Skip to content

getting nested element field#16789

Merged
brandonkelly merged 3 commits into5.xfrom
bugfix/getting-nested-element-field
Mar 3, 2025
Merged

getting nested element field#16789
brandonkelly merged 3 commits into5.xfrom
bugfix/getting-nested-element-field

Conversation

@i-just
Copy link
Copy Markdown
Contributor

@i-just i-just commented Feb 27, 2025

Description

When getting a field for the nested element, don’t bail because we couldn’t get an owner. When we can’t get the owner, we might still be able to get the field by ID.

Steps to reproduce:

  • have a fresh install of cms 5.6.6 or higher, with commerce 5.x
  • Create a multisite Craft installation with 2 sites.
  • Set up a single Commerce store.
  • Create a Commerce Product Type (enabled for both sites), enable versioning, and add a Matrix field (enabled for both sites) to the variant field layout.
  • Click “+ New Product.” on the product index page. While on the new product screen, click “+ New Product Variant.” In the variant slide-out add an entry to the Matrix field.
  • Click “Create Product Variant” on the variant (it should save successfully and close the slide-out).
  • Click “Create Product” on the product. You should see this error:
    CleanShot 2025-02-26 at 23 10 55@2x

if you edit an existing product and try to add a second/another variant, and the variant contains a new matrix entry, you’ll get an “Invalid owner ID: ” error.

Notes:

  • both exceptions are caused by the same problem;
  • they’re related to this change: f0fee32
  • it started happening in 5.6.6
  • it’ll only happen if you have revisions on for the product type (in a multisite setup)

The error is thrown when creating revisions. Creating a revision means duplicating an element. In the case above, the duplication needs to be propagated to other sites. When doing so, we setElementUri(). When we do this for the matrix entry (that is nested in a variant in this case), we call getUriFormat(), which calls NestedElementTrait::getField(). To get the field, we first try to get the owner/primary owner, which is not possible as the revision element is not yet saved in the database, so this query doesn’t return anything.

Related issues

reported by @lukeholder

@brandonkelly brandonkelly merged commit e9e9925 into 5.x Mar 3, 2025
@brandonkelly brandonkelly deleted the bugfix/getting-nested-element-field branch March 3, 2025 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants