Add price with minimal
This commit is contained in:
1 parent
d0efd0e61a
commit
fbfbfc2d92
1 file changed
+192
@@ -0,0 +1,192 @@
|
||||
{%- 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
|
||||
|
||||
# Check if variant has volume pricing
|
||||
assign has_volume_pricing = null
|
||||
assign price_min = null
|
||||
assign price_max = null
|
||||
|
||||
# For product cards (collection/search pages), calculate min/max across all variants
|
||||
# For product pages, only use the selected variant's pricing
|
||||
assign is_product_card = false
|
||||
if template.name != 'product'
|
||||
assign is_product_card = true
|
||||
endif
|
||||
|
||||
if is_product_card
|
||||
assign price_min = product_resource.price_min
|
||||
assign price_max = product_resource.price_max
|
||||
|
||||
# start - Yagi discounted price calculation
|
||||
assign price = product_resource.metafields.app--168074346497.min_auto_discounted_price.value | default: product_resource.price
|
||||
|
||||
if product_resource.metafields.app--168074346497.discount_percentage.value > 0.01
|
||||
assign deducted_percentage = 1.0 | minus: product_resource.metafields.app--168074346497.discount_percentage.value
|
||||
|
||||
assign price = product_resource.price | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil
|
||||
assign price_min = price
|
||||
assign price_max = product_resource.price_max | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil
|
||||
|
||||
comment
|
||||
assign compare_at_price = product_resource.price
|
||||
|
||||
if product_resource.compare_at_price > compare_at_price
|
||||
assign compare_at_price = product_resource.compare_at_price
|
||||
endif
|
||||
endcomment
|
||||
endif
|
||||
# end - Yagi discounted price calculation
|
||||
|
||||
assign has_volume_pricing = product_resource.quantity_price_breaks_configured? | default: false
|
||||
else
|
||||
# Product page: only use selected variant's pricing
|
||||
if selected_variant.quantity_price_breaks.size > 0
|
||||
assign has_volume_pricing = true
|
||||
assign price_min = selected_variant.quantity_price_breaks.last.price
|
||||
assign price_max = selected_variant.price
|
||||
endif
|
||||
endif
|
||||
|
||||
# Determine if currency code should be shown
|
||||
assign use_currency = false
|
||||
if product.handle == product_resource.handle
|
||||
if settings.currency_code_enabled_product_pages
|
||||
assign use_currency = true
|
||||
endif
|
||||
elsif settings.currency_code_enabled_product_cards
|
||||
assign use_currency = true
|
||||
endif
|
||||
|
||||
# Format all prices
|
||||
if use_currency
|
||||
assign price = price | money_with_currency
|
||||
assign compare_at_price = compare_at_price | money_with_currency
|
||||
assign price_min = price_min | money_with_currency
|
||||
assign price_max = price_max | money_with_currency
|
||||
else
|
||||
assign price = price | money
|
||||
assign compare_at_price = compare_at_price | money
|
||||
assign price_min = price_min | money
|
||||
assign price_max = price_max | money
|
||||
endif
|
||||
-%}
|
||||
|
||||
<div ref="priceContainer">
|
||||
{% if has_volume_pricing %}
|
||||
{% comment %} Volume pricing display {% endcomment %}
|
||||
{% if show_compare_price %}
|
||||
<span class="price-item__group">
|
||||
<span class="visually-hidden">{{ 'content.price_regular' | t }} </span>
|
||||
<span class="compare-at-price">{{- compare_at_price -}}</span>
|
||||
</span>
|
||||
{% endif %}
|
||||
<span class="price-item__group">
|
||||
<span class="visually-hidden">{{ 'content.price_range' | t }} </span>
|
||||
<span class="price">{{ price_min }} - {{ price_max }}</span>
|
||||
</span>
|
||||
{% else %}
|
||||
{% comment %} Standard pricing display {% endcomment %}
|
||||
<div
|
||||
class="
|
||||
price__regular
|
||||
{% if show_compare_price %}
|
||||
price__hidden
|
||||
{% endif %}
|
||||
"
|
||||
>
|
||||
<span class="price">{{ price | default: ' ' }}</span>
|
||||
</div>
|
||||
<div
|
||||
class="
|
||||
price__sale
|
||||
{% unless show_compare_price %}
|
||||
price__hidden
|
||||
{% endunless %}
|
||||
"
|
||||
>
|
||||
{% if show_sale_price_first %}
|
||||
<span class="price-item__group">
|
||||
<span class="visually-hidden">{{ 'content.price_sale' | t }} </span>
|
||||
<span class="price-item--sale price">{{ price | default: ' ' }}</span>
|
||||
</span>
|
||||
<span class="price-item__group">
|
||||
<span class="visually-hidden">{{ 'content.price_regular' | t }} </span>
|
||||
<span class="price-item--regular compare-at-price">{{- compare_at_price -}}</span>
|
||||
</span>
|
||||
{% else %}
|
||||
<span class="price-item__group">
|
||||
<span class="visually-hidden">{{ 'content.price_regular' | t }} </span>
|
||||
<span class="price-item--regular compare-at-price">{{- compare_at_price -}}</span>
|
||||
</span>
|
||||
<span class="price-item__group">
|
||||
<span class="visually-hidden">{{ 'content.price_sale' | t }} </span>
|
||||
<span class="price-item--sale price">{{ price | default: ' ' }}</span>
|
||||
</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{%- if selected_variant.unit_price and show_unit_price %}
|
||||
{%- liquid
|
||||
if use_currency
|
||||
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 -%}
|
||||
</div>
|
||||
{%- if has_volume_pricing -%}
|
||||
<small
|
||||
ref="volumePricingNote"
|
||||
class="volume-pricing-note"
|
||||
>
|
||||
{{- 'content.volume_pricing_available' | t -}}
|
||||
</small>
|
||||
{%- endif -%}
|
||||
Reference in new issue
Block a user