Skip to content

Commit

Permalink
Improve cart page rendering:
Browse files Browse the repository at this point in the history
- Render line_items collection in partial rather than looping
over line_items and rendering the partial multiple times

Fix solidusio#3609
  • Loading branch information
sohara authored and Jeff Dutil committed Aug 22, 2013
1 parent bd54efa commit 424e7d5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 34 deletions.
4 changes: 1 addition & 3 deletions frontend/app/views/spree/orders/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
</tr>
</thead>
<tbody id="line_items" data-hook>
<%= order_form.fields_for :line_items do |item_form| %>
<%= render :partial => 'line_item', :locals => { :variant => item_form.object.variant, :line_item => item_form.object, :item_form => item_form } %>
<% end %>
<%= render partial: 'line_item', collection: order_form.object.line_items, locals: {order_form: order_form} %>
</tbody>
<%= render "spree/orders/adjustments" unless @order.adjustments.eligible.blank? %>
</table>
65 changes: 34 additions & 31 deletions frontend/app/views/spree/orders/_line_item.html.erb
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
<tr class="<%= cycle('', 'alt') %> line-item">
<td class="cart-item-image" data-hook="cart_item_image">
<% if variant.images.length == 0 %>
<%= link_to small_image(variant.product), variant.product %>
<% else %>
<%= link_to image_tag(variant.images.first.attachment.url(:small)), variant.product %>
<% end %>
</td>
<td class="cart-item-description" data-hook="cart_item_description">
<h4><%= link_to variant.product.name, product_path(variant.product) %></h4>
<%= variant.options_text %>
<% if @order.insufficient_stock_lines.include? line_item %>
<span class="out-of-stock">
<%= Spree.t(:out_of_stock) %>&nbsp;&nbsp;<br />
</span>
<% end %>
<%= line_item_description(variant) %>
</td>
<td class="cart-item-price" data-hook="cart_item_price">
<%= line_item.single_money.to_html %>
</td>
<td class="cart-item-quantity" data-hook="cart_item_quantity">
<%= item_form.number_field :quantity, :min => 0, :class => "line_item_quantity", :size => 5 %>
</td>
<td class="cart-item-total" data-hook="cart_item_total">
<%= line_item.display_amount.to_html unless line_item.quantity.nil? %>
</td>
<td class="cart-item-delete" data-hook="cart_item_delete">
<%= link_to image_tag('icons/delete.png'), '#', :class => 'delete', :id => "delete_#{dom_id(line_item)}" %>
</td>
</tr>
<% variant = line_item.variant -%>
<%= order_form.fields_for :line_items, line_item do |item_form| -%>
<tr class="<%= cycle('', 'alt') %> line-item">
<td class="cart-item-image" data-hook="cart_item_image">
<% if variant.images.length == 0 %>
<%= link_to small_image(variant.product), variant.product %>
<% else %>
<%= link_to image_tag(variant.images.first.attachment.url(:small)), variant.product %>
<% end %>
</td>
<td class="cart-item-description" data-hook="cart_item_description">
<h4><%= link_to variant.product.name, product_path(variant.product) %></h4>
<%= variant.options_text %>
<% if @order.insufficient_stock_lines.include? line_item %>
<span class="out-of-stock">
<%= Spree.t(:out_of_stock) %>&nbsp;&nbsp;<br />
</span>
<% end %>
<%= line_item_description(variant) %>
</td>
<td class="cart-item-price" data-hook="cart_item_price">
<%= line_item.single_money.to_html %>
</td>
<td class="cart-item-quantity" data-hook="cart_item_quantity">
<%= item_form.number_field :quantity, :min => 0, :class => "line_item_quantity", :size => 5 %>
</td>
<td class="cart-item-total" data-hook="cart_item_total">
<%= line_item.display_amount.to_html unless line_item.quantity.nil? %>
</td>
<td class="cart-item-delete" data-hook="cart_item_delete">
<%= link_to image_tag('icons/delete.png'), '#', :class => 'delete', :id => "delete_#{dom_id(line_item)}" %>
</td>
</tr>
<% end -%>

0 comments on commit 424e7d5

Please sign in to comment.