Ensure Filter Products by Attribute block reloads the page when interacting with PHP templates (https://github.com/woocommerce/woocommerce-blocks/pull/6332)

This commit is contained in:
Albert Juhé Lluveras 2022-04-28 09:51:24 +02:00 committed by GitHub
parent 1d0acebfa9
commit 81f348b466
1 changed files with 17 additions and 10 deletions

View File

@ -274,29 +274,36 @@ const AttributeFilterBlock = ( {
[ pageUrl, attributeObject?.taxonomy ]
);
const onClickSubmit = ( isChecked ) => {
const query = updateAttributeFilter(
productAttributesQuery,
setProductAttributesQuery,
attributeObject,
getSelectedTerms( isChecked ),
blockAttributes.queryType === 'or' ? 'in' : 'and'
);
// This is for PHP rendered template filtering only.
if ( filteringForPhpTemplate ) {
redirectPageForPhpTemplate( query, isChecked.length === 0 );
}
};
const onSubmit = useCallback(
( isChecked ) => {
if ( isEditor ) {
return;
}
const query = updateAttributeFilter(
updateAttributeFilter(
productAttributesQuery,
setProductAttributesQuery,
attributeObject,
getSelectedTerms( isChecked ),
blockAttributes.queryType === 'or' ? 'in' : 'and'
);
// This is for PHP rendered template filtering only.
if ( filteringForPhpTemplate && hasSetPhpFilterDefaults ) {
redirectPageForPhpTemplate( query, isChecked.length === 0 );
}
},
[
hasSetPhpFilterDefaults,
filteringForPhpTemplate,
redirectPageForPhpTemplate,
isEditor,
productAttributesQuery,
setProductAttributesQuery,
@ -588,7 +595,7 @@ const AttributeFilterBlock = ( {
<FilterSubmitButton
className="wc-block-attribute-filter__button"
disabled={ isLoading || isDisabled }
onClick={ () => onSubmit( checked ) }
onClick={ () => onClickSubmit( checked ) }
/>
) }
</div>