From f890b55a83a6c06197bd39e56ad593f3b7d1d647 Mon Sep 17 00:00:00 2001 From: Axel Date: Tue, 17 Jun 2025 01:20:01 +0800 Subject: [PATCH] first commit --- .DS_Store | Bin 0 -> 6148 bytes snippets/price-list.liquid | 218 +++++++++++++++++++++++++++++++++++++ 2 files changed, 218 insertions(+) create mode 100644 .DS_Store create mode 100644 snippets/price-list.liquid diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..765625e0b3206dba781807b9e967e1e37c78d793 GIT binary patch literal 6148 zcmeHKu};G<5WRyAkytu1`WNyCp@c8U*aej$Kx#;&mOY=w#vgR#TX@fRR1M9*fDl4= zk^Rp0-PwLpY@dke;$>Zm%tfR?Au5##VfWmSSJ%bZ8khZ+n71HnKr z5Dfen1Guv(#f4$i!9Xw&3>+BX`H)bEmE&NTj}BBh1px9Hodr5`3Hl_*%5gBn2t>^l zXs+rhhMGJ2liO8}gQ2;Ldh($@^Jns+d3MB4*<7?Tj5-(y2F47WTXW9){|3LzWRgF2 ziB>QW4E!?&bXGU@0-N%?^<;azYZJ;X3Wat96$tdvBLEGaBbRy5#uIheRgQxpqp&}_ Q1LGl(35hBg_yq<&0Fxju-T(jq literal 0 HcmV?d00001 diff --git a/snippets/price-list.liquid b/snippets/price-list.liquid new file mode 100644 index 0000000..e268d72 --- /dev/null +++ b/snippets/price-list.liquid @@ -0,0 +1,218 @@ +{%- comment -%} +---------------------------------------------------------------------------------------------------------------------- +PRODUCT PRICE +---------------------------------------------------------------------------------------------------------------------- + +Render a list of price for a product, variant or line item. + +******************************************** +Supported variables +******************************************** + +* product: if provided, the prices are rendered for the whole product +* variant: if provided, then only the price from this variant is rendered +* alignment: can be "start", "center" or "end" (default to start) +* line_item: if provided, then the price from this line item are rendered (used on cart or order) +* hide_unit_price: if set to true unit prices are hidden (mostly useful for size constrained elements) +* context: can be "product", "line_item" or "card". This controls how the prices are displayed (using the correct sizes) +{%- endcomment -%} + +{%- liquid + case context + when 'product' + assign regular_price_classes = 'h6 ' + assign on_sale_price_classes = 'h6 text-on-sale' + assign compare_at_price_classes = 'h7 line-through' + assign unit_price_classes = 'subheading text-subdued' + + when 'card' + case settings.product_card_style + when 'subheading': + assign regular_price_classes = 'subheading text-subdued' + assign on_sale_price_classes = 'subheading text-on-sale' + assign compare_at_price_classes = 'subheading text-subdued line-through' + assign unit_price_classes = 'subheading text-subdued' + + when 'body_text': + assign regular_price_classes = 'text-sm text-subdued' + assign on_sale_price_classes = 'text-sm text-on-sale' + assign compare_at_price_classes = 'text-sm text-subdued line-through' + assign unit_price_classes = 'text-sm text-subdued' + + when 'heading': + assign regular_price_classes = 'text-subdued' + assign on_sale_price_classes = 'text-on-sale' + assign compare_at_price_classes = 'text-subdued line-through' + assign unit_price_classes = 'text-subdued' + endcase + + when 'line_item' + assign regular_price_classes = 'subheading text-subdued' + assign on_sale_price_classes = 'subheading text-on-sale' + assign compare_at_price_classes = 'subheading text-subdued line-through' + assign unit_price_classes = 'subheading text-subdued' + endcase +-%} + + + {%- if variant != blank -%} + {%- comment -%} + -------------------------------------------------------------------------------------------------------------------- + VARIANT CASE (used on product page, quick view...) + -------------------------------------------------------------------------------------------------------------------- + {%- endcomment -%} + + {{ 'product.price.sale_price' | t }} + + {%- if settings.currency_code_enabled -%} + {{- variant.price | money_with_currency -}} + {%- else -%} + {{- variant.price | money -}} + {%- endif -%} + + + {%- if variant.compare_at_price > variant.price -%} + + {{ 'product.price.regular_price' | t }} + + {%- if settings.currency_code_enabled -%} + {{- variant.compare_at_price | money_with_currency -}} + {%- else -%} + {{- variant.compare_at_price | money -}} + {%- endif -%} + + {%- endif -%} + {%- elsif line_item != blank -%} + {%- comment -%} + -------------------------------------------------------------------------------------------------------------------- + LINE ITEM CASE (used on cart, order page...) + -------------------------------------------------------------------------------------------------------------------- + {%- endcomment -%} + + {{ 'product.price.sale_price' | t }} + + {%- if settings.currency_code_enabled -%} + {{- line_item.final_price | money_with_currency -}} + {%- else -%} + {{- line_item.final_price | money -}} + {%- endif -%} + + + {%- if line_item.original_price > line_item.final_price -%} + + {{ 'product.price.regular_price' | t }} + + {%- if settings.currency_code_enabled -%} + {{- line_item.original_price | money_with_currency -}} + {%- else -%} + {{- line_item.original_price | money -}} + {%- endif -%} + + {%- endif -%} + {%- elsif product != blank -%} + {%- comment -%} + -------------------------------------------------------------------------------------------------------------------- + PRODUCT CASE (used on card) + -------------------------------------------------------------------------------------------------------------------- + {%- endcomment -%} + {%- liquid + if product.price_varies and settings.product_card_price_strategy != 'from_price' + assign variant = product.variants | sort: 'price' | last | default: product.selected_or_first_available_variant + else + assign variant = product.variants | sort: 'price' | first | default: product.selected_or_first_available_variant + endif + + assign raw_variant_price = variant.price + assign raw_variant_compare_at_price = variant.compare_at_price + + assign raw_variant_price = variant.metafields.app--168074346497.auto_discounted_price.value | default: variant.price + + if variant.metafields.app--168074346497.discount_type.value != nil and variant.metafields.app--168074346497.discount_type.value != "fixed" and product.metafields.app--168074346497.discount_percentage.value > 0.01 + assign deducted_percentage = 1.0 | minus: product.metafields.app--168074346497.discount_percentage.value + + if variant.metafields.app--168074346497.discount_percentage.value > 0.01 + assign deducted_percentage = 1.0 | minus: variant.metafields.app--168074346497.discount_percentage.value + endif + + assign raw_variant_price = variant.price | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil + assign raw_variant_compare_at_price = variant.price + + if variant.compare_at_price > raw_variant_compare_at_price + assign raw_variant_compare_at_price = variant.compare_at_price + endif + endif + + if settings.currency_code_enabled + assign variant_price = raw_variant_price | money_with_currency + assign variant_compare_at_price = raw_variant_compare_at_price | money_with_currency + else + assign variant_price = raw_variant_price | money + assign variant_compare_at_price = raw_variant_compare_at_price | money + endif + -%} + + {%- if product.price_varies -%} + {%- assign is_variant_on_sale = false -%} + + {%- if variant.price < variant.compare_at_price -%} + {%- assign is_variant_on_sale = true -%} + {%- endif -%} + + {%- if settings.product_card_price_strategy == 'from_price' -%} + + {{ 'product.price.sale_price' | t }} + {{- 'product.price.from_price_html' | t: price_min: variant_price -}} + + {%- else -%} + + {{ 'product.price.sale_price' | t }} + {{- variant_price -}} + + {%- endif -%} + {%- else -%} + + {{ 'product.price.sale_price' | t }} + {{- variant_price -}} + + {%- endif -%} + + {%- if raw_variant_price < raw_variant_compare_at_price -%} + + {{ 'product.price.regular_price' | t }} + {{- variant_compare_at_price -}} + + {%- endif -%} + {%- else -%} + {%- comment -%} + -------------------------------------------------------------------------------------------------------------------- + PLACEHOLDER CASE (used on featured product section for instance) + -------------------------------------------------------------------------------------------------------------------- + {%- endcomment -%} + + + {{ 'product.price.sale_price' | t }} + + {%- if settings.currency_code_enabled -%} + {{- 4999 | money_with_currency -}} + {%- else -%} + {{- 4999 | money -}} + {%- endif -%} + + {%- endif -%} + + {%- unless hide_unit_price -%} + {%- assign unit_price_item = variant | default: line_item | default: product.selected_or_first_available_variant -%} + + {%- if unit_price_item.unit_price -%} + + {%- assign unit_price_measurement = unit_price_item.unit_price_measurement -%} + + {%- if unit_price_measurement.reference_value != 1 -%} + {%- assign reference_value = unit_price_measurement.reference_value -%} + {%- endif -%} + + ({{ unit_price_item.unit_price | money }}/{{ reference_value }}{{ unit_price_measurement.reference_unit }}) + + {%- endif -%} + {%- endunless -%} + \ No newline at end of file