Product Query: make sure request params are set when enhancing REST query (https://github.com/woocommerce/woocommerce-blocks/pull/7796)
This fixes a bug in which in certain cases Products wouldn't load in the editor because the Product Query block was doing some REST API request with some invalid parameters.
This commit is contained in:
parent
936979dc33
commit
4e340ee3ed
|
@ -120,11 +120,13 @@ class ProductQuery extends AbstractBlock {
|
||||||
* @param WP_REST_Request $request Request.
|
* @param WP_REST_Request $request Request.
|
||||||
*/
|
*/
|
||||||
public function update_rest_query( $args, $request ) {
|
public function update_rest_query( $args, $request ) {
|
||||||
$on_sale_query = $request->get_param( '__woocommerceOnSale' ) !== 'true' ? array() : $this->get_on_sale_products_query();
|
$orderby = $request->get_param( 'orderby' );
|
||||||
$orderby_query = $this->get_custom_orderby_query( $request->get_param( 'orderby' ) );
|
$woo_attributes = $request->get_param( '__woocommerceAttributes' );
|
||||||
$tax_query = $this->get_product_attributes_query( $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 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -287,7 +289,7 @@ class ProductQuery extends AbstractBlock {
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function get_product_attributes_query( $attributes ) {
|
private function get_product_attributes_query( $attributes = array() ) {
|
||||||
$grouped_attributes = array_reduce(
|
$grouped_attributes = array_reduce(
|
||||||
$attributes,
|
$attributes,
|
||||||
function ( $carry, $item ) {
|
function ( $carry, $item ) {
|
||||||
|
|
Loading…
Reference in New Issue