Skip to content

Commit 5c29bd3

Browse files
[Filter] Fix numeric facet option labels replaced by their index
1 parent 60c2767 commit 5c29bd3

3 files changed

Lines changed: 12 additions & 9 deletions

File tree

src/Resources/views/shop/form/checkbox.html.twig

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
{% block sylius_gally_filter_checkbox_row -%}
22
<div class="{% if required %}required {% endif %}field{% if (not compound or force_error|default(false)) and not valid %} error{% endif %}">
33
{{- form_label(form) -}}
4-
{% set choices = {} %}
4+
{% set choices = [] %}
55
{% for choice in form.vars.choices %}
6-
{% set choices = choices|merge({(choice.label): choice.value}) %}
6+
{# merge() renumbers integer-like keys (PHP array_merge behavior), so labels that
7+
look like numbers (e.g. "12") must not be used as array keys: kept as a list of
8+
{label, value} pairs instead. #}
9+
{% set choices = choices|merge([{label: choice.label, value: choice.value}]) %}
710
{% endfor %}
811
{{ component('gally_shop:filter:facet_options', {
912
filterField: form.vars.name,

src/Resources/views/shop/product/_shared/facet_options.html.twig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
</div>
1313
{% endif %}
1414
<div class="ui">
15-
{% for label, value in choices %}
15+
{% for choice in choices %}
1616
<div class="form-check">
1717
<input type="checkbox" class="form-check-input"
1818
id="{{ baseId }}_{{ loop.index0 }}"
1919
name="{{ fieldName }}[]"
20-
value="{{ value }}"
21-
{% if value in selectedValues %}checked{% endif %}>
22-
<label class="form-check-label" for="{{ baseId }}_{{ loop.index0 }}">{{ label }}</label>
20+
value="{{ choice.value }}"
21+
{% if choice.value in selectedValues %}checked{% endif %}>
22+
<label class="form-check-label" for="{{ baseId }}_{{ loop.index0 }}">{{ choice.label }}</label>
2323
</div>
2424
{% endfor %}
2525
</div>

src/Twig/Component/Filter/FacetOptionsComponent.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class FacetOptionsComponent
4848
#[LiveProp]
4949
public string $baseId = '';
5050

51-
/** @var array<string, string> */
51+
/** @var list<array{label: string, value: string}> */
5252
#[LiveProp]
5353
public array $initialChoices = [];
5454

@@ -97,7 +97,7 @@ public function viewMore(): void
9797
}
9898

9999
/**
100-
* @return array<string, string>
100+
* @return list<array{label: string, value: string}>
101101
*/
102102
#[ExposeInTemplate('choices')]
103103
public function getChoices(): array
@@ -116,7 +116,7 @@ public function getChoices(): array
116116
/** @var array<string, string> $option */
117117
foreach ($aggregationOptions as $option) {
118118
if (isset($option['label'])) {
119-
$choices[$option['label']] = $option['value'] ?? '';
119+
$choices[] = ['label' => $option['label'], 'value' => $option['value'] ?? ''];
120120
}
121121
}
122122

0 commit comments

Comments
 (0)