Skip to content

armgit / spree

Public Imported from GitHub
0

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.

[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.rb
index 97aa97e4f1..0486681b5a 100644
--- a/core/app/helpers/spree/products_helper.rb
+++ b/core/app/helpers/spree/products_helper.rb
@@ -35,6 +35,11 @@ module Spree
variants_option_types_presenter(variants, product).default_variant || product.default_variant
end
+ 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).options
end
diff --git a/core/app/presenters/spree/variant_presenter.rb b/core/app/presenters/spree/variant_presenter.rb
index 8ee21cc0ad..7ccf9cf88f 100644
--- a/core/app/presenters/spree/variant_presenter.rb
+++ b/core/app/presenters/spree/variant_presenter.rb
@@ -2,6 +2,7 @@ module Spree
class VariantPresenter
include Rails.application.routes.url_helpers
include Spree::BaseHelper
+ include Spree::ProductsHelper
attr_reader :current_currency, :current_price_options, :current_store
@@ -19,7 +20,7 @@ module Spree
display_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 Spree
purchasable: variant.purchasable?
}
end
-
- def should_display_compare_at_price(variant)
- variant.compare_at_price.present? && variant.compare_at_price > variant.price
- end
end
end
diff --git a/frontend/app/views/spree/products/_cart_form.html.erb b/frontend/app/views/spree/products/_cart_form.html.erb
index 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 %>">