From ee56647683aa5a1e1de735d29ad339e5519d8777 Mon Sep 17 00:00:00 2001 From: MercuryKojo Date: Thu, 10 Oct 2024 15:15:42 +0200 Subject: [PATCH 1/3] fix(filterDefinition: preSelect.split needs to be nullsafe (#203) local_single hasa preSelect as null and therefore throws an error here Introduced here: https://github.com/pimcore/ecommerce-framework-bundle/pull/194 --- .../indexfieldselectionfield/tags/indexFieldSelection.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Resources/public/js/indexfieldselectionfield/tags/indexFieldSelection.js b/src/Resources/public/js/indexfieldselectionfield/tags/indexFieldSelection.js index f6fdde6c..9daa528c 100644 --- a/src/Resources/public/js/indexfieldselectionfield/tags/indexFieldSelection.js +++ b/src/Resources/public/js/indexfieldselectionfield/tags/indexFieldSelection.js @@ -62,10 +62,10 @@ pimcore.object.tags.indexFieldSelection = Class.create(pimcore.object.tags.selec load: function(store) { if(this.data) { if(this.preSelectCombobox.rendered) { - this.preSelectCombobox.setValue(this.data.preSelect.split(',').map(Number)); + this.preSelectCombobox.setValue(this.data.preSelect?.split(',').map(Number)); } else { this.preSelectCombobox.addListener("afterRender", function() { - this.preSelectCombobox.setValue(this.data.preSelect.split(',').map(Number)); + this.preSelectCombobox.setValue(this.data.preSelect?.split(',').map(Number)); }.bind(this)); } } @@ -239,10 +239,10 @@ pimcore.object.tags.indexFieldSelection = Class.create(pimcore.object.tags.selec if(this.fieldConfig.multiPreSelect == 'local_single' || this.fieldConfig.multiPreSelect == 'local_multi') { if(this.preSelectCombobox.rendered) { - this.preSelectCombobox.setValue(this.data.preSelect.split(',').map(Number)); + this.preSelectCombobox.setValue(this.data.preSelect?.split(',').map(Number)); } else { this.preSelectCombobox.addListener("afterRender", function() { - this.preSelectCombobox.setValue(this.data.preSelect.split(',').map(Number)); + this.preSelectCombobox.setValue(this.data.preSelect?.split(',').map(Number)); }.bind(this)); } } From 245c9a7c01155b5b04033438ae7ed66f79ab4064 Mon Sep 17 00:00:00 2001 From: MercuryKojo Date: Tue, 15 Oct 2024 20:50:42 +0200 Subject: [PATCH 2/3] fix: category id needs to be casted to string for trim function (#205) --- src/FilterService/FilterType/MultiSelectCategory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FilterService/FilterType/MultiSelectCategory.php b/src/FilterService/FilterType/MultiSelectCategory.php index 9e5982f9..c4d43eec 100644 --- a/src/FilterService/FilterType/MultiSelectCategory.php +++ b/src/FilterService/FilterType/MultiSelectCategory.php @@ -96,7 +96,7 @@ public function addCondition(AbstractFilterDefinitionType $filterDefinition, Pro $category = $category->getId(); } - $category = '%,' . trim($category) . ',%'; + $category = '%,' . trim((string)$category) . ',%'; $conditions[] = $filterDefinition->getField() . ' LIKE ' . $db->quote($category); } From c3223f1871e06d204421ea67b34c83e7566bef13 Mon Sep 17 00:00:00 2001 From: MercuryKojo Date: Thu, 31 Oct 2024 08:37:17 +0100 Subject: [PATCH 3/3] fix: .map(Number) creates problems if preselect is not an id but a string (#206) * fix: .map(Number) creates problems if preselect is not an id but a string this is checking if filterGroups in fieldConfig contains 'relation' and only then maps to Number. This could still cause an issue, if a field contains ids and strings. I couldn't find a usecase for this, but something to think about. Another solution would be to cast the key in FilterGroupHelper->getGroupValuesForFilterGroup to string and we can remove the map function altogether. Function is only used in the pimcore_ecommerceframework_index_getvaluesforfilterfield route and therefor should not cause other problems * Introduce method for preselect value --------- Co-authored-by: mattamon --- .../tags/indexFieldSelection.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Resources/public/js/indexfieldselectionfield/tags/indexFieldSelection.js b/src/Resources/public/js/indexfieldselectionfield/tags/indexFieldSelection.js index 9daa528c..f165174c 100644 --- a/src/Resources/public/js/indexfieldselectionfield/tags/indexFieldSelection.js +++ b/src/Resources/public/js/indexfieldselectionfield/tags/indexFieldSelection.js @@ -62,10 +62,10 @@ pimcore.object.tags.indexFieldSelection = Class.create(pimcore.object.tags.selec load: function(store) { if(this.data) { if(this.preSelectCombobox.rendered) { - this.preSelectCombobox.setValue(this.data.preSelect?.split(',').map(Number)); + this.preSelectCombobox.setValue(this.getPreselectValue()); } else { this.preSelectCombobox.addListener("afterRender", function() { - this.preSelectCombobox.setValue(this.data.preSelect?.split(',').map(Number)); + this.preSelectCombobox.setValue(this.getPreselectValue()); }.bind(this)); } } @@ -239,10 +239,10 @@ pimcore.object.tags.indexFieldSelection = Class.create(pimcore.object.tags.selec if(this.fieldConfig.multiPreSelect == 'local_single' || this.fieldConfig.multiPreSelect == 'local_multi') { if(this.preSelectCombobox.rendered) { - this.preSelectCombobox.setValue(this.data.preSelect?.split(',').map(Number)); + this.preSelectCombobox.setValue(this.getPreselectValue()); } else { this.preSelectCombobox.addListener("afterRender", function() { - this.preSelectCombobox.setValue(this.data.preSelect?.split(',').map(Number)); + this.preSelectCombobox.setValue(this.getPreselectValue()); }.bind(this)); } } @@ -262,5 +262,12 @@ pimcore.object.tags.indexFieldSelection = Class.create(pimcore.object.tags.selec isDirty: function() { return this.fieldsCombobox.isDirty() || (this.preSelectCombobox && this.preSelectCombobox.isDirty()); + }, + + getPreselectValue: function() { + if(this.fieldConfig.filterGroups?.includes('relation')) { + return this.data.preSelect?.split(',').map(Number); + } + return this.data.preSelect?.split(','); } });