Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {%- comment -%}
- Renders a product price with potential discounts based on price list rules.
- Required variables:
- - product: The product object containing price and collections
- - rules: The rules from the price list configuration metaobject
- - show_original_price: Whether to show the original price
- Optional variables:
- - None
- {%- endcomment -%}
- {%- liquid
- assign current_variant = product.selected_or_first_available_variant
- assign original_price = current_variant.price
- assign final_price = original_price
- assign has_discount = false
- if rules != blank
- for rule in rules
- assign rule_applies = false
- # Check customer tags
- if customer.tags != blank and rule.customerTags != blank
- for tag in rule.customerTags
- if customer.tags contains tag
- assign rule_applies = true
- break
- endif
- endfor
- endif
- # Check product applicability
- if rule_applies
- case rule.applicationType
- when 'ALL_PRODUCTS'
- assign rule_applies = true
- when 'PRODUCTS'
- if rule.products contains product.id
- assign rule_applies = true
- endif
- when 'COLLECTIONS'
- for collection in product.collections
- if rule.collections contains collection.id
- assign rule_applies = true
- break
- endif
- endfor
- endcase
- endif
- # Apply discount if rule matches
- if rule_applies
- assign discounted_price = original_price
- if rule.discountType == 'PERCENTAGE'
- assign discount_amount = original_price | times: rule.discountValue | divided_by: 100
- assign discounted_price = original_price | minus: discount_amount
- elsif rule.discountType == 'FIXED_AMOUNT'
- assign discounted_price = original_price | minus: rule.discountValue
- endif
- if discounted_price < final_price
- assign final_price = discounted_price
- assign has_discount = true
- endif
- endif
- endfor
- endif
- -%}
- <div
- class="dollarlabs_pricelist--product_price"
- id="dollarlabs_pricelist--product_price-{{ section.id }}"
- data-custom-price
- >
- {%- if has_discount -%}
- {%- if show_original_price -%}
- <span style="text-decoration: line-through;" class="dollarlabs_pricelist--original_price">
- {{- original_price | money -}}
- </span>
- {%- endif -%}
- <span class="dollarlabs_pricelist--final_price">
- {{- final_price | money -}}
- </span>
- {%- else -%}
- <span class="dollarlabs_pricelist--regular_price">
- {{- original_price | money -}}
- </span>
- {%- endif -%}
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement