Skip to content

Commit 7565e40

Browse files
committed
WIP
1 parent f2cc05a commit 7565e40

File tree

3 files changed

+91
-14
lines changed

3 files changed

+91
-14
lines changed

locales/en.default.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,39 @@
164164
"sale_price": "Sale price",
165165
"unit_price": "Unit price"
166166
},
167+
"unit_price": {
168+
"per_item": {
169+
"single": "{{price}} each",
170+
"one": "{{price}} per {{count}} item",
171+
"other": "{{price}} per {{count}} items"
172+
},
173+
"per_unit": "{{price}} / {{count}}{{unit}}",
174+
"per_unit_accessibility": "{{price}} per {{count}}{{unit}}",
175+
"unit": {
176+
"mg": "mg",
177+
"g": "g",
178+
"kg": "kg",
179+
"ml": "ml",
180+
"cl": "cl",
181+
"l": "L",
182+
"m3": "",
183+
"mm": "mm",
184+
"cm": "cm",
185+
"m": "m",
186+
"m2": "",
187+
"oz": "oz",
188+
"lb": "lb",
189+
"floz": "fl oz",
190+
"pt": "pt",
191+
"qt": "qt",
192+
"gal": "gal",
193+
"in": "in",
194+
"ft": "ft",
195+
"yd": "yd",
196+
"ft2": "ft²",
197+
"item": "item"
198+
}
199+
},
167200
"share": "Share this product",
168201
"sold_out": "Sold out",
169202
"unavailable": "Unavailable",

snippets/price.liquid

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -108,20 +108,9 @@
108108
{{ money_price }}
109109
</span>
110110
</div>
111-
<small class="unit-price caption{% if product.selected_or_first_available_variant.unit_price_measurement == nil %} hidden{% endif %}">
112-
<span class="visually-hidden">{{ 'products.product.price.unit_price' | t }}</span>
113-
<span class="price-item price-item--last">
114-
<span>{{- product.selected_or_first_available_variant.unit_price | money -}}</span>
115-
<span aria-hidden="true">/</span>
116-
<span class="visually-hidden">&nbsp;{{ 'accessibility.unit_price_separator' | t }}&nbsp;</span>
117-
<span>
118-
{%- if product.selected_or_first_available_variant.unit_price_measurement.reference_value != 1 -%}
119-
{{- product.selected_or_first_available_variant.unit_price_measurement.reference_value -}}
120-
{%- endif -%}
121-
{{ product.selected_or_first_available_variant.unit_price_measurement.reference_unit }}
122-
</span>
123-
</span>
124-
</small>
111+
{%- if use_variant -%}
112+
{% render 'unit-price', variant: target %}
113+
{%- endif -%}
125114
</div>
126115
{%- if show_badges -%}
127116
<span class="badge price__badge-sale color-{{ settings.sale_badge_color_scheme }}">

snippets/unit-price.liquid

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{%- assign measurement = variant.unit_price_measurement -%}
2+
<small class="unit-price caption{% if measurement == nil %} hidden{% endif %}">
3+
<span class="visually-hidden">{{ 'products.product.price.unit_price' | t }}</span>
4+
<span class="price-item price-item--last">
5+
{%- assign price = variant.unit_price | money -%}
6+
{%- if measurement.measured_type == 'count' -%}
7+
{%- assign count = measurement.reference_value -%}
8+
{%- if measurement.reference_value == 1 -%}
9+
{{- 'products.product.unit_price.per_item.single' | t: price: price -}}
10+
{%- else -%}
11+
{{- 'products.product.unit_price.per_item' | t: price: price, count: count -}}
12+
{%- endif -%}
13+
{%- else -%}
14+
{%- case measurement.reference_unit -%}
15+
{%- when 'ml',
16+
'cl',
17+
'l',
18+
'm3',
19+
'pt',
20+
'qt',
21+
'gal',
22+
'floz',
23+
'mg',
24+
'g',
25+
'kg',
26+
'oz',
27+
'lb',
28+
'mm',
29+
'cm',
30+
'm',
31+
'ft',
32+
'yd',
33+
'in',
34+
'm2',
35+
'ft2',
36+
'item'
37+
-%}
38+
{% comment %}theme-check-disable TranslationKeyExists{% endcomment %}
39+
{%- assign unit = 'products.product.unit_price.unit.' | append: measurement.reference_unit | t -%}
40+
{% comment %}theme-check-enable TranslationKeyExists{% endcomment %}
41+
{%- else -%}
42+
{%- assign unit = measurement.reference_unit -%}
43+
{%- endcase -%}
44+
{%- if measurement.reference_value != 1 -%}
45+
{%- assign count = measurement.reference_value -%}
46+
{%- endif -%}
47+
<span aria-hidden="true">
48+
{{- 'products.product.unit_price.per_unit' | t: price: price, count: count, unit: unit -}}
49+
</span>
50+
<span class="visually-hidden">
51+
{{- 'products.product.unit_price.per_unit_accessibility' | t: price: price, count: count, unit: unit -}}
52+
</span>
53+
{%- endif -%}
54+
</span>
55+
</small>

0 commit comments

Comments
 (0)