Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Product Query: make sure request params are set when enhancing REST query #7796

Merged
merged 4 commits into from
Dec 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/BlockTypes/ProductQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,13 @@ public function update_query( $pre_render, $parsed_block ) {
* @param WP_REST_Request $request Request.
*/
public function update_rest_query( $args, $request ) {
$on_sale_query = $request->get_param( '__woocommerceOnSale' ) !== 'true' ? array() : $this->get_on_sale_products_query();
$orderby_query = $this->get_custom_orderby_query( $request->get_param( 'orderby' ) );
$tax_query = $this->get_product_attributes_query( $request->get_param( '__woocommerceAttributes' ) );
$orderby = $request->get_param( 'orderby' );
$woo_attributes = $request->get_param( '__woocommerceAttributes' );
$on_sale_query = $request->get_param( '__woocommerceOnSale' ) === 'true' ? $this->get_on_sale_products_query() : array();
$orderby_query = isset( $orderby ) ? $this->get_custom_orderby_query( $orderby ) : array();
$attributes_query = is_array( $woo_attributes ) ? $this->get_product_attributes_query( $woo_attributes ) : array();

return array_merge( $args, $on_sale_query, $orderby_query, $tax_query );
return array_merge( $args, $on_sale_query, $orderby_query, $attributes_query );
}

/**
Expand Down Expand Up @@ -287,7 +289,7 @@ private function get_custom_orderby_query( $orderby ) {
*
* @return array
*/
private function get_product_attributes_query( $attributes ) {
private function get_product_attributes_query( $attributes = array() ) {
$grouped_attributes = array_reduce(
$attributes,
function ( $carry, $item ) {
Expand Down