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

Commit

Permalink
Ensure Filter Products by Attribute block reloads the page when inter…
Browse files Browse the repository at this point in the history
…acting with PHP templates (#6332)
  • Loading branch information
Aljullu authored Apr 28, 2022
1 parent 20c48c1 commit 64dc70e
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions assets/js/blocks/attribute-filter/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -588,7 +595,7 @@ const AttributeFilterBlock = ( {
<FilterSubmitButton
className="wc-block-attribute-filter__button"
disabled={ isLoading || isDisabled }
onClick={ () => onSubmit( checked ) }
onClick={ () => onClickSubmit( checked ) }
/>
) }
</div>
Expand Down

0 comments on commit 64dc70e

Please sign in to comment.