From f55e25b009e42f668d5c5016ae97be673990c8ac Mon Sep 17 00:00:00 2001 From: Karol Manijak <20098064+kmanijak@users.noreply.github.com> Date: Wed, 22 May 2024 11:57:53 +0200 Subject: [PATCH] Filter by Attribute: fix potential reading property of undefined error (#47699) * Fix reading from undefined error in attribute-filter * Add changelog --- .../assets/js/blocks/attribute-filter/block.tsx | 2 +- .../assets/js/types/type-defs/attributes.ts | 2 +- .../fix-attribute-filter-reading-property-of-undefined | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 plugins/woocommerce/changelog/fix-attribute-filter-reading-property-of-undefined diff --git a/plugins/woocommerce-blocks/assets/js/blocks/attribute-filter/block.tsx b/plugins/woocommerce-blocks/assets/js/blocks/attribute-filter/block.tsx index 4f9f54c88a3..62b7e7930ac 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/attribute-filter/block.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/attribute-filter/block.tsx @@ -130,7 +130,7 @@ const AttributeFilterBlock = ( { resourceName: 'products/attributes/terms', resourceValues: [ attributeObject?.id || 0 ], shouldSelect: blockAttributes.attributeId > 0, - query: { orderby: attributeObject.orderby }, + query: { orderby: attributeObject?.orderby || 'menu_order' }, } ); const { results: filteredCounts, isLoading: filteredCountsLoading } = diff --git a/plugins/woocommerce-blocks/assets/js/types/type-defs/attributes.ts b/plugins/woocommerce-blocks/assets/js/types/type-defs/attributes.ts index 3843082953f..baa44ba596e 100644 --- a/plugins/woocommerce-blocks/assets/js/types/type-defs/attributes.ts +++ b/plugins/woocommerce-blocks/assets/js/types/type-defs/attributes.ts @@ -13,7 +13,7 @@ export interface AttributeObject { id: number; label: string; name: string; - order: 'menu_order' | 'name' | 'name_num' | 'id'; + orderby: 'menu_order' | 'name' | 'name_num' | 'id'; parent: number; taxonomy: string; type: string; diff --git a/plugins/woocommerce/changelog/fix-attribute-filter-reading-property-of-undefined b/plugins/woocommerce/changelog/fix-attribute-filter-reading-property-of-undefined new file mode 100644 index 00000000000..86339f16052 --- /dev/null +++ b/plugins/woocommerce/changelog/fix-attribute-filter-reading-property-of-undefined @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Filter by Attribute: fix potential reading from undefined error