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.

Метод класса: CatalogSearch{}

Хуков нет.

Возвращает

array.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->store_api_params( $query, $filters, ?array $category_slugs, $limit, $offset ): array;
$query(строка) (обязательный)
Free-text search term.
$filters(массив) (обязательный)
Request filters.
?array $category_slugs(обязательный)
.
$limit(int) (обязательный)
Page size.
$offset(int) (обязательный)
Offset of the first result.

Код CatalogSearch::store_api_params() 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;
}