commit d0efd0e61a7d0d6064772b2522f04665ac1dc9b4 Author: Axel Date: Thu Oct 2 00:43:27 2025 +0800 first commit diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..4e389f3 Binary files /dev/null and b/.DS_Store differ 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 -%} +