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

Commit

Permalink
try: process shared params separately
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhtungdu committed Sep 21, 2023
1 parent dcb70d5 commit 7277515
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/BlockTypes/CollectionFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,27 +218,30 @@ private function get_formatted_products_params( $query ) {
return $params;
}

/**
* The following params can be passed directly to Store API endpoints.
*/
$shared_params = array( 'exclude', 'offset', 'order', 'serach' );

/**
* The following params just need to transform the key, their value can
* be passed as it is to the Store API.
*/
$params_mapping = array(
'exclude' => 'exclude',
'offset' => 'offset',
'order' => 'order',
$params_keys_mapping = array(
'orderBy' => 'orderby',
'pages' => 'page',
'parents' => 'parent',
'perPage' => 'per_page',
'search' => 'search',
'woocommerceStockStatus' => 'stock_status',
'woocommerceOnSale' => 'on_sale',
'woocommerceHandPickedProducts' => 'include',
);

foreach ( $params_mapping as $key => $mapped_key ) {
if ( isset( $query[ $key ] ) ) {
$params[ $mapped_key ] = $query[ $key ];
foreach ( $query as $key => $value ) {
if ( in_array( $key, $shared_params, true ) ) {
$params[ $key ] = $value;
} elseif ( isset( $params_keys_mapping[ $key ] ) ) {
$params[ $params_keys_mapping[ $key ] ] = $value;
}
}

Expand Down

0 comments on commit 7277515

Please sign in to comment.