From d0efd0e61a7d0d6064772b2522f04665ac1dc9b4 Mon Sep 17 00:00:00 2001 From: Axel Date: Thu, 2 Oct 2025 00:43:27 +0800 Subject: [PATCH] first commit --- .DS_Store | Bin 0 -> 6148 bytes snippets/price.liquid | 103 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 .DS_Store create mode 100644 snippets/price.liquid diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..4e389f3de2b2c8eeab506788fd6d088ff9309c0d GIT binary patch literal 6148 zcmeHKT}s115T4Nr0bly)<6faRh$RX>_X5&ZR7g#r^?i@x6+A`G;A!-mAB!O?_#`4T zVfUMzpWW;S+076UFQ2yyqB#*&Xo4(CLBw2iop|sWkadop?&v`Ko3`5&Ci;sedH0I; z^hA%;<2kW~b!j=lORQ3{sEgkmcakXPMv~*%GKG;|OEM8bw$NWjdiEG2?gMnaR z%)qG)=W_pF;gcyA`Qwxr1p~prKVyJr&8k^qQ+~HjwkLOOLc2v1k+>`h1p4SF00TKk eF4SrMBs$`1$80FGh+Wfx@gtywL>CPF0s|k%?mqzl literal 0 HcmV?d00001 diff --git a/snippets/price.liquid b/snippets/price.liquid new file mode 100644 index 0000000..5344d56 --- /dev/null +++ b/snippets/price.liquid @@ -0,0 +1,103 @@ +{%- doc -%} + This snippet is used to render a product card. + It is used in the product block,featured product block, and the product card block. + + @param {product} product_resource - The product to render + @param {boolean} [show_unit_price] - Whether to show the unit price + @param {boolean} [show_sale_price_first] - Whether to show the sale price first +{%- enddoc -%} + +{%- liquid + assign show_unit_price = show_unit_price | default: false + assign show_sale_price_first = show_sale_price_first | default: false + assign selected_variant = product_resource.selected_or_first_available_variant + assign price = selected_variant.price + assign compare_at_price = selected_variant.compare_at_price + + # start - Yagi discounted price calculation + assign price = selected_variant.metafields.app--168074346497.auto_discounted_price.value | default: selected_variant.price + + if price < selected_variant.price + assign compare_at_price = selected_variant.price + endif + + if selected_variant.metafields.app--168074346497.discount_type.value != nil and selected_variant.metafields.app--168074346497.discount_type.value != "fixed" + assign deducted_percentage = 1.0 | minus: product.metafields.app--168074346497.discount_percentage.value + + if selected_variant.metafields.app--168074346497.discount_percentage.value > 0.01 + assign deducted_percentage = 1.0 | minus: selected_variant.metafields.app--168074346497.discount_percentage.value + endif + + assign price = selected_variant.price | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil + + assign compare_at_price = selected_variant.price + + if selected_variant.compare_at_price > compare_at_price + assign compare_at_price = selected_variant.compare_at_price + endif + endif + # end - Yagi discounted price calculation + + assign show_compare_price = false + if compare_at_price > price + assign show_compare_price = true + endif + + if product_resource == blank + assign price = 1999 + endif + + # Checks if product handle matches the closest product's handle (i.e. product page) + # and if the currency code is enabled for product pages + if product.handle == closest.product.handle and settings.currency_code_enabled_product_pages + assign price = price | money_with_currency + assign compare_at_price = compare_at_price | money_with_currency + + # Checks if product handle does not match the closest product's handle (i.e. product card) + # and if the currency code is enabled for product cards + elsif product.handle != closest.product.handle and settings.currency_code_enabled_product_cards + assign price = price | money_with_currency + assign compare_at_price = compare_at_price | money_with_currency + + else + assign price = price | money + assign compare_at_price = compare_at_price | money + endif +-%} + +
+ {% if show_sale_price_first == false and show_compare_price %} + + {{ 'content.price_regular' | t }}  + {{- compare_at_price -}} + + {% endif %} + + {% if show_compare_price %} + + {{ 'content.price_sale' | t }}  + {{ price | default: ' ' }} + + {% else %} + {{ price | default: ' ' }} + {% endif %} + + {% if show_sale_price_first == true and show_compare_price %} + + {{ 'content.price_regular' | t }}  + {{- compare_at_price -}} + + {% endif %} + {%- if selected_variant.unit_price and show_unit_price %} + {%- liquid + if product.handle == closest.product.handle and settings.currency_code_enabled_product_pages + assign unit_price = selected_variant.unit_price | money_with_currency + elsif product.handle != closest.product.handle and settings.currency_code_enabled_product_cards + assign unit_price = selected_variant.unit_price | money_with_currency + else + assign unit_price = selected_variant.unit_price | money + endif + -%} + {% render 'unit-price', price: unit_price, measurement: selected_variant.unit_price_measurement %} + {%- endif -%} +