mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Move line item rendering to collection in cart page
Improvement from upstream Spree commit. Brings a big performance boost to rendering, especially with larger numbers of items in the cart. 50%+ reduction in rendering times reported.
This commit is contained in:
@@ -17,8 +17,7 @@
|
||||
%th.cart-item-delete-header
|
||||
|
||||
%tbody#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 }
|
||||
= render partial: 'line_item', collection: order_form.object.line_items, locals: {order_form: order_form}
|
||||
|
||||
= render 'bought' if show_bought_items? && @order.cart?
|
||||
|
||||
|
||||
@@ -1,37 +1,39 @@
|
||||
%tr.line-item{class: "variant-#{variant.id}"}
|
||||
%td.cart-item-description{'data-hook' => "cart_item_description"}
|
||||
- variant = line_item.variant
|
||||
= order_form.fields_for :line_items, line_item do |item_form|
|
||||
%tr.line-item{class: "variant-#{variant.id}"}
|
||||
%td.cart-item-description{'data-hook' => "cart_item_description"}
|
||||
|
||||
%div.item-thumb-image{"data-hook" => "cart_item_image"}
|
||||
= render 'spree/shared/variant_thumbnail', variant: variant
|
||||
%div.item-thumb-image{"data-hook" => "cart_item_image"}
|
||||
= render 'spree/shared/variant_thumbnail', variant: variant
|
||||
|
||||
= render 'spree/shared/line_item_name', line_item: line_item
|
||||
= render 'spree/shared/line_item_name', line_item: line_item
|
||||
|
||||
- if @insufficient_stock_lines.andand.include? line_item
|
||||
%span.out-of-stock
|
||||
= variant.in_stock? ? t(".insufficient_stock", :on_hand => variant.on_hand) : t(".out_of_stock")
|
||||
%br/
|
||||
- if @insufficient_stock_lines.andand.include? line_item
|
||||
%span.out-of-stock
|
||||
= variant.in_stock? ? t(".insufficient_stock", :on_hand => variant.on_hand) : t(".out_of_stock")
|
||||
%br/
|
||||
|
||||
- if @unavailable_order_variants.andand.include? line_item.variant
|
||||
%span.out-of-stock
|
||||
= t(".unavailable_item")
|
||||
%br/
|
||||
- if @unavailable_order_variants.andand.include? line_item.variant
|
||||
%span.out-of-stock
|
||||
= t(".unavailable_item")
|
||||
%br/
|
||||
|
||||
%td.text-right.cart-item-price{"data-hook" => "cart_item_price"}
|
||||
= line_item.single_display_amount_with_adjustments.to_html
|
||||
- if feature? :unit_price, spree_current_user
|
||||
%br
|
||||
%span.unit-price
|
||||
= line_item.unit_price_price_and_unit
|
||||
%td.text-center.cart-item-quantity{"data-hook" => "cart_item_quantity"}
|
||||
- finalized_quantity = @order.completed? ? line_item.quantity : 0
|
||||
= item_form.number_field :quantity,
|
||||
:min => 0, "ofn-on-hand" => "#{variant.on_demand && 9999 || variant.on_hand}",
|
||||
"finalizedquantity" => finalized_quantity, :class => "line_item_quantity", :size => 5,
|
||||
"ng-model" => "line_item_#{line_item.id}",
|
||||
"validate-stock-quantity" => true
|
||||
%td.cart-item-total.text-right{"data-hook" => "cart_item_total"}
|
||||
= line_item.display_amount_with_adjustments.to_html unless line_item.quantity.nil?
|
||||
%td.text-right.cart-item-price{"data-hook" => "cart_item_price"}
|
||||
= line_item.single_display_amount_with_adjustments.to_html
|
||||
- if feature? :unit_price, spree_current_user
|
||||
%br
|
||||
%span.unit-price
|
||||
= line_item.unit_price_price_and_unit
|
||||
%td.text-center.cart-item-quantity{"data-hook" => "cart_item_quantity"}
|
||||
- finalized_quantity = @order.completed? ? line_item.quantity : 0
|
||||
= item_form.number_field :quantity,
|
||||
:min => 0, "ofn-on-hand" => "#{variant.on_demand && 9999 || variant.on_hand}",
|
||||
"finalizedquantity" => finalized_quantity, :class => "line_item_quantity", :size => 5,
|
||||
"ng-model" => "line_item_#{line_item.id}",
|
||||
"validate-stock-quantity" => true
|
||||
%td.cart-item-total.text-right{"data-hook" => "cart_item_total"}
|
||||
= line_item.display_amount_with_adjustments.to_html unless line_item.quantity.nil?
|
||||
|
||||
%td.cart-item-delete.text-center{"data-hook" => "cart_item_delete"}
|
||||
%a.delete{href: "#", id: "delete_#{dom_id(line_item)}"}
|
||||
%i.delete.ofn-i_026-trash
|
||||
%td.cart-item-delete.text-center{"data-hook" => "cart_item_delete"}
|
||||
%a.delete{href: "#", id: "delete_#{dom_id(line_item)}"}
|
||||
%i.delete.ofn-i_026-trash
|
||||
|
||||
Reference in New Issue
Block a user