Commit 1a9d722a8a0 for woocommerce

commit 1a9d722a8a0c8cdaed42f6a722e98c7c60ae5c44
Author: Sergey Mitroshin <sergeymitr@gmail.com>
Date:   Sun Nov 22 19:31:54 2026 -0500

    UCP: Misc. catalog improvements (#71173)

    Addresses minor issues with UCP catalog endpoints:
    1. Prevent excessive taxonomy lookups for product variations.
    2. Fix the spec inconsistency with variable products' "selected" values.
    3. Make "lookup" and "product" queries apply the filters.
    4. Add the required, empty payment_handlers registry to the UCP discovery profile.
    5. Keep empty JSON objects as objects when replaying a stored UCP idempotent response.

diff --git a/plugins/woocommerce/changelog/fix-ucp-default-selected b/plugins/woocommerce/changelog/fix-ucp-default-selected
new file mode 100644
index 00000000000..bb1760212e5
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-ucp-default-selected
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+UCP: Report the featured variant's options as selected when a catalog product request makes no selection.
diff --git a/plugins/woocommerce/changelog/fix-ucp-discovery-payment-handlers b/plugins/woocommerce/changelog/fix-ucp-discovery-payment-handlers
new file mode 100644
index 00000000000..a830d5ee4bc
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-ucp-discovery-payment-handlers
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+UCP: Include the required, empty payment handlers registry in the store's discovery profile.
diff --git a/plugins/woocommerce/changelog/fix-ucp-idempotency-replay-empty-object b/plugins/woocommerce/changelog/fix-ucp-idempotency-replay-empty-object
new file mode 100644
index 00000000000..095e76813d4
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-ucp-idempotency-replay-empty-object
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+UCP: Keep the empty payment handlers registry an object when a checkout request is retried with the same Idempotency-Key.
diff --git a/plugins/woocommerce/changelog/fix-ucp-lookup-price-filter b/plugins/woocommerce/changelog/fix-ucp-lookup-price-filter
new file mode 100644
index 00000000000..27cfd06809c
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-ucp-lookup-price-filter
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+UCP: Apply the price filter to the variants returned by catalog lookup and product requests.
diff --git a/plugins/woocommerce/changelog/fix-ucp-variation-term-lookups b/plugins/woocommerce/changelog/fix-ucp-variation-term-lookups
new file mode 100644
index 00000000000..c496fa35bae
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-ucp-variation-term-lookups
@@ -0,0 +1,4 @@
+Significance: patch
+Type: performance
+
+UCP: Stop running three term queries per variation when building catalog responses.
diff --git a/plugins/woocommerce/src/Internal/ProductFeed/Mapping/UcpProductMapper.php b/plugins/woocommerce/src/Internal/ProductFeed/Mapping/UcpProductMapper.php
index a930044991b..7eff6f67a28 100644
--- a/plugins/woocommerce/src/Internal/ProductFeed/Mapping/UcpProductMapper.php
+++ b/plugins/woocommerce/src/Internal/ProductFeed/Mapping/UcpProductMapper.php
@@ -3,6 +3,7 @@ declare( strict_types = 1 );

 namespace Automattic\WooCommerce\Internal\ProductFeed\Mapping;

+use Automattic\WooCommerce\StoreApi\Formatters\MoneyFormatter;
 use Automattic\WooCommerce\StoreApi\SchemaController;
 use Automattic\WooCommerce\StoreApi\Schemas\V1\ProductSchema;
 use Automattic\WooCommerce\StoreApi\Schemas\V1\Ucp\UcpProductSchema;
@@ -71,6 +72,13 @@ class UcpProductMapper implements ProductShapeMapperInterface {
 	 */
 	private $variant_budget = self::MAX_VARIANTS_PER_RESPONSE;

+	/**
+	 * Price filter of the response being built: optional `min` and `max` in minor units.
+	 *
+	 * @var array
+	 */
+	private $price_bounds = array();
+
 	/**
 	 * Constructor.
 	 *
@@ -84,10 +92,51 @@ class UcpProductMapper implements ProductShapeMapperInterface {

 	/**
 	 * Start a new response, clearing per-response state.
+	 *
+	 * @param array $price_bounds Optional `min` and `max` variant prices in minor units, both inclusive.
 	 */
-	public function begin_response(): void {
+	public function begin_response( array $price_bounds = array() ): void {
 		$this->truncations    = array();
 		$this->variant_budget = self::MAX_VARIANTS_PER_RESPONSE;
+		$this->price_bounds   = $price_bounds;
+	}
+
+	/**
+	 * Whether a price in minor units passes the response's price filter.
+	 *
+	 * @param int $amount Price in minor units.
+	 * @return bool
+	 */
+	private function in_price_range( int $amount ): bool {
+		return ( ! isset( $this->price_bounds['min'] ) || $amount >= $this->price_bounds['min'] )
+			&& ( ! isset( $this->price_bounds['max'] ) || $amount <= $this->price_bounds['max'] );
+	}
+
+	/**
+	 * Keep the variation ids whose displayed price passes the response's price filter.
+	 *
+	 * Reads the parent's cached price list, so no variation is loaded to be rejected.
+	 *
+	 * @param \WC_Product_Variable $product The variable product.
+	 * @param array                $variation_ids Variation ids, in the order to keep.
+	 * @return array
+	 */
+	private function filter_by_price( \WC_Product_Variable $product, array $variation_ids ): array {
+		if ( empty( $this->price_bounds ) ) {
+			return $variation_ids;
+		}
+
+		$prices    = $product->get_variation_prices( true )['price'] ?? array();
+		$formatter = new MoneyFormatter();
+
+		return array_values(
+			array_filter(
+				$variation_ids,
+				function ( $id ) use ( $prices, $formatter ) {
+					return isset( $prices[ $id ] ) && $this->in_price_range( (int) $formatter->format( $prices[ $id ] ) );
+				}
+			)
+		);
 	}

 	/**
@@ -223,7 +272,8 @@ class UcpProductMapper implements ProductShapeMapperInterface {
 	 * A selection narrows the variants to those matching every selected option.
 	 * One matching no variation is relaxed from its last option until one does,
 	 * and `selected` reports the options kept, as UCP requires. A request naming
-	 * a variation returns it first, with its own options as the selection.
+	 * a variation returns it first, with its own options as the selection. A
+	 * request naming neither gets the featured variation first, and its options.
 	 *
 	 * @param \WC_Product $product WooCommerce product.
 	 * @param array       $selected Selected option values, each `{ name, label, id? }`.
@@ -231,22 +281,34 @@ class UcpProductMapper implements ProductShapeMapperInterface {
 	 * @return array
 	 */
 	public function map_detail_product( \WC_Product $product, array $selected = array(), int $variation_id = 0 ): array {
-		if ( ! $product instanceof \WC_Product_Variable || ( empty( $selected ) && $variation_id <= 0 ) ) {
+		if ( ! $product instanceof \WC_Product_Variable ) {
 			return $this->map_product( $product );
 		}

 		$item = $this->item( $product );

+		if ( empty( $selected ) && $variation_id <= 0 ) {
+			return $this->map_featured_selection( $product, $item );
+		}
+
 		// UCP: a variant id fully determines the selection state, so the
 		// request's `selected` is ignored rather than merged.
 		if ( $variation_id > 0 ) {
+			// A named variation the price filter excludes excludes the product:
+			// its siblings would come back under a selection describing it.
+			if ( empty( $this->filter_by_price( $product, array( $variation_id ) ) ) ) {
+				return $this->map_item( $product, $item, array(), false, array() );
+			}
+
 			$selected = $this->variation_options_by_id( $item )[ $variation_id ] ?? array();
 		}

+		// Only matches inside the price filter stop the relaxation, as for the featured selection.
+		$in_range = $this->filter_by_price( $product, array_map( 'intval', array_column( (array) $item['variations'], 'id' ) ) );
 		$matching = array();

 		while ( ! empty( $selected ) ) {
-			$matching = $this->match_selection( $item, $selected );
+			$matching = array_values( array_intersect( $this->match_selection( $item, $selected ), $in_range ) );

 			if ( ! empty( $matching ) ) {
 				break;
@@ -297,6 +359,75 @@ class UcpProductMapper implements ProductShapeMapperInterface {
 		return $this->schema;
 	}

+	/**
+	 * Map a variable product with its featured variation first and `selected` set to its options.
+	 *
+	 * The featured variation is the first one matching the product's default
+	 * attributes, or the first visible one when they are unset or match nothing.
+	 * Only variations passing the price filter are considered.
+	 *
+	 * @param \WC_Product_Variable $product The variable product.
+	 * @param array                $item Its Store API item response.
+	 * @return array
+	 */
+	private function map_featured_selection( \WC_Product_Variable $product, array $item ): array {
+		$defaults = $this->default_selection( $product, $item );
+		$in_range = $this->filter_by_price( $product, array_map( 'intval', array_column( (array) $item['variations'], 'id' ) ) );
+		$matching = array_values( array_intersect( $this->match_selection( $item, $defaults ), $in_range ) );
+
+		// Default matches go first; the returned prices may still drop some, so the first variant built is featured.
+		$mapped   = $this->map_item( $product, $item, array(), false, array_merge( $matching, array_diff( $in_range, $matching ) ) );
+		$featured = (int) ( $mapped['variants'][0]['id'] ?? 0 );
+		if ( $featured <= 0 ) {
+			return $mapped;
+		}
+
+		$selected = $this->variation_options_by_id( $item )[ $featured ] ?? array();
+
+		// An attribute the featured variation leaves as "Any" takes the default.
+		$fixed = array_column( $selected, 'name' );
+		foreach ( $defaults as $default ) {
+			if ( ! in_array( $default['name'], $fixed, true ) ) {
+				$selected[] = $default;
+			}
+		}
+
+		$mapped['selected'] = $selected;
+
+		return $mapped;
+	}
+
+	/**
+	 * Read the product's default attributes as selected options.
+	 *
+	 * Read from the product, not the item's `default` term flags: those are
+	 * missing for custom attributes whose name has more than one word.
+	 *
+	 * @param \WC_Product_Variable $product The variable product.
+	 * @param array                $item Its Store API item response.
+	 * @return array List of `{ name, label }`.
+	 */
+	private function default_selection( \WC_Product_Variable $product, array $item ): array {
+		$attributes = $product->get_attributes();
+		$names      = $this->term_names( $item );
+		$defaults   = array();
+
+		foreach ( $product->get_default_attributes() as $key => $value ) {
+			$attribute = $attributes[ $key ] ?? null;
+			if ( '' === (string) $value || ! $attribute instanceof \WC_Product_Attribute || ! $attribute->get_variation() ) {
+				continue;
+			}
+
+			$name       = wc_attribute_label( $attribute->get_name(), $product );
+			$defaults[] = array(
+				'name'  => $name,
+				'label' => $names[ $name ][ (string) $value ] ?? (string) $value,
+			);
+		}
+
+		return $defaults;
+	}
+
 	/**
 	 * Build the Store API item response for a product or variation, as nested arrays.
 	 *
@@ -501,14 +632,23 @@ class UcpProductMapper implements ProductShapeMapperInterface {
 	 */
 	private function build_variants( \WC_Product $product, array $item, string $currency, array $required_variation_ids, bool $only_required, ?array $candidates ): array {
 		if ( ! $product instanceof \WC_Product_Variable ) {
-			return array( $this->build_simple_variant( $product, $item, $currency ) );
+			$variant = $this->build_simple_variant( $product, $item, $currency );
+
+			// As for variations, a product with no price set is outside any price filter.
+			if ( ! empty( $this->price_bounds ) && '' === (string) $product->get_price() ) {
+				return array();
+			}
+
+			return $this->in_price_range( $variant['price']['amount'] ) ? array( $variant ) : array();
 		}

 		$children = array_map( 'intval', null === $candidates ? $product->get_visible_children() : $candidates );
+		$children = $this->filter_by_price( $product, $children );
 		$required = array_values( array_intersect( $children, array_map( 'intval', $required_variation_ids ) ) );
 		$options  = $this->variation_options_by_id( $item );

-		if ( $only_required && ! empty( $required ) ) {
+		// With a price filter the named variations may all be gone; build nothing then.
+		if ( $only_required && ( ! empty( $required ) || ! empty( $this->price_bounds ) ) ) {
 			// Bounded by the request's own id cap; nothing left out, nothing to
 			// disclose.
 			$variants              = $this->build_variation_list( $required, $options, $currency );
@@ -557,7 +697,12 @@ class UcpProductMapper implements ProductShapeMapperInterface {
 				continue;
 			}

-			$variants[] = $this->build_variation_variant( $variation, $this->item( $variation ), $options[ (int) $variation_id ] ?? array(), $currency );
+			$variant = $this->build_variation_variant( $variation, $this->item( $variation ), $options[ (int) $variation_id ] ?? array(), $currency );
+
+			// The returned amount is the authority, should it differ from the cached price list.
+			if ( $this->in_price_range( $variant['price']['amount'] ) ) {
+				$variants[] = $variant;
+			}
 		}

 		return $variants;
diff --git a/plugins/woocommerce/src/Internal/Ucp/UcpDiscovery.php b/plugins/woocommerce/src/Internal/Ucp/UcpDiscovery.php
index fed7844505d..f3712d6da42 100644
--- a/plugins/woocommerce/src/Internal/Ucp/UcpDiscovery.php
+++ b/plugins/woocommerce/src/Internal/Ucp/UcpDiscovery.php
@@ -375,8 +375,8 @@ final class UcpDiscovery implements RegisterHooksInterface {
 	public function get_profile(): array {
 		return array(
 			'ucp'   => array(
-				'version'      => Utils::VERSION,
-				'services'     => array(
+				'version'          => Utils::VERSION,
+				'services'         => array(
 					'dev.ucp.shopping' => array(
 						array(
 							'version'   => Utils::VERSION,
@@ -387,12 +387,14 @@ final class UcpDiscovery implements RegisterHooksInterface {
 						),
 					),
 				),
-				'capabilities' => array_map(
+				'capabilities'     => array_map(
 					static function ( array $declaration ): array {
 						return array( $declaration );
 					},
 					Utils::capability_declarations()
 				),
+				// UCP requires the registry even when empty. Encodes as `{}`, since the store offers no payment handlers yet.
+				'payment_handlers' => new \stdClass(),
 			),
 			'links' => array(
 				array(
diff --git a/plugins/woocommerce/src/StoreApi/Routes/V1/Ucp/AbstractCatalogRoute.php b/plugins/woocommerce/src/StoreApi/Routes/V1/Ucp/AbstractCatalogRoute.php
index f670322fd93..db4e53be768 100644
--- a/plugins/woocommerce/src/StoreApi/Routes/V1/Ucp/AbstractCatalogRoute.php
+++ b/plugins/woocommerce/src/StoreApi/Routes/V1/Ucp/AbstractCatalogRoute.php
@@ -91,6 +91,73 @@ abstract class AbstractCatalogRoute extends AbstractRoute {
 		);
 	}

+	/**
+	 * Validate `filters.price`, refusing values that would silently degrade to something meaningless.
+	 *
+	 * @param array $filters Request filters.
+	 * @return \WP_REST_Response|null Error response, or null when the input is acceptable.
+	 */
+	protected function validate_price_filter( array $filters ) {
+		if ( isset( $filters['price'] ) && ! is_array( $filters['price'] ) ) {
+			return $this->ucp_error( 'VALIDATION_ERROR', __( 'filters.price must be an object.', 'woocommerce' ), 'recoverable', 400 );
+		}
+
+		$bounds = array();
+
+		foreach ( array( 'min', 'max' ) as $bound ) {
+			if ( ! isset( $filters['price'][ $bound ] ) ) {
+				continue;
+			}
+
+			$value = $filters['price'][ $bound ];
+
+			// A fractional or out-of-range bound would be changed by the integer cast below.
+			if ( ! is_numeric( $value ) || (float) $value < 0 || (float) $value >= PHP_INT_MAX || floor( (float) $value ) !== (float) $value ) {
+				return $this->ucp_error(
+					'VALIDATION_ERROR',
+					sprintf(
+						/* translators: %s: price filter bound name, `min` or `max`. */
+						__( 'filters.price.%s must be a non-negative integer amount in minor units.', 'woocommerce' ),
+						$bound
+					),
+					'recoverable',
+					400
+				);
+			}
+
+			$bounds[ $bound ] = (int) $value;
+		}
+
+		if ( isset( $bounds['min'], $bounds['max'] ) && $bounds['min'] > $bounds['max'] ) {
+			return $this->ucp_error(
+				'VALIDATION_ERROR',
+				__( 'filters.price.min must not exceed filters.price.max.', 'woocommerce' ),
+				'recoverable',
+				400
+			);
+		}
+
+		return null;
+	}
+
+	/**
+	 * Read the validated `filters.price` bounds, in minor units.
+	 *
+	 * @param array $filters Request filters.
+	 * @return array Optional `min` and `max` keys.
+	 */
+	protected function price_bounds( array $filters ): array {
+		$bounds = array();
+
+		foreach ( array( 'min', 'max' ) as $bound ) {
+			if ( is_array( $filters['price'] ?? null ) && isset( $filters['price'][ $bound ] ) ) {
+				$bounds[ $bound ] = (int) $filters['price'][ $bound ];
+			}
+		}
+
+		return $bounds;
+	}
+
 	/**
 	 * Get the product mapper for the response being built.
 	 *
diff --git a/plugins/woocommerce/src/StoreApi/Routes/V1/Ucp/CatalogLookup.php b/plugins/woocommerce/src/StoreApi/Routes/V1/Ucp/CatalogLookup.php
index f06cbf58cde..53feec74ec0 100644
--- a/plugins/woocommerce/src/StoreApi/Routes/V1/Ucp/CatalogLookup.php
+++ b/plugins/woocommerce/src/StoreApi/Routes/V1/Ucp/CatalogLookup.php
@@ -65,11 +65,15 @@ class CatalogLookup extends AbstractCatalogRoute {
 		return array_merge(
 			parent::get_request_args(),
 			array(
-				'ids' => array(
+				'ids'     => array(
 					'description' => __( 'Product or variant identifiers to look up.', 'woocommerce' ),
 					'type'        => 'array',
 					'items'       => array( 'type' => array( 'string', 'integer' ) ),
 				),
+				'filters' => array(
+					'description' => __( 'Filter criteria to narrow the returned products and variants.', 'woocommerce' ),
+					'type'        => 'object',
+				),
 			)
 		);
 	}
@@ -109,6 +113,12 @@ class CatalogLookup extends AbstractCatalogRoute {
 			);
 		}

+		$filters = (array) ( Utils::json_param( $request, 'filters' ) ?? array() );
+		$invalid = $this->validate_price_filter( $filters );
+		if ( null !== $invalid ) {
+			return $invalid;
+		}
+
 		$messages = array();

 		$currency_warning = $this->currency_warning( $this->get_context( $request ), $this->store_currency() );
@@ -156,11 +166,16 @@ class CatalogLookup extends AbstractCatalogRoute {

 		// One response spans several mapping calls here, so the per-response state
 		// is started explicitly rather than by the mapper.
-		$this->mapper()->begin_response();
+		$this->mapper()->begin_response( $this->price_bounds( $filters ) );

 		$products = array();
 		foreach ( $groups as $group ) {
-			$products[] = $this->mapper()->map_lookup_product( $group['product'], $group['inputs'] );
+			$product = $this->mapper()->map_lookup_product( $group['product'], $group['inputs'] );
+
+			// UCP: a product whose variants all fall outside the filters is excluded.
+			if ( ! empty( $product['variants'] ) ) {
+				$products[] = $product;
+			}
 		}

 		$messages = array_merge(
diff --git a/plugins/woocommerce/src/StoreApi/Routes/V1/Ucp/CatalogProduct.php b/plugins/woocommerce/src/StoreApi/Routes/V1/Ucp/CatalogProduct.php
index 5045627159a..b010f3538e5 100644
--- a/plugins/woocommerce/src/StoreApi/Routes/V1/Ucp/CatalogProduct.php
+++ b/plugins/woocommerce/src/StoreApi/Routes/V1/Ucp/CatalogProduct.php
@@ -70,6 +70,10 @@ class CatalogProduct extends AbstractCatalogRoute {
 					'description' => __( 'Option selections used to narrow the returned variants.', 'woocommerce' ),
 					'type'        => 'array',
 				),
+				'filters'  => array(
+					'description' => __( 'Filter criteria to narrow the returned variants.', 'woocommerce' ),
+					'type'        => 'object',
+				),
 			)
 		);
 	}
@@ -107,6 +111,12 @@ class CatalogProduct extends AbstractCatalogRoute {
 			);
 		}

+		$filters = (array) ( Utils::json_param( $request, 'filters' ) ?? array() );
+		$invalid = $this->validate_price_filter( $filters );
+		if ( null !== $invalid ) {
+			return $invalid;
+		}
+
 		$resolved = $this->resolve_product( $id );

 		if ( null === $resolved ) {
@@ -130,9 +140,29 @@ class CatalogProduct extends AbstractCatalogRoute {
 			);
 		}

-		$this->mapper()->begin_response();
+		$this->mapper()->begin_response( $this->price_bounds( $filters ) );
 		$product = $this->mapper()->map_detail_product( $resolved['product'], $this->normalize_selected( $selected ), (int) $resolved['variation_id'] );

+		// `variants` cannot be empty, so a product the filters leave nothing of is an error.
+		if ( empty( $product['variants'] ) ) {
+			return new \WP_REST_Response(
+				array(
+					'ucp'      => $this->ucp_metadata( 'error' ),
+					'messages' => array(
+						array(
+							'type'         => 'error',
+							'code'         => 'not_found',
+							'content'      => __( 'No variant of this product matches the filters.', 'woocommerce' ),
+							'severity'     => 'recoverable',
+							'path'         => '$.filters',
+							'content_type' => 'plain',
+						),
+					),
+				),
+				200
+			);
+		}
+
 		$response = array(
 			'ucp'     => $this->ucp_metadata( 'success' ),
 			'product' => $product,
diff --git a/plugins/woocommerce/src/StoreApi/Routes/V1/Ucp/CatalogSearch.php b/plugins/woocommerce/src/StoreApi/Routes/V1/Ucp/CatalogSearch.php
index c747164550c..5b42a185d60 100644
--- a/plugins/woocommerce/src/StoreApi/Routes/V1/Ucp/CatalogSearch.php
+++ b/plugins/woocommerce/src/StoreApi/Routes/V1/Ucp/CatalogSearch.php
@@ -197,45 +197,7 @@ class CatalogSearch extends AbstractCatalogRoute {
 			);
 		}

-		if ( ! $has_price ) {
-			return null;
-		}
-
-		$bounds = array();
-
-		foreach ( array( 'min', 'max' ) as $bound ) {
-			if ( ! isset( $filters['price'][ $bound ] ) ) {
-				continue;
-			}
-
-			$value = $filters['price'][ $bound ];
-
-			if ( ! is_numeric( $value ) || (float) $value < 0 ) {
-				return $this->ucp_error(
-					'VALIDATION_ERROR',
-					sprintf(
-						/* translators: %s: price filter bound name, `min` or `max`. */
-						__( 'filters.price.%s must be a non-negative amount in minor units.', 'woocommerce' ),
-						$bound
-					),
-					'recoverable',
-					400
-				);
-			}
-
-			$bounds[ $bound ] = (int) $value;
-		}
-
-		if ( isset( $bounds['min'], $bounds['max'] ) && $bounds['min'] > $bounds['max'] ) {
-			return $this->ucp_error(
-				'VALIDATION_ERROR',
-				__( 'filters.price.min must not exceed filters.price.max.', 'woocommerce' ),
-				'recoverable',
-				400
-			);
-		}
-
-		return null;
+		return $this->validate_price_filter( $filters );
 	}

 	/**
diff --git a/plugins/woocommerce/src/StoreApi/Schemas/V1/Ucp/UcpProductSchema.php b/plugins/woocommerce/src/StoreApi/Schemas/V1/Ucp/UcpProductSchema.php
index 0c02e8088b2..c5a27694312 100644
--- a/plugins/woocommerce/src/StoreApi/Schemas/V1/Ucp/UcpProductSchema.php
+++ b/plugins/woocommerce/src/StoreApi/Schemas/V1/Ucp/UcpProductSchema.php
@@ -37,4 +37,19 @@ class UcpProductSchema extends ProductSchema {
 	protected function prepare_html_response( $response ) {
 		return $response;
 	}
+
+	/**
+	 * Skip term lookups for variations: catalog terms belong to the parent product.
+	 *
+	 * @param \WC_Product $product Product object.
+	 * @param string      $taxonomy Taxonomy name.
+	 * @return array Array of terms (id, name, slug).
+	 */
+	protected function get_term_list( \WC_Product $product, $taxonomy = '' ) {
+		if ( $product instanceof \WC_Product_Variation ) {
+			return array();
+		}
+
+		return parent::get_term_list( $product, $taxonomy );
+	}
 }
diff --git a/plugins/woocommerce/src/StoreApi/Utilities/Ucp/IdempotencyClaim.php b/plugins/woocommerce/src/StoreApi/Utilities/Ucp/IdempotencyClaim.php
index fe1830686f9..14f1bae673b 100644
--- a/plugins/woocommerce/src/StoreApi/Utilities/Ucp/IdempotencyClaim.php
+++ b/plugins/woocommerce/src/StoreApi/Utilities/Ucp/IdempotencyClaim.php
@@ -217,7 +217,7 @@ final class IdempotencyClaim {
 	 */
 	private static function replay( array $existing ): \WP_REST_Response {
 		$response = new \WP_REST_Response(
-			json_decode( (string) $existing['response_body'], true ),
+			self::restore_json_value( json_decode( (string) $existing['response_body'] ) ),
 			isset( $existing['response_status'] ) ? (int) $existing['response_status'] : 200
 		);

@@ -226,6 +226,29 @@ final class IdempotencyClaim {
 		return $response;
 	}

+	/**
+	 * Turn decoded JSON objects back into arrays, except those that would then encode as a JSON list.
+	 *
+	 * An associative decode turns `{}` into `[]`, so an empty registry such as `payment_handlers`
+	 * would replay as a list. Such objects stay `stdClass`, and every other one becomes an array.
+	 *
+	 * @param mixed $value Value from `json_decode()` without associative mode.
+	 * @return mixed
+	 */
+	private static function restore_json_value( $value ) {
+		if ( is_array( $value ) ) {
+			return array_map( array( self::class, 'restore_json_value' ), $value );
+		}
+
+		if ( ! $value instanceof \stdClass ) {
+			return $value;
+		}
+
+		$properties = array_map( array( self::class, 'restore_json_value' ), get_object_vars( $value ) );
+
+		return wp_is_numeric_array( $properties ) ? (object) $properties : $properties;
+	}
+
 	/**
 	 * Refuse a key another request is still working on.
 	 *
diff --git a/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/UcpCatalog.php b/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/UcpCatalog.php
index 716fc9893b3..54bf3860769 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/UcpCatalog.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/UcpCatalog.php
@@ -316,6 +316,65 @@ class UcpCatalog extends ControllerTestCase {
 		$this->assertSame( 'VALIDATION_ERROR', $data['messages'][0]['code'] );
 	}

+	/**
+	 * Price filters every catalog route refuses.
+	 *
+	 * @return array
+	 */
+	public function provider_malformed_price_filters(): array {
+		return array(
+			'not an object'             => array( '1000' ),
+			'fractional bound'          => array( array( 'min' => 1000.9 ) ),
+			'beyond the integer range'  => array( array( 'min' => '1e400' ) ),
+			'reversed after truncation' => array(
+				array(
+					'min' => 1000.9,
+					'max' => 1000.1,
+				),
+			),
+		);
+	}
+
+	/**
+	 * A malformed `filters.price` is refused rather than ignored or truncated.
+	 *
+	 * @dataProvider provider_malformed_price_filters
+	 *
+	 * @param mixed $price The `filters.price` value.
+	 */
+	public function test_malformed_price_filter_returns_ucp_validation_error( $price ): void {
+		$id      = (string) self::$product_ids[0];
+		$filters = array( 'filters' => array( 'price' => $price ) );
+
+		foreach ( array(
+			'/catalog/product' => array( 'id' => $id ),
+			'/catalog/lookup'  => array( 'ids' => array( $id ) ),
+			'/catalog/search'  => array( 'query' => 'product' ),
+		) as $route => $body ) {
+			$response = $this->post( $route, $filters + $body );
+
+			$this->assertSame( 400, $response->get_status(), $route );
+			$this->assertSame( 'VALIDATION_ERROR', $response->get_data()['messages'][0]['code'], $route );
+		}
+	}
+
+	/**
+	 * Zero and integer-valued bounds are accepted.
+	 */
+	public function test_integral_price_bounds_are_accepted(): void {
+		$body = array(
+			'ids'     => array( (string) self::$product_ids[0] ),
+			'filters' => array(
+				'price' => array(
+					'min' => 0,
+					'max' => '1500.0',
+				),
+			),
+		);
+
+		$this->assertSame( 200, $this->post( '/catalog/lookup', $body )->get_status() );
+	}
+
 	/**
 	 * A missing `ids` list is a UCP validation error, not a WordPress one.
 	 */
@@ -397,6 +456,84 @@ class UcpCatalog extends ControllerTestCase {
 		$this->assertSame( 'unrecoverable', $data['messages'][0]['severity'] );
 	}

+	/**
+	 * Price filters for the helper's variations, priced 10, 15, 16, 17, 18 and 19.
+	 *
+	 * @return array
+	 */
+	public function provider_variant_price_filters(): array {
+		return array(
+			'max is inclusive'                 => array( array( 'max' => 1500 ), array( 1000, 1500 ) ),
+			'min skips the default first pick' => array(
+				array(
+					'min' => 1600,
+					'max' => 1700,
+				),
+				array( 1600, 1700 ),
+			),
+			'nothing in range'                 => array( array( 'max' => 999 ), array() ),
+		);
+	}
+
+	/**
+	 * @testdox Lookup and product detail should return only the variants inside the price filter.
+	 *
+	 * @dataProvider provider_variant_price_filters
+	 *
+	 * @param array $price Price filter bounds in minor units.
+	 * @param array $expected Variant amounts expected back, or none when the product is excluded.
+	 */
+	public function test_lookup_and_detail_apply_the_price_filter( array $price, array $expected ): void {
+		$id   = (string) \WC_Helper_Product::create_variation_product()->get_id();
+		$body = array( 'filters' => array( 'price' => $price ) );
+
+		$detail = $this->post( '/catalog/product', $body + array( 'id' => $id ) )->get_data();
+		$lookup = $this->post( '/catalog/lookup', $body + array( 'ids' => array( $id ) ) )->get_data();
+
+		if ( empty( $expected ) ) {
+			$this->assertSame( 'error', $detail['ucp']['status'] );
+			$this->assertSame( array(), $lookup['products'] );
+			return;
+		}
+
+		$amounts = static function ( array $product ): array {
+			return array_map(
+				static function ( array $variant ): int {
+					return $variant['price']['amount'];
+				},
+				$product['variants']
+			);
+		};
+
+		$this->assertSame( $expected, $amounts( $detail['product'] ) );
+		$this->assertSame( $expected, $amounts( $lookup['products'][0] ) );
+		$this->assertSame( $detail['product']['variants'][0]['options'], $detail['product']['selected'] );
+	}
+
+	/**
+	 * @testdox A selection matching only variants outside the price filter should be relaxed until one inside it matches.
+	 */
+	public function test_product_detail_relaxes_a_selection_the_price_filter_excludes(): void {
+		$id   = (string) \WC_Helper_Product::create_variation_product()->get_id();
+		$data = $this->post(
+			'/catalog/product',
+			array(
+				'id'       => $id,
+				'selected' => array(
+					array(
+						'name'  => 'size',
+						'label' => 'small',
+					),
+				),
+				'filters'  => array( 'price' => array( 'min' => 1500 ) ),
+			)
+		)->get_data();
+
+		$this->assertSame( 'success', $data['ucp']['status'] );
+		$this->assertSame( array(), $data['product']['selected'] );
+		$this->assertSame( 1500, $data['product']['variants'][0]['price']['amount'] );
+	}
+
 	/**
 	 * A variant id puts that variation first, takes its options as the selection,
 	 * and overrides a conflicting request selection.
diff --git a/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/UcpCheckout.php b/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/UcpCheckout.php
index ab48c68e54f..54e9d68904d 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/UcpCheckout.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/UcpCheckout.php
@@ -109,7 +109,7 @@ class UcpCheckout extends ControllerTestCase {
 	 * @param string $method HTTP method.
 	 * @param string $path Route path under /wc/ucp/v1.
 	 * @param array  $body Request body.
-	 * @param array  $headers Extra request headers.
+	 * @param array  $headers Extra request headers; an `Idempotency-Key` replaces the fresh one.
 	 * @return \WP_REST_Response
 	 */
 	private function request( string $method, string $path, array $body = array(), array $headers = array() ) {
@@ -117,7 +117,9 @@ class UcpCheckout extends ControllerTestCase {
 		$request->set_headers( $headers );
 		$request->set_header( 'content-type', 'application/json' );
 		// A write needs a key of its own; the key itself is the UcpIdempotency suite's concern.
-		$request->set_header( 'Idempotency-Key', wp_generate_uuid4() );
+		if ( null === $request->get_header( 'Idempotency-Key' ) ) {
+			$request->set_header( 'Idempotency-Key', wp_generate_uuid4() );
+		}
 		$request->set_body( wp_json_encode( $body ) );

 		return rest_get_server()->dispatch( $request );
@@ -234,6 +236,22 @@ class UcpCheckout extends ControllerTestCase {
 		$this->assertSame( 400, $missing->get_status(), 'line_items is required without a cart_id.' );
 	}

+	/**
+	 * @testdox A replayed create answers the same body, with payment_handlers still an empty object.
+	 */
+	public function test_replay_keeps_the_empty_payment_handlers_object(): void {
+		$key   = wp_generate_uuid4();
+		$body  = array( 'line_items' => array( $this->line_item( 0, 1 ) ) );
+		$first = $this->request( 'POST', '/checkout-sessions', $body, array( 'Idempotency-Key' => $key ) );
+		$this->assertSame( 201, $first->get_status() );
+		$this->simulate_new_request();
+		$replay = $this->request( 'POST', '/checkout-sessions', $body, array( 'Idempotency-Key' => $key ) );
+
+		$this->assertSame( 'true', $replay->get_headers()['Idempotency-Replayed'] ?? '' );
+		$this->assertInstanceOf( \stdClass::class, $replay->get_data()['ucp']['payment_handlers'] );
+		$this->assertSame( wp_json_encode( $first->get_data() ), wp_json_encode( $replay->get_data() ) );
+	}
+
 	/**
 	 * Version cases for the `UCP-Agent` header.
 	 *
diff --git a/plugins/woocommerce/tests/php/src/Internal/ProductFeed/Mapping/UcpProductMapperTest.php b/plugins/woocommerce/tests/php/src/Internal/ProductFeed/Mapping/UcpProductMapperTest.php
index 6306d2e30d5..6d396a9a946 100644
--- a/plugins/woocommerce/tests/php/src/Internal/ProductFeed/Mapping/UcpProductMapperTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/ProductFeed/Mapping/UcpProductMapperTest.php
@@ -225,6 +225,84 @@ class UcpProductMapperTest extends \WC_Unit_Test_Case {
 		$this->assertCount( 2, $mapped['variants'] );
 	}

+	/**
+	 * @testdox A request with no selection should report the featured variation's options as selected.
+	 */
+	public function test_detail_without_selection_reports_the_featured_variation(): void {
+		$variable = new \WC_Product_Variable();
+		$variable->set_name( 'Default Selection' );
+		$variable->set_status( 'publish' );
+		$variable->set_attributes( array( WC_Helper_Product::create_product_attribute_object( 'size', array( 'small', 'large' ) ) ) );
+		$parent_id = $variable->save();
+
+		$ids = array();
+		foreach ( array( 'small', 'large' ) as $size ) {
+			$variation = new \WC_Product_Variation();
+			$variation->set_parent_id( $parent_id );
+			$variation->set_attributes( array( 'pa_size' => $size ) );
+			$variation->set_regular_price( '10' );
+			$variation->set_status( 'publish' );
+			$ids[ $size ] = $variation->save();
+		}
+
+		\WC_Product_Variable::sync( $parent_id );
+		$mapper = new UcpProductMapper( 'USD' );
+
+		$mapped = $mapper->map_detail_product( wc_get_product( $parent_id ) );
+		$this->assertSame( 'small', $mapped['selected'][0]['label'] );
+		$this->assertSame( (string) $ids['small'], $mapped['variants'][0]['id'] );
+
+		$product = wc_get_product( $parent_id );
+		$product->set_default_attributes( array( 'pa_size' => 'large' ) );
+		$product->save();
+
+		$mapped = $mapper->map_detail_product( wc_get_product( $parent_id ) );
+		$this->assertSame( 'large', $mapped['selected'][0]['label'] );
+		$this->assertSame( (string) $ids['large'], $mapped['variants'][0]['id'] );
+		$this->assertCount( 2, $mapped['variants'] );
+	}
+
+	/**
+	 * @testdox The featured variation should come from the variants left after the returned prices are filtered.
+	 */
+	public function test_detail_features_a_variation_the_returned_prices_keep(): void {
+		$variable = new \WC_Product_Variable();
+		$variable->set_name( 'Featured In Range' );
+		$variable->set_status( 'publish' );
+		$variable->set_attributes( array( WC_Helper_Product::create_product_attribute_object( 'size', array( 'small', 'large' ) ) ) );
+		$parent_id = $variable->save();
+
+		$ids = array();
+		foreach ( array(
+			'small' => '10',
+			'large' => '12',
+		) as $size => $price ) {
+			$variation = new \WC_Product_Variation();
+			$variation->set_parent_id( $parent_id );
+			$variation->set_attributes( array( 'pa_size' => $size ) );
+			$variation->set_regular_price( $price );
+			$variation->set_status( 'publish' );
+			$ids[ $size ] = $variation->save();
+		}
+
+		\WC_Product_Variable::sync( $parent_id );
+
+		// The cached price list keeps small at 10; its returned price is 20.
+		$raise_small = function ( $price, $variation ) use ( $ids ) {
+			return $variation->get_id() === $ids['small'] ? '20' : $price;
+		};
+		add_filter( 'woocommerce_product_variation_get_price', $raise_small, 10, 2 );
+
+		$mapper = new UcpProductMapper( 'USD' );
+		$mapper->begin_response( array( 'max' => 1500 ) );
+		$mapped = $mapper->map_detail_product( wc_get_product( $parent_id ) );
+
+		remove_filter( 'woocommerce_product_variation_get_price', $raise_small, 10 );
+
+		$this->assertSame( array( (string) $ids['large'] ), array_column( $mapped['variants'], 'id' ) );
+		$this->assertSame( 'large', $mapped['selected'][0]['label'] );
+	}
+
 	/**
 	 * The storefront treats an "Any" variation attribute as a wildcard and
 	 * `options` advertises every term for it, so a selection must match it too.
diff --git a/plugins/woocommerce/tests/php/src/Internal/Ucp/UcpDiscoveryTest.php b/plugins/woocommerce/tests/php/src/Internal/Ucp/UcpDiscoveryTest.php
index 0647752e81e..838afc0d012 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Ucp/UcpDiscoveryTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Ucp/UcpDiscoveryTest.php
@@ -65,6 +65,7 @@ class UcpDiscoveryTest extends \WC_Unit_Test_Case {
 			$this->assertSame( array( $declaration ), $profile['ucp']['capabilities'][ $capability ] );
 		}
 		$this->assertSame( home_url( '/.well-known/ucp' ), $profile['links'][0]['href'] );
+		$this->assertSame( '{}', wp_json_encode( $profile['ucp']['payment_handlers'] ) );
 	}

 	/**
@@ -329,7 +330,7 @@ class UcpDiscoveryTest extends \WC_Unit_Test_Case {
 		$output = $this->render( self::RULE, '1' );

 		$this->assertNotNull( $output );
-		$this->assertSame( $this->sut->get_profile(), json_decode( (string) $output, true ) );
+		$this->assertSame( $this->json_profile(), json_decode( (string) $output, true ) );
 	}

 	/**
@@ -338,7 +339,7 @@ class UcpDiscoveryTest extends \WC_Unit_Test_Case {
 	public function test_maybe_render_request_uri_fallback(): void {
 		$output = $this->render( '', '', '/.well-known/ucp/' );

-		$this->assertSame( $this->sut->get_profile(), json_decode( (string) $output, true ) );
+		$this->assertSame( $this->json_profile(), json_decode( (string) $output, true ) );
 	}

 	/**
@@ -368,6 +369,15 @@ class UcpDiscoveryTest extends \WC_Unit_Test_Case {
 		}
 	}

+	/**
+	 * The profile after a JSON round trip, as a client decodes it.
+	 *
+	 * @return array
+	 */
+	private function json_profile(): array {
+		return json_decode( (string) wp_json_encode( $this->sut->get_profile() ), true );
+	}
+
 	/**
 	 * @testdox On WordPress.com the fix names its support where other stores are pointed to their hosting provider.
 	 */