Automattic\WooCommerce\StoreApi\Routes\V1\Ucp

CatalogSearch::store_api_params │ private │ WC 1.0

Translate the UCP search body into Store API product collection parameters.

Price bounds pass through in minor units for ProductQuery to convert and tax-adjust. Like core's other price filters it matches on range overlap: a variable product qualifies when its min–max span intersects the bounds, even with no variation inside them.

Method of the class: CatalogSearch{}

No Hooks.

Returns

array.

Usage

// private - for code of main (parent) class only
$result = $this->store_api_params( $query, $filters, ?array $category_slugs, $limit, $offset ): array;
$query(string) (required)
Free-text search term.
$filters(array) (required)
Request filters.
?array $category_slugs(required)
.
$limit(int) (required)
Page size.
$offset(int) (required)
Offset of the first result.

CatalogSearch::store_api_params() code WC 11.3.0

private function store_api_params( string $query, array $filters, ?array $category_slugs, int $limit, int $offset ): array {
	$params = array(
		'orderby'            => 'date',
		'order'              => 'desc',
		'per_page'           => $limit,
		'offset'             => $offset,
		'catalog_visibility' => $query ? CatalogVisibility::SEARCH : CatalogVisibility::CATALOG,
	);

	if ( '' !== $query ) {
		$params['search'] = $query;
	}

	if ( ! empty( $category_slugs ) ) {
		$params['category'] = $category_slugs;
	}

	if ( isset( $filters['price'] ) && is_array( $filters['price'] ) ) {
		foreach ( array( 'min', 'max' ) as $bound ) {
			if ( isset( $filters['price'][ $bound ] ) ) {
				$params[ $bound . '_price' ] = (int) $filters['price'][ $bound ];
			}
		}
	}

	return $params;
}