Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
[SD-1146] Fix compare at price displaying on PDP
Robert Nowakowski2f226cffd056
diff --git a/core/app/helpers/spree/products_helper.rb b/core/app/helpers/spree/products_helper.rbindex 97aa97e4f1..0486681b5a 100644--- a/core/app/helpers/spree/products_helper.rb+++ b/core/app/helpers/spree/products_helper.rb@@ -35,6 +35,11 @@ module Spreevariants_option_types_presenter(variants, product).default_variant || product.default_variantend+ def should_display_compare_at_price?(default_variant)+ default_variant_price = default_variant.price_in(current_currency)+ default_variant_price.compare_at_amount.present? && (default_variant_price.compare_at_amount > default_variant_price.amount)+ end+def used_variants_options(variants, product)variants_option_types_presenter(variants, product).optionsenddiff --git a/core/app/presenters/spree/variant_presenter.rb b/core/app/presenters/spree/variant_presenter.rbindex 8ee21cc0ad..7ccf9cf88f 100644--- a/core/app/presenters/spree/variant_presenter.rb+++ b/core/app/presenters/spree/variant_presenter.rb@@ -2,6 +2,7 @@ module Spreeclass VariantPresenterinclude Rails.application.routes.url_helpersinclude Spree::BaseHelper+ include Spree::ProductsHelperattr_reader :current_currency, :current_price_options, :current_store@@ -19,7 +20,7 @@ module Spreedisplay_price: display_price(variant),price: variant.price_in(current_currency),display_compare_at_price: display_compare_at_price(variant),- should_display_compare_at_price: should_display_compare_at_price(variant),+ should_display_compare_at_price: should_display_compare_at_price?(variant),is_product_available_in_currency: @is_product_available_in_currency,backorderable: backorderable?(variant),in_stock: in_stock?(variant),@@ -75,9 +76,5 @@ module Spreepurchasable: variant.purchasable?}end-- def should_display_compare_at_price(variant)- variant.compare_at_price.present? && variant.compare_at_price > variant.price- endendenddiff --git a/frontend/app/views/spree/products/_cart_form.html.erb b/frontend/app/views/spree/products/_cart_form.html.erbindex 5f92425aec..5fe1a7d5ab 100644--- a/frontend/app/views/spree/products/_cart_form.html.erb+++ b/frontend/app/views/spree/products/_cart_form.html.erb@@ -16,7 +16,6 @@<% is_product_available_in_currency = product_available_in_currency? %><% default_variant = default_variant(@variants, @product) %>-<% should_display_compare_at_price = default_variant.compare_at_price.present? && default_variant.compare_at_price > default_variant.price %><%= form_for :order, html: {id: 'add-to-cart-form',@@ -28,7 +27,7 @@<div id="inside-product-cart-form" data-hook="inside_product_cart_form"><% if is_product_available_in_currency %><div id="product-price" class="mb-2 text-center text-md-left add-to-cart-form-price" data-hook="product_price">- <% if should_display_compare_at_price %>+ <% if should_display_compare_at_price?(default_variant) %><span class="compare-at-price mr-3"><%= display_compare_at_price(default_variant) %></span><% end %><span class="price selling" content="<%= @product_price.to_d %>">