first commit
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
.yagi-price-container{display: flex; gap: 0.5em; align-items: center;} .yagi-price-container .price__sale { display: flex; flex-direction: row-reverse !important; justify-content: flex-end; gap: 0.5em; align-items: center;} .yagi-discounted-price {font-size: 19px; font-weight: bold;} .yagi-original-price {font-size: 19px}
|
||||||
@@ -0,0 +1,158 @@
|
|||||||
|
{% comment %}
|
||||||
|
Renders a list of product's price (regular, sale)
|
||||||
|
|
||||||
|
Accepts:
|
||||||
|
- product_object: {Object} Product Liquid object (optional)
|
||||||
|
- use_variant: {Boolean} Renders selected or first variant price instead of overall product pricing (optional)
|
||||||
|
- show_badges: {Boolean} Renders 'Sale' and 'Sold Out' tags if the product matches the condition (optional)
|
||||||
|
- badge_type: {Enum} normal|amount|percentage
|
||||||
|
- show_compare_at_price: {Boolean} Whether to display the compare-at price
|
||||||
|
- class: {String} Adds a price class to the price element (optional)
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
{% render 'price', product_object: product %}
|
||||||
|
{% endcomment %}
|
||||||
|
{%- liquid
|
||||||
|
if use_variant
|
||||||
|
assign target = product_object.selected_or_first_available_variant
|
||||||
|
else
|
||||||
|
assign target = product_object
|
||||||
|
endif
|
||||||
|
|
||||||
|
if show_compare_at_price
|
||||||
|
assign compare_at_price = target.compare_at_price
|
||||||
|
endif
|
||||||
|
|
||||||
|
assign price = target.price
|
||||||
|
|
||||||
|
assign available = target.available | default: false
|
||||||
|
|
||||||
|
comment
|
||||||
|
start Yagi app code
|
||||||
|
endcomment
|
||||||
|
|
||||||
|
if use_variant
|
||||||
|
assign price = target.metafields.app--168074346497.auto_discounted_price.value | default: target.price
|
||||||
|
|
||||||
|
if target.metafields.app--168074346497.discount_type.value != nil and target.metafields.app--168074346497.discount_type.value != "fixed" and product_object.metafields.app--168074346497.discount_percentage.value > 0.01
|
||||||
|
assign deducted_percentage = 1.0 | minus: product_object.metafields.app--168074346497.discount_percentage.value
|
||||||
|
|
||||||
|
if target.metafields.app--168074346497.discount_percentage.value > 0.01
|
||||||
|
assign deducted_percentage = 1.0 | minus: target.metafields.app--168074346497.discount_percentage.value
|
||||||
|
endif
|
||||||
|
|
||||||
|
assign price = target.price | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil
|
||||||
|
|
||||||
|
if show_compare_at_price
|
||||||
|
assign compare_at_price = target.price
|
||||||
|
|
||||||
|
if target.compare_at_price > compare_at_price
|
||||||
|
assign compare_at_price = target.compare_at_price
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
if price < target.price and compare_at_price == blank and show_compare_at_price
|
||||||
|
assign compare_at_price = target.price
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
assign price = product_object.metafields.app--168074346497.min_auto_discounted_price.value | default: product_object.price
|
||||||
|
|
||||||
|
if product_object.metafields.app--168074346497.discount_percentage.value > 0.01
|
||||||
|
assign deducted_percentage = 1.0 | minus: product_object.metafields.app--168074346497.discount_percentage.value
|
||||||
|
|
||||||
|
assign price = product_object.price | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil
|
||||||
|
|
||||||
|
if show_compare_at_price
|
||||||
|
assign compare_at_price = product_object.price
|
||||||
|
|
||||||
|
if product_object.compare_at_price > compare_at_price
|
||||||
|
assign compare_at_price = product_object.compare_at_price
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
if price < product_object.price and compare_at_price == blank and show_compare_at_price
|
||||||
|
assign compare_at_price = product_object.price
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
comment
|
||||||
|
end Yagi app code
|
||||||
|
endcomment
|
||||||
|
|
||||||
|
assign money_price = price | money
|
||||||
|
if settings.currency_code_enabled
|
||||||
|
assign money_price = price | money_with_currency
|
||||||
|
endif
|
||||||
|
|
||||||
|
if target == product_object and product_object.price_varies
|
||||||
|
assign money_price = 'products.product.price.from_price_html' | t: price: money_price
|
||||||
|
endif
|
||||||
|
-%}
|
||||||
|
|
||||||
|
{%- unless target == blank -%}
|
||||||
|
<div class="{% if class %}{{ class }} {% endif %}price{% if compare_at_price > price and compare_at_price != blank %} price--on-sale{% endif %}">
|
||||||
|
<div class="price-container">
|
||||||
|
{%- if compare_at_price > price and compare_at_price != blank -%}
|
||||||
|
<span class="visually-hidden">{{ 'products.product.price.sale_price' | t }}</span>
|
||||||
|
<b class="price-item price-item--sale" dir="ltr">
|
||||||
|
{{ money_price }}
|
||||||
|
</b>
|
||||||
|
{% comment %} “相同的售价,但是原价不同”,为了防止用户困扰,不显示这种情况 {% endcomment %}
|
||||||
|
{%- unless product_object.price_varies == false and product_object.compare_at_price_varies %}
|
||||||
|
<span class="visually-hidden">{{ 'products.product.price.regular_price' | t }}</span>
|
||||||
|
<s class="price-item price-item--regular" dir="ltr">
|
||||||
|
{%- if settings.currency_code_enabled -%}
|
||||||
|
{{ compare_at_price | money_with_currency }}
|
||||||
|
{%- else -%}
|
||||||
|
{{ compare_at_price | money }}
|
||||||
|
{%- endif -%}
|
||||||
|
</s>
|
||||||
|
{%- endunless -%}
|
||||||
|
{%- else -%}
|
||||||
|
<span class="visually-hidden">{{ 'products.product.price.regular_price' | t }}</span>
|
||||||
|
<b class="price-item price-item--regular" dir="ltr">
|
||||||
|
{{ money_price }}
|
||||||
|
</b>
|
||||||
|
{%- endif -%}
|
||||||
|
{% comment %} 按照单位价格计算方式 {% endcomment %}
|
||||||
|
{%- unless product_object.selected_or_first_available_variant.unit_price_measurement == blank -%}
|
||||||
|
<span class="visually-hidden">{{ 'products.product.price.unit_price' | t }}</span>
|
||||||
|
<span class="unit-price price-item" dir="ltr">
|
||||||
|
<span>{{- product_object.selected_or_first_available_variant.unit_price | money -}}</span>
|
||||||
|
<span aria-hidden="true">/</span>
|
||||||
|
<span class="visually-hidden"> {{ 'accessibility.unit_price_separator' | t }} </span>
|
||||||
|
<span>
|
||||||
|
{%- if product_object.selected_or_first_available_variant.unit_price_measurement.reference_value != 1 -%}
|
||||||
|
{{- product_object.selected_or_first_available_variant.unit_price_measurement.reference_value -}}
|
||||||
|
{%- endif -%}
|
||||||
|
{{ product_object.selected_or_first_available_variant.unit_price_measurement.reference_unit }}
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
{%- endunless -%}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{%- if show_badges -%}
|
||||||
|
{%- if available == false -%}
|
||||||
|
<span class="badge sold-out-badge">{{ 'products.product.sold_out' | t }}</span>
|
||||||
|
{%- elsif compare_at_price > price and settings.enable_sale_badge -%}
|
||||||
|
{% assign badge_type = badge_type | default: 'percentage' %}
|
||||||
|
{% render 'sale-badge', target: target, type: badge_type %}
|
||||||
|
{%- endif -%}
|
||||||
|
{%- endif -%}
|
||||||
|
</div>
|
||||||
|
{%- else -%}
|
||||||
|
<div class="price{% if class %} {{ class }}{% endif %}">
|
||||||
|
<div class="price-container">
|
||||||
|
<span class="visually-hidden">{{ 'products.product.price.regular_price' | t }}</span>
|
||||||
|
<b class="price-item price-item--regular" dir="ltr">
|
||||||
|
{%- if settings.currency_code_enabled -%}
|
||||||
|
{{ '1999' | money_with_currency }}
|
||||||
|
{%- else -%}
|
||||||
|
{{ '1999' | money }}
|
||||||
|
{%- endif -%}
|
||||||
|
</b>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{%- endunless -%}
|
||||||
Reference in New Issue
Block a user