Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getting nested element field #16789

Merged
merged 3 commits into from
Mar 3, 2025
Merged

Conversation

i-just
Copy link
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