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.

Fixed Cart panel N+1s when changing qty (#13036)

Damian Legawiecf3673c4d9b62
diff --git a/storefront/app/helpers/spree/cart_helper.rb b/storefront/app/helpers/spree/cart_helper.rb
index 656fe2546d..c1795d48e4 100644
--- a/storefront/app/helpers/spree/cart_helper.rb
+++ b/storefront/app/helpers/spree/cart_helper.rb
@@ -30,7 +30,7 @@ module Spree
def color_options_style_for_line_items(line_items)
@color_options_style_for_line_items = begin
colors = line_items.map(&:variant).map do |v|
- color_option_values = v.option_values.find_all do |ov|
+ color_option_values = v.option_values.includes(:option_type).find_all do |ov|
ov.option_type.color?
end
diff --git a/storefront/app/views/themes/default/spree/shared/_line_item_options.html.erb b/storefront/app/views/themes/default/spree/shared/_line_item_options.html.erb
index af88531052..d0abc68725 100644
--- a/storefront/app/views/themes/default/spree/shared/_line_item_options.html.erb
+++ b/storefront/app/views/themes/default/spree/shared/_line_item_options.html.erb
@@ -1,4 +1,6 @@
-<% line_item.variant.option_values.select { |ov| ov.option_type.color? }.each do |option| %>
+<% options = line_item.variant.option_values.includes(:option_type) %>
+
+<% options.select { |ov| ov.option_type.color? }.each do |option| %>
<div>
<input class="hidden color-input" value="<%= option.name %>" >
<div class="label-container h-[30px] border border-default p-0.5 inline-flex items-center hover:border-dashed hover:border-primary">
@@ -9,7 +11,7 @@
</div>
</div>
<% end %>
-<% line_item.variant.option_values.reject { |ov| ov.option_type.color? }.each do |option| %>
+<% options.reject { |ov| ov.option_type.color? }.each do |option| %>
<div>
<div class="h-[30px] border border-default px-2 inline-flex items-center hover:border-dashed hover:border-primary text-sm">
<%= option.presentation %>