first commit
This commit is contained in:
114
snippets/price.liquid
Normal file
114
snippets/price.liquid
Normal file
@@ -0,0 +1,114 @@
|
||||
{% comment %}
|
||||
Parameters:
|
||||
- product {Object} - Product object.
|
||||
- show_currency_code {Boolean} - Use 'money_with_currency' instead of 'money'.
|
||||
- show_labels {Boolean} - Show Sale/Sold Out labels (optional, default is false).
|
||||
- for_variant_picker {Boolean} - Uses variant price and markup for display of all variant states (optional, default is false).
|
||||
- current_variant {Object} - Current variant, if for_variant_picker is true.
|
||||
|
||||
Usage:
|
||||
{% render 'price', product: product %}
|
||||
{% endcomment %}
|
||||
|
||||
{%- liquid
|
||||
assign variant = current_variant | default: product.variants | sort: 'price' | first
|
||||
|
||||
if for_variant_picker
|
||||
if current_variant == false
|
||||
assign available = true
|
||||
endif
|
||||
else
|
||||
assign for_variant_picker = false
|
||||
assign available = variant.available | default: false
|
||||
endif
|
||||
|
||||
assign compare_at_price = variant.compare_at_price
|
||||
assign price = variant.price | default: 1999
|
||||
|
||||
comment
|
||||
start yagi code
|
||||
endcomment
|
||||
assign target = 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.metafields.app--168074346497.discount_percentage.value > 0.01
|
||||
assign deducted_percentage = 1.0 | minus: product.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 price < target.price and compare_at_price == blank
|
||||
assign compare_at_price = target.price
|
||||
endif
|
||||
|
||||
comment
|
||||
end yagi code
|
||||
endcomment
|
||||
-%}
|
||||
|
||||
<div class="price{%- if compare_at_price > price %} price--on-sale{% endif -%}
|
||||
{%- if available == false %} price--sold-out{% endif -%}">
|
||||
<div class="price__default">
|
||||
{%- if product.price_varies -%}
|
||||
{%- if for_variant_picker == false -%}
|
||||
<span class="price__from">{{ 'products.product.from' | t }}</span>
|
||||
{%- elsif for_variant_picker and current_variant == false -%}
|
||||
<span class="price__from">{{ 'products.product.from' | t }}</span>
|
||||
{%- endif -%}
|
||||
{%- endif %}
|
||||
<span class="price__current">
|
||||
{%- if show_currency_code -%}
|
||||
{{ price | money_with_currency }}
|
||||
{%- else -%}
|
||||
{{ price | money }}
|
||||
{%- endif -%}
|
||||
</span>
|
||||
{% if for_variant_picker or compare_at_price > price -%}
|
||||
<span class="price__was">
|
||||
{%- if compare_at_price > price -%}
|
||||
{{- compare_at_price | money -}}
|
||||
{%- endif -%}
|
||||
</span>
|
||||
{%- endif -%}
|
||||
</div>
|
||||
|
||||
{% if show_labels %}
|
||||
{% if settings.prod_sold_out_show and product.available == false %}
|
||||
<span class="price-label price-label--sold-out">{{ 'products.product.sold_out' | t }}</span>
|
||||
{% elsif settings.prod_pre_order_label_show and product.template_suffix contains 'preorder' %}
|
||||
<span class="price-label price-label--preorder">{{ 'products.product.preorder' | t }}</span>
|
||||
{% elsif settings.prod_sale_show and variant.compare_at_price > variant.price %}
|
||||
<span class="price-label price-label--sale">{{ 'products.product.sale' | t }}</span>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% if for_variant_picker or variant.unit_price_measurement %}
|
||||
<div class="unit-price"{% if variant.unit_price_measurement == nil %} hidden{% endif %}>
|
||||
<span class="visually-hidden">{{ 'products.product.price.unit_price' | t }}</span>
|
||||
<span class="unit-price__price">{{ variant.unit_price | money }}</span>
|
||||
<span class="unit-price__separator">{{ 'products.product.price.unit_price_separator' | t }}</span>
|
||||
<span class="unit-price__unit">
|
||||
{%- if variant.unit_price_measurement.reference_value != 1 -%}
|
||||
{{- variant.unit_price_measurement.reference_value -}}
|
||||
{%- endif -%}
|
||||
{{ variant.unit_price_measurement.reference_unit }}
|
||||
</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if for_variant_picker %}
|
||||
<div class="price__no-variant" hidden>
|
||||
<strong class="price__current">{{ 'products.variant.non_existent' | t }}</strong>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
107
snippets/product-label-detail.liquid
Normal file
107
snippets/product-label-detail.liquid
Normal file
@@ -0,0 +1,107 @@
|
||||
{%- capture all_variants_label_html -%}
|
||||
{%- if product.metafields.theme.label != blank -%}
|
||||
<span class="product-label product-label--meta">
|
||||
<span>{{ product.metafields.theme.label | escape }}</span>
|
||||
</span>
|
||||
{%- endif -%}
|
||||
|
||||
{%- liquid
|
||||
if settings.prod_new_show
|
||||
if settings.prod_new_method == 'date'
|
||||
assign now_s = 'now' | date: '%s' | plus: 0
|
||||
assign pub_s = product.created_at | date: '%s' | plus: 0
|
||||
assign diff_days = now_s | minus: pub_s | divided_by: 86400
|
||||
|
||||
if diff_days < settings.prod_new_limit_int
|
||||
assign new_label_text = 'products.product.new' | t
|
||||
endif
|
||||
elsif settings.prod_new_method == 'tag'
|
||||
if product.tags contains 'New' or product.tags contains 'new'
|
||||
assign new_label_text = 'products.product.new' | t
|
||||
endif
|
||||
else
|
||||
for collection in product.collections
|
||||
assign split_collection_handle = collection.handle | split: '-'
|
||||
if split_collection_handle contains 'new'
|
||||
assign new_label_text = 'products.product.new' | t
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
endif
|
||||
-%}
|
||||
{%- if new_label_text -%}
|
||||
<span class="product-label product-label--new-in">
|
||||
<span>{{ new_label_text }}</span>
|
||||
</span>
|
||||
{%- endif -%}
|
||||
{%- endcapture -%}
|
||||
|
||||
<variant-content class="product-label-list">
|
||||
{%- for variant in product.variants -%}
|
||||
<script type="text/template" data-variant="{{ variant.id }}">
|
||||
{%- capture label_html -%}
|
||||
{{- all_variants_label_html -}}
|
||||
|
||||
{%- liquid
|
||||
if variant.metafields.app--168074346497.discount_type.value != nil and variant.metafields.app--168074346497.discount_type.value != "fixed"
|
||||
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 variant_price = variant.price | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil
|
||||
|
||||
assign variant_compare_at_price = variant.price
|
||||
|
||||
if variant.compare_at_price > variant_compare_at_price
|
||||
assign variant_compare_at_price = variant.compare_at_price
|
||||
endif
|
||||
endif
|
||||
|
||||
assign sale_label_text = false
|
||||
if settings.prod_reduction_show and variant_compare_at_price > variant_price
|
||||
if settings.prod_reduction_type == 'percent'
|
||||
assign amount = 1.0 | times: variant_price | divided_by: variant_compare_at_price
|
||||
assign amount = 1.0 | minus: amount
|
||||
assign amount = amount | times: 100.0 | round
|
||||
assign sale_label_text = 'products.product.percent_reduction' | t: amount: amount
|
||||
else
|
||||
assign amount = variant_compare_at_price | minus: variant_price | money
|
||||
assign sale_label_text = 'products.product.value_reduction_html' | t: amount: amount
|
||||
endif
|
||||
endif
|
||||
-%}
|
||||
{%- if sale_label_text -%}
|
||||
<span class="product-label product-label--sale">
|
||||
<span>{{ sale_label_text }}</span>
|
||||
</span>
|
||||
{%- endif -%}
|
||||
{%- endcapture -%}
|
||||
|
||||
{%- if label_html != blank -%}
|
||||
<div class="product-label-container">
|
||||
{{- label_html -}}
|
||||
</div>
|
||||
{%- endif -%}
|
||||
</script>
|
||||
|
||||
{%- if current_variant and variant.id == current_variant.id and label_html -%}
|
||||
<div class="product-label-container">
|
||||
{{- label_html -}}
|
||||
</div>
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
|
||||
{%- if current_variant == false and all_variants_label_html != blank -%}
|
||||
<script type="text/template" data-variant="">
|
||||
<div class="product-label-container">
|
||||
{{- all_variants_label_html -}}
|
||||
</div>
|
||||
</script>
|
||||
<div class="product-label-container">
|
||||
{{- all_variants_label_html -}}
|
||||
</div>
|
||||
{%- endif -%}
|
||||
</variant-content>
|
||||
98
snippets/product-label.liquid
Normal file
98
snippets/product-label.liquid
Normal file
@@ -0,0 +1,98 @@
|
||||
{%- capture label_html -%}
|
||||
{%- assign label_count = 0 -%}
|
||||
{%- if product.metafields.theme.label != blank -%}
|
||||
{%- assign label_count = label_count | plus: 1 -%}
|
||||
<span class="product-label product-label--meta">
|
||||
<span>{{ product.metafields.theme.label | escape }}</span>
|
||||
</span>
|
||||
{%- endif -%}
|
||||
|
||||
{%- liquid
|
||||
if settings.prod_new_show
|
||||
if settings.prod_new_method == 'date'
|
||||
assign now_s = 'now' | date: '%s' | plus: 0
|
||||
assign pub_s = product.created_at | date: '%s' | plus: 0
|
||||
assign diff_days = now_s | minus: pub_s | divided_by: 86400
|
||||
|
||||
if diff_days < settings.prod_new_limit_int
|
||||
assign new_label_text = 'products.product.new' | t
|
||||
endif
|
||||
elsif settings.prod_new_method == 'tag'
|
||||
if product.tags contains 'New' or product.tags contains 'new'
|
||||
assign new_label_text = 'products.product.new' | t
|
||||
endif
|
||||
else
|
||||
for collection in product.collections
|
||||
assign split_collection_handle = collection.handle | split: '-'
|
||||
if split_collection_handle contains 'new'
|
||||
assign new_label_text = 'products.product.new' | t
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
endif
|
||||
-%}
|
||||
{%- if new_label_text -%}
|
||||
{%- assign label_count = label_count | plus: 1 -%}
|
||||
<span class="product-label product-label--new-in">
|
||||
<span>{{ new_label_text }}</span>
|
||||
</span>
|
||||
{%- endif -%}
|
||||
|
||||
{%- liquid
|
||||
assign cheapest_variant_price = cheapest_variant.price
|
||||
assign cheapest_variant_compare_at_price = cheapest_variant.compare_at_price
|
||||
|
||||
if cheapest_variant.metafields.app--168074346497.discount_type.value != nil and cheapest_variant.metafields.app--168074346497.discount_type.value != "fixed"
|
||||
assign deducted_percentage = 1.0 | minus: product.metafields.app--168074346497.discount_percentage.value
|
||||
|
||||
if cheapest_variant.metafields.app--168074346497.discount_percentage.value > 0.01
|
||||
assign deducted_percentage = 1.0 | minus: cheapest_variant.metafields.app--168074346497.discount_percentage.value
|
||||
endif
|
||||
|
||||
assign cheapest_variant_price = cheapest_variant.price | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil
|
||||
|
||||
assign cheapest_variant_compare_at_price = cheapest_variant.price
|
||||
|
||||
if cheapest_variant.compare_at_price > cheapest_variant_compare_at_price
|
||||
assign cheapest_variant_compare_at_price = cheapest_variant.compare_at_price
|
||||
endif
|
||||
endif
|
||||
|
||||
if label_count < 2 and settings.prod_reduction_show and cheapest_variant_compare_at_price > cheapest_variant_price
|
||||
if settings.prod_reduction_type == 'percent'
|
||||
assign amount = 1.0 | times: cheapest_variant_price | divided_by: cheapest_variant_compare_at_price
|
||||
assign amount = 1.0 | minus: amount
|
||||
assign amount = amount | times: 100.0 | round
|
||||
assign sale_label_text = 'products.product.percent_reduction' | t: amount: amount
|
||||
else
|
||||
assign amount = cheapest_variant_compare_at_price | minus: cheapest_variant_price | money
|
||||
assign sale_label_text = 'products.product.value_reduction_html' | t: amount: amount
|
||||
endif
|
||||
assign label_count = label_count | plus: 1
|
||||
endif
|
||||
-%}
|
||||
{%- if sale_label_text -%}
|
||||
<span class="product-label product-label--sale">
|
||||
<span>{{ sale_label_text }}</span>
|
||||
</span>
|
||||
{%- endif -%}
|
||||
|
||||
{%- if label_count < 2 and settings.prod_stock_warn_show and settings.prod_stock_warn_limit_int == 0 and product.variants.size == 1 and product.variants.first.inventory_management != blank and product.variants.first.inventory_quantity > 0 -%}
|
||||
{%- assign label_count = label_count | plus: 1 -%}
|
||||
<span class="product-label product-label--stock">
|
||||
<span>{{ 'products.inventory.only_x_left' | t: quantity: product.variants.first.inventory_quantity }}</span>
|
||||
</span>
|
||||
{%- elsif label_count < 2 and settings.prod_stock_warn_show and product.variants.size == 1 and product.variants.first.inventory_management != blank and product.variants.first.inventory_quantity > 0 and product.variants.first.inventory_quantity <= settings.prod_stock_warn_limit_int -%}
|
||||
{%- assign label_count = label_count | plus: 1 -%}
|
||||
<span class="product-label product-label--stock">
|
||||
<span>{{ 'products.inventory.only_x_left' | t: quantity: product.variants.first.inventory_quantity }}</span>
|
||||
</span>
|
||||
{%- endif -%}
|
||||
{%- endcapture -%}
|
||||
|
||||
{%- if label_html != blank -%}
|
||||
<div class="product-label-container">
|
||||
{{- label_html -}}
|
||||
</div>
|
||||
{%- endif -%}
|
||||
Reference in New Issue
Block a user