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
Check if prices are already loaded (eg. via includes) in Pricing Resolver
Damian Legawiec1c65e8f990b5
diff --git a/core/lib/spree/core/pricing/resolver.rb b/core/lib/spree/core/pricing/resolver.rbindex fd269c2184..d36467471c 100644--- a/core/lib/spree/core/pricing/resolver.rb+++ b/core/lib/spree/core/pricing/resolver.rb@@ -44,19 +44,46 @@ module Spreeenddef find_price_for_list(price_list)- context.variant.prices- .with_currency(context.currency)- .where(price_list_id: price_list.id)- .non_zero- .first+ currency = context.currency&.upcase++ if prices.loaded?+ prices.detect do |p|+ p.currency == currency &&+ p.price_list_id == price_list.id &&+ p.amount.present? &&+ !p.amount.zero?+ end+ else+ context.variant.prices+ .with_currency(currency)+ .where(price_list_id: price_list.id)+ .non_zero+ .first+ endenddef find_base_price+ currency = context.currency&.upcase++ price = if prices.loaded?+ prices.detect do |p|+ p.currency == currency &&+ p.price_list_id.nil? &&+ p.amount.present?+ end+ else+ context.variant.prices+ .with_currency(currency)+ .where(price_list_id: nil)+ .where.not(amount: nil)+ .first+ end++ price || build_empty_price+ end++ def pricescontext.variant.prices- .with_currency(context.currency)- .where(price_list_id: nil)- .where.not(amount: nil)- .first || build_empty_priceenddef build_empty_price