commit d9bb82bcf64dddc31f4dc9dacfa542b954c74cb8 Author: Axel Date: Fri May 22 01:55:15 2026 +0800 first commit diff --git a/custom_css.css b/custom_css.css new file mode 100644 index 0000000..68aab73 --- /dev/null +++ b/custom_css.css @@ -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} \ No newline at end of file diff --git a/snippets/price.liquid b/snippets/price.liquid new file mode 100644 index 0000000..15c4692 --- /dev/null +++ b/snippets/price.liquid @@ -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 -%} +
+
+ {%- if compare_at_price > price and compare_at_price != blank -%} + {{ 'products.product.price.sale_price' | t }} + + {{ money_price }} + + {% comment %} “相同的售价,但是原价不同”,为了防止用户困扰,不显示这种情况 {% endcomment %} + {%- unless product_object.price_varies == false and product_object.compare_at_price_varies %} + {{ 'products.product.price.regular_price' | t }} + + {%- if settings.currency_code_enabled -%} + {{ compare_at_price | money_with_currency }} + {%- else -%} + {{ compare_at_price | money }} + {%- endif -%} + + {%- endunless -%} + {%- else -%} + {{ 'products.product.price.regular_price' | t }} + + {{ money_price }} + + {%- endif -%} + {% comment %} 按照单位价格计算方式 {% endcomment %} + {%- unless product_object.selected_or_first_available_variant.unit_price_measurement == blank -%} + {{ 'products.product.price.unit_price' | t }} + + {{- product_object.selected_or_first_available_variant.unit_price | money -}} + +  {{ 'accessibility.unit_price_separator' | t }}  + + {%- 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 }} + + + {%- endunless -%} +
+ + {%- if show_badges -%} + {%- if available == false -%} + {{ 'products.product.sold_out' | t }} + {%- 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 -%} +
+{%- else -%} +
+
+ {{ 'products.product.price.regular_price' | t }} + + {%- if settings.currency_code_enabled -%} + {{ '1999' | money_with_currency }} + {%- else -%} + {{ '1999' | money }} + {%- endif -%} + +
+
+{%- endunless -%}