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.

Remove some product methods memoization, add default_image and secondary_image to memoized methods const

Łukasz Adamczyk13aab30b48e2
diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb
index 0dd64d784a..21d19f6e24 100644
--- a/core/app/models/spree/product.rb
+++ b/core/app/models/spree/product.rb
@@ -34,6 +34,7 @@ module Spree
MEMOIZED_METHODS = %w[total_on_hand taxonomy_ids taxon_and_ancestors category
default_variant_id tax_category default_variant
+ default_image secondary_image
purchasable? in_stock? backorderable? has_variants?]
STATUS_TO_WEBHOOK_EVENT = {
@@ -399,29 +400,29 @@ module Spree
attr_accessor :prototype_id
def first_or_default_variant(currency)
- @first_or_default_variant ||= if !has_variants?
- default_variant
- elsif first_available_variant(currency).present?
- first_available_variant(currency)
- else
- variants.first
- end
+ if !has_variants?
+ default_variant
+ elsif first_available_variant(currency).present?
+ first_available_variant(currency)
+ else
+ variants.first
+ end
end
def first_available_variant(currency)
- @first_available_variant ||= variants.find { |v| v.purchasable? && v.price_in(currency).amount.present? }
+ variants.find { |v| v.purchasable? && v.price_in(currency).amount.present? }
end
def price_varies?(currency)
- @price_varies ||= prices_including_master.find_all { |p| p.currency == currency && p.amount.present? }.map(&:amount).uniq.count > 1
+ prices_including_master.find_all { |p| p.currency == currency && p.amount.present? }.map(&:amount).uniq.count > 1
end
def any_variant_available?(currency)
- @any_variant_available ||= if has_variants?
- first_available_variant(currency).present?
- else
- master.purchasable? && master.price_in(currency).amount.present?
- end
+ if has_variants?
+ first_available_variant(currency).present?
+ else
+ master.purchasable? && master.price_in(currency).amount.present?
+ end
end
# returns the lowest price for the product in the given currency