Advertisement
lezlet

dollarlabs-price.liquid

Feb 17th, 2025
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. {%- comment -%}
  2. Renders a product price with potential discounts based on price list rules.
  3.  
  4. Required variables:
  5. - product: The product object containing price and collections
  6. - rules: The rules from the price list configuration metaobject
  7. - show_original_price: Whether to show the original price
  8.  
  9. Optional variables:
  10. - None
  11. {%- endcomment -%}
  12.  
  13. {%- liquid
  14. assign current_variant = product.selected_or_first_available_variant
  15. assign original_price = current_variant.price
  16. assign final_price = original_price
  17. assign has_discount = false
  18.  
  19. if rules != blank
  20. for rule in rules
  21. assign rule_applies = false
  22.  
  23. # Check customer tags
  24. if customer.tags != blank and rule.customerTags != blank
  25. for tag in rule.customerTags
  26. if customer.tags contains tag
  27. assign rule_applies = true
  28. break
  29. endif
  30. endfor
  31. endif
  32.  
  33. # Check product applicability
  34. if rule_applies
  35. case rule.applicationType
  36. when 'ALL_PRODUCTS'
  37. assign rule_applies = true
  38. when 'PRODUCTS'
  39. if rule.products contains product.id
  40. assign rule_applies = true
  41. endif
  42. when 'COLLECTIONS'
  43. for collection in product.collections
  44. if rule.collections contains collection.id
  45. assign rule_applies = true
  46. break
  47. endif
  48. endfor
  49. endcase
  50. endif
  51.  
  52. # Apply discount if rule matches
  53. if rule_applies
  54. assign discounted_price = original_price
  55. if rule.discountType == 'PERCENTAGE'
  56. assign discount_amount = original_price | times: rule.discountValue | divided_by: 100
  57. assign discounted_price = original_price | minus: discount_amount
  58. elsif rule.discountType == 'FIXED_AMOUNT'
  59. assign discounted_price = original_price | minus: rule.discountValue
  60. endif
  61.  
  62. if discounted_price < final_price
  63. assign final_price = discounted_price
  64. assign has_discount = true
  65. endif
  66. endif
  67. endfor
  68. endif
  69. -%}
  70.  
  71. <div
  72. class="dollarlabs_pricelist--product_price"
  73. id="dollarlabs_pricelist--product_price-{{ section.id }}"
  74. data-custom-price
  75. >
  76. {%- if has_discount -%}
  77. {%- if show_original_price -%}
  78. <span style="text-decoration: line-through;" class="dollarlabs_pricelist--original_price">
  79. {{- original_price | money -}}
  80. </span>
  81. {%- endif -%}
  82. <span class="dollarlabs_pricelist--final_price">
  83. {{- final_price | money -}}
  84. </span>
  85. {%- else -%}
  86. <span class="dollarlabs_pricelist--regular_price">
  87. {{- original_price | money -}}
  88. </span>
  89. {%- endif -%}
  90. </div>
  91.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement