23181 fix product properties in schema aggregator output#23185
Open
23181 fix product properties in schema aggregator output#23185
Conversation
…oizer Callers iterating over indexables (notably the schema aggregator) need to temporarily redirect what `for_current_page()` resolves to and then restore the prior value. Expose this as an atomic save/restore helper instead of letting callers peek into the memoizer's internal cache.
…external schema When aggregating schema for multiple WooCommerce products, the `image` and `mainEntityOfPage` `@id`s on every `Product` piece were identical. Root cause: `WPSEO_WooCommerce_Schema` derives those `@id`s from `YoastSEO()->meta->for_current_page()`, which the memoizer resolves once per request — so the first product's canonical wins for all subsequent products. Prime the memoizer's current_page cache with each indexable's context around the external `collect()` call, and restore the previous value via `try/finally` (so a throwing integration can't leak the override). This fixes every per-product field generated by `WPSEO_WooCommerce_Schema` (image, mainEntityOfPage, variation images, BuyAction target), not just the two originally reported.
Coverage Report for CI Build 5Warning No base build found for commit Coverage: 49.913%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsRequires a base build to compare against. How to fix this → Coverage Stats
💛 - Coveralls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
@idvalues formainEntityOfPageandimageproperties.Summary
This PR can be summarized in the following changelog entry:
@idvalues formainEntityOfPageandimageproperties.Relevant technical choices:
Meta_Tags_Context_Memoizer::for_current_page()caches the first call's result.WPSEO_WooCommerce_Schemarelies onfor_current_page()for canonical/main_schema_id (per-product values), so every product after the first reuses the first product's URLMeta_Tags_Context_Memoizerthat allows to "swap" the current page, allowing to fetch data for each product.Test instructions
Test instructions for the acceptance test before the PR gets merged
This PR can be acceptance tested by following these steps:
Yoast SEO->Settings->Site featuresand turn onSchema aggregation endpointYOUR-BLOG-URL/wp-json/yoast/v1/schema-aggregator/get-schema/producthttps://schema-visualizer.yoast.com/Productpiece is connected to its ownImage, which is the same one referenced by theWebPageas mainEntityOfPage`Relevant test scenarios
Test instructions for QA when the code is in the RC
Impact check
This PR affects the following parts of the plugin, which may require extra testing:
Other environments
[shopify-seo], added test instructions for Shopify and attached theShopifylabel to this PR.[yoast-doc-extension], added test instructions for Yoast SEO for Google Docs and attached theGoogle Docs Add-onlabel to this PR.Documentation
Quality assurance
grunt build:imagesand commited the results, if my PR introduces new images or SVGs.Innovation
innovationlabel.Fixes #23181