Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

Commit

Permalink
Compare at price logic (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanPJF authored Apr 7, 2017
1 parent 7e7e601 commit ba63aba
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
11 changes: 7 additions & 4 deletions src/scripts/sections/product.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ theme.Product = (function() {
addToCart: '[data-add-to-cart]',
addToCartText: '[data-add-to-cart-text]',
comparePrice: '[data-compare-price]',
comparePriceText: '[data-compare-text]',
originalSelectorId: '[data-product-select]',
priceWrapper: '[data-price-wrapper]',
productFeaturedImage: '[data-product-featured-image]',
Expand Down Expand Up @@ -103,16 +104,18 @@ theme.Product = (function() {
*/
updateProductPrices: function(evt) {
var variant = evt.variant;
var $comparePrice = $(selectors.comparePrice, this.$container);
var $compareEls = $comparePrice.add(selectors.comparePriceText, this.$container);

$(selectors.productPrice, this.$container)
.html(slate.Currency.formatMoney(variant.price, theme.moneyFormat));

if (variant.compare_at_price > variant.price) {
$(selectors.comparePrice, this.$container)
.html(slate.Currency.formatMoney(variant.compare_at_price, theme.moneyFormat))
.removeClass('hide');
$comparePrice.html(slate.Currency.formatMoney(variant.compare_at_price, theme.moneyFormat));
$compareEls.removeClass('hide');
} else {
$(selectors.comparePrice, this.$container).addClass('hide');
$comparePrice.html('');
$compareEls.addClass('hide');
}
},

Expand Down
9 changes: 6 additions & 3 deletions src/sections/featured-product.liquid
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{%- assign product = all_products[section.settings.product] -%}
{%- assign current_variant = product.selected_or_first_available_variant -%}

{% if product.empty? %}
{%- assign section_onboarding = true -%}
Expand Down Expand Up @@ -81,13 +82,15 @@

<div data-price-wrapper>
<span data-product-price>
{{ product.price | default: '1999' | money }}
{{ current_variant.price | default: '1999' | money }}
</span>

{% if product.compare_at_price_max > product.price %}
<span class="visually-hidden">{{ 'products.product.regular_price' | t }}</span>
<span class="visually-hidden" data-compare-text>{{ 'products.product.regular_price' | t }}</span>
<s data-compare-price>
{{ product.compare_at_price | money }}
{% if current_variant.compare_at_price > current_variant.price %}
{{ current_variant.compare_at_price | money }}
{% endif %}
</s>
{% endif %}
</div>
Expand Down
8 changes: 5 additions & 3 deletions src/sections/product.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,12 @@
{{ current_variant.price | money }}
</span>

{% if current_variant.compare_at_price_max > current_variant.price %}
<span class="visually-hidden">{{ 'products.product.regular_price' | t }}</span>
{% if product.compare_at_price_max > product.price %}
<span class="visually-hidden" data-compare-text>{{ 'products.product.regular_price' | t }}</span>
<s data-compare-price>
{{ current_variant.compare_at_price | money }}
{% if current_variant.compare_at_price > current_variant.price %}
{{ current_variant.compare_at_price | money }}
{% endif %}
</s>
{% endif %}
</div>
Expand Down

0 comments on commit ba63aba

Please sign in to comment.