Automattic\WooCommerce\Blocks\BlockTypes\ProductCollection
Controller::update_rest_query_in_editor
Update the query for the product query block in Editor.
Метод класса: Controller{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$Controller = new Controller(); $Controller->update_rest_query_in_editor( $query, $request ): array;
- $query(массив) (обязательный)
- Query args.
- $request(WP_REST_Request) (обязательный)
- Request.
Код Controller::update_rest_query_in_editor() Controller::update rest query in editor WC 10.5.0
public function update_rest_query_in_editor( $query, $request ): array {
// Only update the query if this is a product collection block.
$is_product_collection_block = $request->get_param( 'isProductCollectionBlock' );
if ( ! $is_product_collection_block ) {
return $query;
}
$product_collection_query_context = $request->get_param( 'productCollectionQueryContext' );
$collection_args = array(
'name' => $product_collection_query_context['collection'] ?? '',
// The editor uses a REST query to grab product post types. This means we don't have a block
// instance to work with and the client needs to provide the location context.
'productCollectionLocation' => $request->get_param( 'productCollectionLocation' ),
);
// Allow collections to modify the collection arguments passed to the query builder.
$handlers = $this->collection_handler_registry->get_collection_handler( $collection_args['name'] );
if ( isset( $handlers['editor_args'] ) ) {
$collection_args = call_user_func( $handlers['editor_args'], $collection_args, $query, $request );
}
$orderby = $request->get_param( 'orderby' );
// When requested, short-circuit the query and return the preview query args.
$preview_state = $request->get_param( 'previewState' );
if ( isset( $preview_state['isPreview'] ) && 'true' === $preview_state['isPreview'] ) {
return $this->query_builder->get_preview_query_args( $collection_args, array_merge( $query, array( 'orderby' => $orderby ) ), $request );
}
$on_sale = $request->get_param( 'woocommerceOnSale' ) === 'true';
$stock_status = $request->get_param( 'woocommerceStockStatus' );
$product_attributes = $request->get_param( 'woocommerceAttributes' );
$handpicked_products = $request->get_param( 'woocommerceHandPickedProducts' );
$featured = $request->get_param( 'featured' );
$time_frame = $request->get_param( 'timeFrame' );
$price_range = $request->get_param( 'priceRange' );
$raw_tax_query_from_rest_params = $query['tax_query'] ?? array();
// This argument is required for the tests to PHP Unit Tests to run correctly.
// Most likely this argument is being accessed in the test environment image.
$query['author'] = '';
// Use QueryBuilder to get the final query args.
return $this->query_builder->get_final_query_args(
$collection_args,
$query,
array(
'orderby' => $orderby,
'on_sale' => $on_sale,
'stock_status' => $stock_status,
'product_attributes' => $product_attributes,
'handpicked_products' => $handpicked_products,
'featured' => $featured,
'timeFrame' => $time_frame,
'priceRange' => $price_range,
'taxonomies_query' => $raw_tax_query_from_rest_params,
)
);
}