commit e494c3b82b358252305a2fc04e395bb564ef45fb Author: Axel Date: Tue Oct 20 17:06:57 2026 +0800 initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..f0dcb94 --- /dev/null +++ b/README.md @@ -0,0 +1,44 @@ +## How to show discounted price on collection page, for Boost AI Search & Filter app + + + +1. Enable the "Discount percentage text" metafield in the Boost app > Settings > Metafield (so that we can access it and display it) + + + +![Settings and Metafields](boost1.png) + + + +![Add Metafield](boost2.png) + + + + + +2. After adding metafield, go to "Integration" > "Shopify integration", and select "Templates " + + + +![Select Shopify integration](boost3.png) + + + +![Click Manage template](boost4.png) + + + +3. Select the active template, and click "Edit code" + + + +![Edit code](boost5.png) + + + + + +Then modify the **product-label/main.liquid** file and **product-price/main.liquid** file, by replacing the code content with the files in this repository. + + + diff --git a/boost1.png b/boost1.png new file mode 100644 index 0000000..be10dbc Binary files /dev/null and b/boost1.png differ diff --git a/boost2.png b/boost2.png new file mode 100644 index 0000000..f6697d4 Binary files /dev/null and b/boost2.png differ diff --git a/boost3.png b/boost3.png new file mode 100644 index 0000000..31ba4a6 Binary files /dev/null and b/boost3.png differ diff --git a/boost4.png b/boost4.png new file mode 100644 index 0000000..455ab06 Binary files /dev/null and b/boost4.png differ diff --git a/boost5.png b/boost5.png new file mode 100644 index 0000000..f29a938 Binary files /dev/null and b/boost5.png differ diff --git a/product-label/main.liquid b/product-label/main.liquid new file mode 100644 index 0000000..a077f65 --- /dev/null +++ b/product-label/main.liquid @@ -0,0 +1,120 @@ +{% assign hideOtherLabelsWhenSoldOut = true -%} +{% assign money_format = request.money_format | strip_html -%} +{% assign removePriceDecimal = false -%} +{% assign showCentAsSuperscript = false -%} +{% assign decimalDelimiter = '' -%} +{% assign withoutTrailingZeros = true -%} + +{% assign compareAtPriceMin = product.compare_at_price_min | default: 0 -%} +{% assign priceMin = product.price_min | default: 0 %} + +{% assign yagi_discount_percentage = product | product_metafield: 'yagi.discount_percentage' | plus: 0 %} +{% if yagi_discount_percentage > 0.01 %} + {% assign compareAtPriceMin = priceMin %} + + {% assign deducted_percentage = 1.0 | minus: yagi_discount_percentage %} + {% assign priceMin = priceMin | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil %} +{% endif %} + +{% if hideOtherLabelsWhenSoldOut != true -%} + {% settings if themeSettings.productItems.productImg.elements.productSaleLabel.isEnable %} + {% if compareAtPriceMin > priceMin -%} + {% assign percent = compareAtPriceMin | minus: priceMin | times: 100 | divided_by: compareAtPriceMin | round -%} + + {% if yagi_discount_percentage > 0.01 %} + {% assign percent = yagi_discount_percentage | times: 100 | ceil %} + {% endif %} + {% assign salePercent = percent | append: '%' -%} + {% assign saleAmount = compareAtPriceMin | minus: priceMin | format_currency: money_format, showCentAsSuperscript, removePriceDecimal, decimalDelimiter, withoutTrailingZeros -%} + {% assign productItemSaleTranslated = "productItem.productItemSale" | translate: translations, "Sale" | replace: '{{salePercent}}', salePercent | replace: '{{saleAmount}}', saleAmount -%} +
+ + {{ productItemSaleTranslated }} + +
+ {% endif -%} + {% settings endif %} + + {% settings if themeSettings.productItems.productImg.elements.productSoldOutLabel.isEnable %} + {% if product.available == false -%} +
+ {{ "productItem.productItemSoldOut" | translate: translations, "Sold out" }} +
+ {% endif -%} + {% settings endif %} + + {% settings if themeSettings.productItems.productImg.elements.productCustomLabelByTag.isEnable %} + {% assign filtered_tags = "" -%} + {% assign all_tags = product.tags -%} + {% if product.original_tags != nill %} + {% assign all_tags = all_tags | concat: product.original_tags -%} + {% endif %} + {% for tag in all_tags -%} + {% if tag contains 'pfs:label' -%} + {% assign tag_without_label = tag | remove: 'pfs:label-' -%} + {% assign filtered_tags = filtered_tags | append: tag_without_label | append: ',' -%} + {% endif -%} + {% endfor -%} + {% assign filtered_tags = filtered_tags | split: ',' -%} + + {% for tag in filtered_tags -%} + {% unless tag == blank %} +
+ + {{ tag }} + +
+ {% endunless %} + {% endfor -%} + {% settings endif %} +{% else -%} + {% if product.available == false -%} + {% settings if themeSettings.productItems.productImg.elements.productSoldOutLabel.isEnable %} +
+ {{ "productItem.productItemSoldOut" | translate: translations, "Sold out" }} +
+ {% settings endif %} + {% else -%} + {% settings if themeSettings.productItems.productImg.elements.productSaleLabel.isEnable %} + {% if compareAtPriceMin > priceMin -%} + {% assign percent = compareAtPriceMin | minus: priceMin | times: 100 | divided_by: compareAtPriceMin| round -%} + {% if yagi_discount_percentage > 0.01 %} + {% assign percent = yagi_discount_percentage | times: 100 | ceil %} + {% endif %} + {% assign salePercent = percent | append: '%' -%} + {% assign saleAmount = compareAtPriceMin | minus: priceMin | format_currency: money_format, showCentAsSuperscript, removePriceDecimal, decimalDelimiter, withoutTrailingZeros -%} + {% assign translatedText = "productItem.productItemSale" | translate: translations, "Sale" | replace: '{{salePercent}}', salePercent | replace: '{{saleAmount}}', saleAmount %} +
+ + {{ translatedText }} + +
+ {% endif -%} + {% settings endif %} + + {% settings if themeSettings.productItems.productImg.elements.productCustomLabelByTag.isEnable %} + {% assign filtered_tags = "" -%} + {% assign all_tags = product.tags -%} + {% if product.original_tags != nill %} + {% assign all_tags = all_tags | concat: product.original_tags -%} + {% endif %} + {% for tag in all_tags -%} + {% if tag contains 'pfs:label' -%} + {% assign tag_without_label = tag | remove: 'pfs:label-' -%} + {% assign filtered_tags = filtered_tags | append: tag_without_label | append: ',' -%} + {% endif -%} + {% endfor -%} + {% assign filtered_tags = filtered_tags | split: ',' -%} + + {% for tag in filtered_tags -%} + {% unless tag == blank %} +
+ + {{ tag }} + +
+ {% endunless %} + {% endfor -%} + {% settings endif %} + {% endif -%} +{% endif -%} diff --git a/product-price/main.liquid b/product-price/main.liquid new file mode 100644 index 0000000..d83cfff --- /dev/null +++ b/product-price/main.liquid @@ -0,0 +1,158 @@ +{% comment %} This Template contains a few variables built from the client js side {% endcomment %} +{% assign removePriceDecimal = false -%} +{% assign decimalDelimiter = '' -%} +{% assign withoutTrailingZeros = true -%} + +{% settings assign textAlign = themeSettings.productItems.productInfo.textAlign %} +{% settings assign productPrice = productInfoElements.price %} + +{% settings assign compareAtPricePosition = '' %} +{% settings if productPrice.compareAtPricePosition %} +{% settings assign compareAtPricePosition = productPrice.compareAtPricePosition %} +{% settings endif %} + +{% assign showCentAsSuperscript = false -%} +{% settings if productPrice.showCentAsSuperscript %} +{% assign showCentAsSuperscript = true -%} +{% settings endif %} + +{% settings assign showCurrencyCodes = false %} +{% settings if productPrice.showCurrencyCodes %} +{% settings assign showCurrencyCodes = true %} +{% settings endif %} + +{% assign money_format = request.money_format -%} +{% settings if showCurrencyCodes %} +{% assign money_format = request.money_format_with_currency -%} +{% settings endif %} + +{% assign showSavingDisplay = false -%} +{% settings if productPrice.showSavingDisplay %} +{% assign showSavingDisplay = true -%} +{% settings endif %} + +{% assign minPrice = product.price_min | times: 1.0 -%} +{% assign maxPrice = 0 -%} +{% if product.price_max -%} + {% assign maxPrice = product.price_max | times: 1.0 -%} +{% endif -%} + +{% comment %} convert variable compareAtPriceMin to number {% endcomment %} +{% assign compareAtPriceMin = 0 -%} +{% if product.compare_at_price_min -%} + {% assign compareAtPriceMin = product.compare_at_price_min | times: 1.0 -%} +{% endif -%} + +{% assign yagi_discount_percentage = product | product_metafield: 'yagi.discount_percentage' | plus: 0 %} +{% if yagi_discount_percentage > 0.01 %} + {% assign compareAtPriceMin = minPrice %} + + {% assign deducted_percentage = 1.0 | minus: yagi_discount_percentage %} + {% assign minPrice = minPrice | divided_by: 100.0 | times: deducted_percentage | times: 100.0 %} + {% assign maxPrice = maxPrice | divided_by: 100.0 | times: deducted_percentage | times: 100.0 %} +{% endif %} + +{% assign isSale = false -%} +{% assign salePercent = 0 -%} +{% assign saleAmount = 0 -%} + +{% if compareAtPriceMin > minPrice -%} + {% assign isSale = true -%} +{% endif -%} + +{% assign compareAtPriceWithFormat = '' -%} +{% unless compareAtPriceMin == null or compareAtPriceMin == 0 or isSale == false -%} + {% comment %} calculate salePercent base on compareAtPriceMin and minPrice {% endcomment %} + {% assign compare = compareAtPriceMin | minus: minPrice | times: 100 -%} + {% assign salePercent = compare | divided_by: compareAtPriceMin | ceil | append: '%' -%} + + {% comment %} compareAtPriceWithFormat is compare price with PriceMin and format currency {% endcomment %} + {% assign compareAtPriceWithFormat = compareAtPriceMin | format_currency: money_format, showCentAsSuperscript, removePriceDecimal, decimalDelimiter, withoutTrailingZeros -%} + {% assign saleAmount = compareAtPriceMin | minus: minPrice -%} +{% endunless -%} + +{% comment %} Format price min {% endcomment %} +{% assign priceMinWithFormat = minPrice | format_currency: money_format, showCentAsSuperscript, removePriceDecimal , decimalDelimiter, withoutTrailingZeros -%} + +{% comment %} Format price max {% endcomment %} +{% assign priceMaxWithFormat = '' -%} +{% if product.price_max and maxPrice > minPrice -%} + {% assign priceMaxWithFormat = maxPrice | format_currency: money_format, showCentAsSuperscript, removePriceDecimal , decimalDelimiter, withoutTrailingZeros -%} +{% endif -%} + +{% comment %} priceMax used for multi variant price display where it can have min-max price with format and translation {% endcomment %} +{% assign hasMultiVariantPrice = false -%} +{% if translations.productItem.amount contains "minPrice" -%} + {% assign hasMultiVariantPrice = true -%} +{% endif -%} + +{% assign isSamePrice = true -%} +{% if minPrice != maxPrice or product.compare_at_price_min != product.compare_at_price_max -%} + {% assign isSamePrice = false -%} +{% endif -%} + +{% assign priceValueWithFormat = priceMinWithFormat -%} +{% if isSamePrice == false and maxPrice > minPrice and hasMultiVariantPrice -%} + {% assign priceValueWithFormat = "productItem.amount" | translate: translations, "" | replace: '{{minPrice}}', priceMinWithFormat | replace: '{{maxPrice}}', priceMaxWithFormat -%} +{% endif -%} + +{% assign savingPriceWithFormat = '' -%} +{% unless showSavingDisplay == false or saleAmount == 0 -%} + {% assign saleAmountWithFormat = saleAmount | format_currency: money_format, showCentAsSuperscript, removePriceDecimal, decimalDelimiter, withoutTrailingZeros -%} + {% assign savingPriceWithFormat = "productItem.savingAmount" | translate: translations, "Save {{saleAmount}}" | replace: '{{saleAmount}}', saleAmountWithFormat | replace: '{{salePercent}}', salePercent -%} +{% endunless -%} + +{% comment %} Price compare display top or bottom {% endcomment %} +{% settings if compareAtPricePosition == 'top' or compareAtPricePosition == 'bottom' %} +
+
+ + {{ priceValueWithFormat }} + {% if savingPriceWithFormat -%} + {{ savingPriceWithFormat }} + {% endif -%} +
+ + {% if compareAtPriceWithFormat -%} +
+ + {{ compareAtPriceWithFormat }} + +
+ {% endif -%} +
+ +{% settings else %} +{% comment %} Price compare display left or right {% endcomment %} +
+ + + {{ priceValueWithFormat }} + + {% if compareAtPriceWithFormat != null and compareAtPriceWithFormat != blank and compareAtPriceWithFormat != 0 and compareAtPriceWithFormat != '' and compareAtPriceWithFormat != '0' %} + {% assign trimmed_compare_price = compareAtPriceWithFormat | strip %} + {% if trimmed_compare_price != '' %} + + {{ compareAtPriceWithFormat }} + + {% endif %} + {% endif %} + + + {% if savingPriceWithFormat -%} + {{ savingPriceWithFormat }} + {% endif -%} +
+{% settings endif %}