-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathregions.inc.twig
74 lines (72 loc) · 3.87 KB
/
regions.inc.twig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
{% set field_name = address.prefix~'_'~location_type %}
{% set show_field = true %}
{% set field_config = "required" %}
{% set field_optional_placeholder = '' %}
{% set maxlength = 50 %}
{% if address.type == 'billing' %}
{% set field_config = config.template_config.custom_checkout_field_requirements[address.type~'_'~location_type] %}
{% set field_optional_placeholder = (field_config == 'optional') ? config.lang.checkout_optional : '' %}
{% set show_field = (field_config != 'hidden') %}
{% endif %}
{% if show_field %}
{% set locations = config.locations %}
{% set locations_filter = (address.type == 'billing') ? config.locations_billing : config.locations_shipping %}
{% set region_lang = "checkout_country" %}
{% set country_code = ((address.country not in locations_filter|keys) or ((address.country in locations_filter|keys) and (locations_filter[address.country] != "*"))) ? address.country : false %}
{% set required_attr = (field_config == "required") ? "data-fc-required" : "" %}
{% if location_type == "region" %}
{% if country_code %}
{% set region_lang = "checkout_location_"~locations[country_code]['r']['lang'] %}
{% set locations = locations[country_code]['r']['options'] %}
{% set locations_filter = (country_code in locations_filter|keys) ? locations_filter[country_code] : [] %}
{% set required_attr = (locations[country_code]['r']['req']) ? "data-fc-required" : "" %}
{% else %}
{% set locations = [] %}
{% set region_lang = "checkout_location_state" %}
{% endif %}
{% endif %}
{% if location_type == "country" %}
{% set maxlength = 2 %}
{% endif %}
<label for="{{ field_name }}" class="fc-form-label fc-form-label--region">{{ config.lang[region_lang]|raw }}</label>
{% if locations|length > 0 %}
<select class="fc-form-control fc-location" data-fc-default-value="{{ address[location_type] }}" data-fc-id="{{ field_name }}" {{ required_attr }} name="{{ field_name }}">
<option value=""></option>
{% for c in locations %}
{% if location_type == "country" %}
{% if (c.cc2 not in locations_filter|keys) or ((c.cc2 in locations_filter|keys) and (locations_filter[c.cc2] != "*")) %}
<option
value="{{ c.cc2 }}"
data-relevancy-booster="{{ c.boost }}"
data-alternative-spellings="{{ c.cc2 }}{% for alt in c.alt %}||{{ alt }}{% endfor %}"
{% if c.cc2 == address[location_type] %}selected{% endif %}
>{{ c.cn }}</option>
{% endif %}
{% else %}
{% if (locations_filter != "*") and (c.c not in locations_filter) %}
<option
value="{{ c.c }}"
data-relevancy-booster="{{ c.boost }}"
data-alternative-spellings="{{ c.c }}{% for alt in c.alt %}||{{ alt }}{% endfor %}"
{% if address[location_type] in [c.c, c.n] %}selected{% endif %}
>{{ c.n }}</option>
{% endif %}
{% endif %}
{% endfor %}
</select>
{% else %}
{% set field_value = address[location_type~'_name'] %}
{% if field_value == "" %}
{% set field_value = address[location_type] %}
{% endif %}
<input
data-fc-id="{{ field_name }}"
name="{{ field_name }}"
value="{{ field_value }}"
type="text"
{{ required_attr }}
placeholder="{{ config.lang[region_lang] }}{{ field_optional_placeholder }}"
maxlength="{{ maxlength }}"
class="fc-form-control fc-location" />
{% endif %}
{% endif %}