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

Ensure Filter Products by Attribute block reloads the page when interacting with PHP templates #6332

Merged
merged 1 commit into from
Apr 28, 2022
Merged
Changes from all commits
Commits
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
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 @@ -268,29 +268,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 );
}
};
dinhtungdu marked this conversation as resolved.
Show resolved Hide resolved

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 @@ -578,7 +585,7 @@ const AttributeFilterBlock = ( {
<FilterSubmitButton
className="wc-block-attribute-filter__button"
disabled={ isLoading || isDisabled }
onClick={ () => onSubmit( checked ) }
onClick={ () => onClickSubmit( checked ) }
/>
) }
</div>
Expand Down