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
Memoize Color option type name to avoid unnecessary SQL calls
Damian Legawiec4f25df3072fb
diff --git a/frontend/app/helpers/spree/frontend_helper.rb b/frontend/app/helpers/spree/frontend_helper.rbindex f8ce4bc0d0..01d7884643 100644--- a/frontend/app/helpers/spree/frontend_helper.rb+++ b/frontend/app/helpers/spree/frontend_helper.rb@@ -298,6 +298,10 @@ module Spree@checkout_available_payment_methods ||= @order.available_payment_methods(current_store)end+ def color_option_type_name+ @color_option_type_name ||= Spree::OptionType.color&.name+ end+privatedef formatted_price(value)diff --git a/frontend/app/views/spree/products/_cart_form.html.erb b/frontend/app/views/spree/products/_cart_form.html.erbindex 5f92425aec..368513f3d9 100644--- a/frontend/app/views/spree/products/_cart_form.html.erb+++ b/frontend/app/views/spree/products/_cart_form.html.erb@@ -56,7 +56,7 @@<ul id="product-variants" class="product-variants"><% used_variants_options(@variants, @product).each_with_index do |option_type, index| %><li>- <% if Spree::OptionType.color&.name == option_type[:name] %>+ <% if color_option_type_name.present? && color_option_type_name == option_type[:name] %><%= render "color_option_type", option_type: option_type, index: index %><% else %><%= render "option_type", option_type: option_type, index: index %>diff --git a/frontend/app/views/spree/shared/_option_values.html.erb b/frontend/app/views/spree/shared/_option_values.html.erbindex 554bde190e..6d4dde4974 100644--- a/frontend/app/views/spree/shared/_option_values.html.erb+++ b/frontend/app/views/spree/shared/_option_values.html.erb@@ -6,7 +6,7 @@<% option_value_param = (selected_option_values.include?(id) ? selected_option_values - [id] : selected_option_values + [id]).join(',') %><%= link_to permitted_params.merge(ot_downcase_name => option_value_param, menu_open: 1), data: { params: permitted_params.merge(ot_downcase_name => option_value_param, menu_open: 1), id: id, filter_name: ot_downcase_name, multiselect: true } do %>- <% if Spree::OptionType.color&.name&.downcase == ot_downcase_name %>+ <% if color_option_type_name.present? && color_option_type_name.downcase == ot_downcase_name %><span class="d-inline-block mb-1"><%= render partial: 'spree/shared/color_select', locals: {