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

[Product Query] Fix filter block data counter #7257

Merged
merged 36 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
16ea028
Product Query: Fix pagination issue
gigitux Sep 12, 2022
f19fd99
Merge branch 'trunk' of https://github.com/woocommerce/woocommerce-bl…
gigitux Sep 14, 2022
816ffe9
Merge branch 'trunk' of https://github.com/woocommerce/woocommerce-bl…
gigitux Sep 15, 2022
6e93dd0
Product Query - Add support for the Filter By Price Block #6790
gigitux Sep 15, 2022
b243528
fix query relation
gigitux Sep 16, 2022
e55a41d
fix on sale query
gigitux Sep 16, 2022
341d47b
Merge branch 'trunk' into add/price_filter_support
gigitux Sep 16, 2022
1fd15a8
Merge branch 'trunk' into add/price_filter_support
gigitux Sep 20, 2022
926f62c
Product Query - Add support for the Filter By Attributes block #6790
gigitux Sep 20, 2022
3176679
Merge branch 'trunk' into add/attribute_filter_support
gigitux Sep 21, 2022
1d56a2e
fix bugged pagination and on-sale filter after refactor
gigitux Sep 21, 2022
c9839f2
Merge branch 'add/price_filter_support' of https://github.com/woocomm…
gigitux Sep 21, 2022
9065ab3
Merge branch 'add/price_filter_support' of https://github.com/woocomm…
gigitux Sep 21, 2022
0be510e
Merge branch 'add/attribute_filter_support' of https://github.com/woo…
gigitux Sep 21, 2022
6f326eb
Merge ranch 'trunk' of https://github.com/woocommerce/woocommerce-blo…
gigitux Sep 22, 2022
5622639
Merge branch 'trunk' of https://github.com/woocommerce/woocommerce-bl…
gigitux Sep 28, 2022
c22d149
Merge branch 'trunk' of https://github.com/woocommerce/woocommerce-bl…
gigitux Sep 28, 2022
80a0dbf
address feedback
gigitux Sep 28, 2022
5be22b9
Product Query - Add support for the Filter By Stock Block #6790
gigitux Sep 29, 2022
2e5f59e
Merge branch 'trunk' into add/stock_filter_support
gigitux Sep 29, 2022
b8bf17e
Fix filter blocks: the data (e.g: max price or stock-status) match th…
gigitux Sep 29, 2022
1bef270
Merge branch 'trunk' into fix/filter_display_data
gigitux Sep 29, 2022
b093589
Merge branch 'trunk' into add/stock_filter_support
gigitux Oct 7, 2022
c7e9773
Merge branch 'trunk' into fix/filter_display_data
gigitux Oct 7, 2022
b1b05f6
Merge branch 'trunk' into fix/filter_display_data
gigitux Oct 10, 2022
9ea5689
Merge branch 'trunk' into add/stock_filter_support
gigitux Oct 10, 2022
f20d7da
Merge branch 'trunk' into fix/filter_display_data
gigitux Oct 11, 2022
e879ae6
Merge branch 'trunk' of https://github.com/woocommerce/woocommerce-bl…
gigitux Oct 26, 2022
027ab12
Merge branch 'add/stock_filter_support' of https://github.com/woocomm…
gigitux Oct 26, 2022
0c45b07
Merge branch 'add/stock_filter_support' of https://github.com/woocomm…
gigitux Oct 27, 2022
c4a46c3
disable phcs rules on top of the file
gigitux Oct 27, 2022
a07778c
Merge branch 'trunk' into fix/filter_display_data
gigitux Oct 27, 2022
e95122d
replace parameter name
gigitux Oct 27, 2022
3c8e6d0
Merge branch 'fix/filter_display_data' of https://github.com/woocomme…
gigitux Oct 27, 2022
987d4a4
fix eslint error
gigitux Oct 27, 2022
a004b75
Merge branch 'trunk' of https://github.com/woocommerce/woocommerce-bl…
gigitux Nov 2, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
*/
import { useState, useEffect, useMemo } from '@wordpress/element';
import { useDebounce } from 'use-debounce';
import { sortBy } from 'lodash';
import { isEmpty, sortBy } from 'lodash';
import { useShallowEqual } from '@woocommerce/base-hooks';
import { getSettingWithCoercion } from '@woocommerce/settings';
import { objectHasProp } from '@woocommerce/types';

/**
Expand Down Expand Up @@ -47,6 +48,7 @@ interface UseCollectionDataProps {
queryStock?: boolean;
queryRating?: boolean;
queryState: Record< string, unknown >;
productIds?: number[];
}

export const useCollectionData = ( {
Expand All @@ -55,6 +57,7 @@ export const useCollectionData = ( {
queryStock,
queryRating,
queryState,
productIds,
}: UseCollectionDataProps ) => {
let context = useQueryStateContext();
context = `${ context }-collection-data`;
Expand Down Expand Up @@ -163,6 +166,7 @@ export const useCollectionData = ( {
per_page: undefined,
orderby: undefined,
order: undefined,
...( ! isEmpty( productIds ) && { include: productIds } ),
...collectionDataQueryVars,
},
shouldSelect: debouncedShouldSelect,
Expand Down
5 changes: 5 additions & 0 deletions assets/js/blocks/attribute-filter/block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ const AttributeFilterBlock = ( {
isString
);

const productIds = isEditor
? []
: getSettingWithCoercion( 'product_ids', [], Array.isArray );

const [ hasSetFilterDefaultsFromUrl, setHasSetFilterDefaultsFromUrl ] =
useState( false );

Expand Down Expand Up @@ -158,6 +162,7 @@ const AttributeFilterBlock = ( {
...queryState,
attributes: filterAvailableTerms ? queryState.attributes : null,
},
productIds,
} );

/**
Expand Down
5 changes: 5 additions & 0 deletions assets/js/blocks/price-filter/block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ const PriceFilterBlock = ( {
isBoolean
);

const productIds = isEditor
? []
: getSettingWithCoercion( 'product_ids', [], Array.isArray );

const [ hasSetFilterDefaultsFromUrl, setHasSetFilterDefaultsFromUrl ] =
useState( false );

Expand All @@ -108,6 +112,7 @@ const PriceFilterBlock = ( {
const { results, isLoading } = useCollectionData( {
queryPrices: true,
queryState,
productIds,
} );

const currency = getCurrencyFromPriceResponse(
Expand Down
5 changes: 5 additions & 0 deletions assets/js/blocks/stock-filter/block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ const StockStatusFilterBlock = ( {
{}
);

const productIds = isEditor
? []
: getSettingWithCoercion( 'product_ids', [], Array.isArray );

const STOCK_STATUS_OPTIONS = useRef(
getSetting( 'hideOutOfStockItems', false )
? otherStockStatusOptions
Expand Down Expand Up @@ -101,6 +105,7 @@ const StockStatusFilterBlock = ( {
useCollectionData( {
queryStock: true,
queryState,
productIds,
} );

/**
Expand Down
4 changes: 3 additions & 1 deletion src/BlockTypes/AttributeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ class AttributeFilter extends AbstractBlock {
*
* @var string
*/
protected $block_name = 'attribute-filter';
protected $block_name = 'attribute-filter';
const FILTER_QUERY_VAR_PREFIX = 'filter_';
const QUERY_TYPE_QUERY_VAR_PREFIX = 'query_type_';

/**
* Extra data passed through from server to client for block.
Expand Down
Loading