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

Commit

Permalink
Fix: Product Query editor preview with Stock Status setting (#7682)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
dinhtungdu and github-actions[bot] authored Dec 5, 2022
1 parent a23cd9c commit b20ec06
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/BlockTypes/ProductQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,13 @@ public function update_query( $pre_render, $parsed_block ) {
public function update_rest_query( $args, $request ) {
$orderby = $request->get_param( 'orderby' );
$woo_attributes = $request->get_param( '__woocommerceAttributes' );
$woo_stock_status = $request->get_param( '__woocommerceStockStatus' );
$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();
$stock_query = is_array( $woo_stock_status ) ? $this->get_stock_status_query( $woo_stock_status ) : array();

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

/**
Expand Down Expand Up @@ -434,11 +436,12 @@ private function get_queries_by_attributes( $parsed_block ) {
$query = $parsed_block['attrs']['query'];
$on_sale_enabled = isset( $query['__woocommerceOnSale'] ) && true === $query['__woocommerceOnSale'];
$attributes_query = isset( $query['__woocommerceAttributes'] ) ? $this->get_product_attributes_query( $query['__woocommerceAttributes'] ) : array();
$stock_query = isset( $query['__woocommerceStockStatus'] ) ? $this->get_stock_status_query( $query['__woocommerceStockStatus'] ) : array();

return array(
'attributes' => $attributes_query,
'on_sale' => ( $on_sale_enabled ? $this->get_on_sale_products_query() : array() ),
'stock_status' => isset( $query['__woocommerceStockStatus'] ) ? $this->get_stock_status_query( $query['__woocommerceStockStatus'] ) : array(),
'attributes' => $attributes_query,
'stock_status' => $stock_query,
);
}

Expand Down

0 comments on commit b20ec06

Please sign in to comment.