Yagi discounted price modification

This commit is contained in:
Axel Kee
2026-07-02 17:54:13 +08:00
parent 2115f7b08c
commit 6ef0445571
2 changed files with 145 additions and 4 deletions
+47 -4
View File
@@ -41,6 +41,49 @@
endif
-%}
{% liquid
comment
start Yagi app code
endcomment
assign card_product_price = card_product.price
assign card_product_compare_at_price = card_product.compare_at_price
assign card_product_price = card_product.metafields.app--168074346497.min_auto_discounted_price.value | default: card_product.price
if card_product.metafields.app--168074346497.discount_percentage.value > 0.01
assign deducted_percentage = 1.0 | minus: card_product.metafields.app--168074346497.discount_percentage.value
assign card_product_price = card_product.price | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil
assign card_product_compare_at_price = card_product.price
if card_product.compare_at_price > card_product_compare_at_price
assign card_product_compare_at_price = card_product.compare_at_price
endif
endif
if shop.metafields.app--168074346497.discount_percentage.value > 0.005
assign discount_percentage = shop.metafields.app--168074346497.discount_percentage.value | times: 1.0
assign deducted_percentage = 1.0 | minus: discount_percentage
assign card_product_price = card_product.price | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil
assign card_product_compare_at_price = card_product.price
if card_product.compare_at_price > card_product_compare_at_price
assign card_product_compare_at_price = card_product.compare_at_price
endif
endif
if card_product_price < card_product.price and card_product_compare_at_price == blank
assign card_product_compare_at_price = card_roduct.price
endif
comment
end Yagi app code
endcomment
%}
<product-component view-event-payload="{{ card_product | standard_event_data: 'view', context: product_view_context | escape }}">
<div class="card-wrapper product-card-wrapper underline-links-hover">
<div
@@ -120,7 +163,7 @@
href="{{ card_product.url }}"
id="StandardCardNoMediaLink-{{ section_id }}-{{ card_product.id }}"
class="full-unstyled-link"
aria-labelledby="StandardCardNoMediaLink-{{ section_id }}-{{ card_product.id }}{% if card_product.available == false or card_product.compare_at_price > card_product.price %} NoMediaStandardBadge-{{ section_id }}-{{ card_product.id }}{% endif %}"
aria-labelledby="StandardCardNoMediaLink-{{ section_id }}-{{ card_product.id }}{% if card_product.available == false or card_product_compare_at_price > card_product_price %} NoMediaStandardBadge-{{ section_id }}-{{ card_product.id }}{% endif %}"
>
{{ card_product.title | escape }}
</a>
@@ -134,7 +177,7 @@
>
{{- 'products.product.sold_out' | t -}}
</span>
{%- elsif card_product.compare_at_price > card_product.price and card_product.available -%}
{%- elsif card_product_compare_at_price > card_product_price and card_product.available -%}
<span
id="NoMediaStandardBadge-{{ section_id }}-{{ card_product.id }}"
class="badge badge--bottom-left color-{{ settings.sale_badge_color_scheme }}"
@@ -157,7 +200,7 @@
href="{{ card_product.url }}"
id="CardLink-{{ section_id }}-{{ card_product.id }}"
class="full-unstyled-link"
aria-labelledby="CardLink-{{ section_id }}-{{ card_product.id }}{% if card_product.available == false or card_product.compare_at_price > card_product.price %} Badge-{{ section_id }}-{{ card_product.id }}{% endif %}"
aria-labelledby="CardLink-{{ section_id }}-{{ card_product.id }}{% if card_product.available == false or card_product_compare_at_price > card_product_price %} Badge-{{ section_id }}-{{ card_product.id }}{% endif %}"
>
{{ card_product.title | escape }}
</a>
@@ -558,7 +601,7 @@
>
{{- 'products.product.sold_out' | t -}}
</span>
{%- elsif card_product.compare_at_price > card_product.price and card_product.available -%}
{%- elsif card_product_compare_at_price > card_product_price and card_product.available -%}
<span
id="Badge-{{ section_id }}-{{ card_product.id }}"
class="badge badge--bottom-left color-{{ settings.sale_badge_color_scheme }}"
+98
View File
@@ -26,6 +26,104 @@
assign price_min = product.price_min
assign price_max = product.price_max
assign available = target.available | default: false
comment
start Yagi app code
endcomment
assign public_or_tags_matched = true
if product.metafields.app--168074346497.segment_tags.value.size > 0
assign public_or_tags_matched = false
endif
for etag in product.metafields.app--168074346497.segment_tags.value
if customer.tags contains etag
assign public_or_tags_matched = true
break
endif
endfor
if public_or_tags_matched
if use_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 price_min = price
assign price_max = product.price_max | 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 shop.metafields.app--168074346497.discount_percentage.value > 0.005
assign discount_percentage = shop.metafields.app--168074346497.discount_percentage.value | times: 1.0
assign deducted_percentage = 1.0 | minus: discount_percentage
assign price = target.price | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil
assign price_min = price
assign price_max = product.price_max | 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
else
assign price = product.metafields.app--168074346497.min_auto_discounted_price.value | default: product.price
if product.metafields.app--168074346497.discount_percentage.value > 0.01
assign deducted_percentage = 1.0 | minus: product.metafields.app--168074346497.discount_percentage.value
assign price = product.price | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil
assign price_min = price
assign price_max = product.price_max | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil
assign compare_at_price = product.price
if product.compare_at_price > compare_at_price
assign compare_at_price = product.compare_at_price
endif
endif
if shop.metafields.app--168074346497.discount_percentage.value > 0.005
assign discount_percentage = shop.metafields.app--168074346497.discount_percentage.value | times: 1.0
assign deducted_percentage = 1.0 | minus: discount_percentage
assign price = product.price | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil
assign price_min = price
assign price_max = product.price_max | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil
assign compare_at_price = product.price
if product.compare_at_price > compare_at_price
assign compare_at_price = product.compare_at_price
endif
endif
if price < product.price and compare_at_price == blank
assign compare_at_price = product.price
endif
endif
endif
comment
end Yagi app code
endcomment
assign money_price = price | money
assign money_price_min = price_min | money
assign money_price_max = price_max | money