commit 5db023db87034bccb2c8f6d38a30e04d5439d6f9 Author: Axel Date: Wed Jul 15 00:14:32 2026 +0800 first commit diff --git a/custom_css.txt b/custom_css.txt new file mode 100644 index 0000000..34ff7c7 --- /dev/null +++ b/custom_css.txt @@ -0,0 +1 @@ +.yagi-price-container{display: flex; gap: 0.5em; align-items: center;} .yagi-price-container .price__sale { display: flex; flex-direction: row !important; justify-content: flex-end; gap: 0.5em; align-items: center;} .yagi-discounted-price { font-size: 14px; color: var(--color-error); } .yagi-original-price { font-size: 14px; } .yagi-sale-badge { font-size: 14px; color: var(--color-error); } \ No newline at end of file diff --git a/snippets/price.liquid b/snippets/price.liquid new file mode 100644 index 0000000..8296cca --- /dev/null +++ b/snippets/price.liquid @@ -0,0 +1,251 @@ +{% comment %} + Renders a list of product's price (regular, sale) + Accepts: + - product_ref: {Object} Product Liquid object + - use_variant: {Boolean} Renders selected or first variant price instead of overall product pricing (optional) + - price_class: {String} Adds a price class to the price element (optional) + - price_extra_info: {Boolean} Show extra info about price (optional) + Usage: + {% render 'price', product_ref: product %} +{% endcomment %} + +{%- liquid + if use_variant + assign target = product_ref.selected_or_first_available_variant + else + assign target = product_ref + endif + + assign variant = product_ref.selected_or_first_available_variant + + assign compare_at_price = target.compare_at_price + assign price = target.price | default: 1999 + + if target == product_ref and product_ref.price_varies == false + assign compare_at_price = target.compare_at_price_max + endif + + 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_ref.metafields.app--168074346497.discount_percentage.value > 0.01 + assign deducted_percentage = 1.0 | minus: product_ref.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 + + assign compare_at_price = target.price + + if target.compare_at_price > compare_at_price + assign compare_at_price = target.compare_at_price + endif + endif + + if shop.metafields.app--168074346497.discount_percentage.value > 0.005 + assign discount_percentage = shop.metafields.app--168074346497.discount_percentage.value | times: 1.0 + assign deducted_percentage = 1.0 | minus: discount_percentage + + assign price = target.price | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil + + assign compare_at_price = target.price + + if target.compare_at_price > compare_at_price + assign compare_at_price = target.compare_at_price + endif + endif + + if price < target.price and compare_at_price == blank + assign compare_at_price = target.price + endif + else + assign price = product_ref.metafields.app--168074346497.min_auto_discounted_price.value | default: product_ref.price + + if product_ref.metafields.app--168074346497.discount_percentage.value > 0.01 + assign deducted_percentage = 1.0 | minus: product_ref.metafields.app--168074346497.discount_percentage.value + + assign price = product_ref.price | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil + + assign compare_at_price = product_ref.price + + if product_ref.compare_at_price > compare_at_price + assign compare_at_price = product_ref.compare_at_price + endif + endif + + if shop.metafields.app--168074346497.discount_percentage.value > 0.005 + assign discount_percentage = shop.metafields.app--168074346497.discount_percentage.value | times: 1.0 + assign deducted_percentage = 1.0 | minus: discount_percentage + + assign price = product_ref.price | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil + + assign compare_at_price = product_ref.price + + if product_ref.compare_at_price > compare_at_price + assign compare_at_price = product_ref.compare_at_price + endif + endif + + if price < product_ref.price and compare_at_price == blank + assign compare_at_price = product_ref.price + endif + endif + + assign available = target.available | default: false + assign money_price = price | money + assign price_extra_info = price_extra_info | default: false + + if settings.show_currency_codes + assign money_price = price | money_with_currency + endif + + +-%} + +
+
+ {%- if product_ref -%} + {%- if target == product_ref and product_ref.price_varies -%} + {%- liquid + assign money_price_min = product_ref.price_min + assign money_price_max = product_ref.price_max + + assign compare_at_price_max = product_ref.compare_at_price_max + + if compare_at_price < price + assign min_price_class = 'class="sale"' + assign money_price_min = product_ref.compare_at_price_min + endif + -%} + + {%- if compare_at_price_max > money_price_max -%} + + {%- assign sale_container_class = 'price__sale' -%} + + {%- if show_sale_badge -%} + {%- assign sale_container_class = sale_container_class | append: ' price__sale--has-badge' -%} + + {%- capture sale_text_html -%} + + {{- 'products.product.price.sale_badge' | t -}} + + {%- endcapture -%} + {%- endif -%} + +
+
+ {{- 'products.product.price.regular_price' | t -}} + {{- compare_at_price_max | money -}} + + + {{- 'products.product.price.from_price' | t -}} + {{- 'products.product.price.min_price' | t -}} + {{- money_price_min | money -}} + + + + {{- 'products.product.price.max_price' | t -}} + {{- money_price_max | money -}} + +
+ + {{ sale_text_html }} +
+ + {% else %} +
+ {{- 'products.product.price.min_price' | t -}} + {{- product_ref.price_min | money -}} + + + + {{- 'products.product.price.max_price' | t -}} + {{- product_ref.price_max | money -}} +
+ {%- endif -%} + + + + {%- elsif compare_at_price > price -%} + {%- assign sale_container_class = 'price__sale' -%} + + {%- if show_sale_badge -%} + {%- assign sale_container_class = sale_container_class | append: ' price__sale--has-badge' -%} + + {%- capture sale_text_html -%} + + {{- 'products.product.price.sale_badge' | t -}} + + {%- endcapture -%} + {%- endif -%} + +
+
+ {{- 'products.product.price.regular_price' | t -}} + {{- compare_at_price | money -}} + {{- 'products.product.price.sale_price' | t -}} + {{- money_price -}} +
+ + {{ sale_text_html }} +
+ {%- else -%} +
+ {{- 'products.product.price.regular_price' | t -}} + {{- money_price -}} +
+ {%- endif -%} + + + {%- if variant.unit_price_measurement -%} +
+ + {{- 'products.product.price.unit_price' | t -}} + + + {%- if settings.show_currency_codes -%} + {{- variant.unit_price | money_with_currency -}} + {%- else -%} + {{- variant.unit_price | money -}} + {%- endif -%} + + + + {%- if variant.unit_price_measurement.reference_value != 1 -%} + {{- variant.unit_price_measurement.reference_value -}} + {%- endif -%} + + {{- variant.unit_price_measurement.reference_unit -}} +
+ {%- endif -%} + + {%- if price_extra_info and cart.taxes_included or shop.shipping_policy.body != blank -%} +
+ {% liquid + assign taxes_text = '' + + if cart.taxes_included + assign taxes_text = 'products.product.include_taxes' | t | append: ' ' + endif + + if shop.shipping_policy.body != blank + assign shipping_text = 'products.product.shipping_policy_html' | t: link: shop.shipping_policy.url + assign taxes_text = taxes_text | append: shipping_text + endif + %} + {{- taxes_text -}} +
+ {%- endif -%} + {%- else -%} + {{- 9999 | money -}} + {%- endif -%} +
+