Automattic\WooCommerce\Blocks\BlockTypes

ProductCollection::get_final_frontend_query()privateWC 1.0

Get the final query arguments for the frontend.

Method of the class: ProductCollection{}

No Hooks.

Return

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->get_final_frontend_query( $query, $page, $is_exclude_applied_filters );
$query(array) (required)
The query arguments.
$page(int)
The page number.
Default: 1
$is_exclude_applied_filters(true|false)
Whether to exclude the applied filters or not.
Default: false

ProductCollection::get_final_frontend_query() code WC 9.4.2

private function get_final_frontend_query( $query, $page = 1, $is_exclude_applied_filters = false ) {
	$offset   = $query['offset'] ?? 0;
	$per_page = $query['perPage'] ?? 9;

	$common_query_values = array(
		// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
		'meta_query'     => array(),
		'posts_per_page' => $query['perPage'],
		'order'          => $query['order'],
		'offset'         => ( $per_page * ( $page - 1 ) ) + $offset,
		'post__in'       => array(),
		'post_status'    => 'publish',
		'post_type'      => 'product',
		// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query
		'tax_query'      => array(),
		'paged'          => $page,
		's'              => $query['search'],
	);

	$is_on_sale          = $query['woocommerceOnSale'] ?? false;
	$product_attributes  = $query['woocommerceAttributes'] ?? array();
	$taxonomies_query    = $this->get_filter_by_taxonomies_query( $query['tax_query'] ?? array() );
	$handpicked_products = $query['woocommerceHandPickedProducts'] ?? array();
	$time_frame          = $query['timeFrame'] ?? null;
	$price_range         = $query['priceRange'] ?? null;

	$final_query = $this->get_final_query_args(
		$common_query_values,
		array(
			'on_sale'             => $is_on_sale,
			'stock_status'        => $query['woocommerceStockStatus'],
			'orderby'             => $query['orderBy'],
			'product_attributes'  => $product_attributes,
			'taxonomies_query'    => $taxonomies_query,
			'handpicked_products' => $handpicked_products,
			'featured'            => $query['featured'] ?? false,
			'timeFrame'           => $time_frame,
			'priceRange'          => $price_range,
		),
		$is_exclude_applied_filters
	);

	return $final_query;
}