mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Sort line items by name and unit_value for confirmation email and summary screen
This commit is contained in:
@@ -32,6 +32,13 @@ Spree::LineItem.class_eval do
|
||||
end
|
||||
}
|
||||
|
||||
scope :sorted_by_name_and_unit_value,
|
||||
# Find line items that are from order sorted by variant name and unit value
|
||||
joins(:variant=> :product).
|
||||
reorder('spree_products.name asc, spree_variants.unit_value asc').
|
||||
select('spree_line_items.*')
|
||||
|
||||
|
||||
scope :supplied_by, lambda { |enterprise|
|
||||
joins(:product).
|
||||
where('spree_products.supplier_id = ?', enterprise)
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
%h4
|
||||
= t :email_order_summary_price
|
||||
%tbody
|
||||
- @order.line_items.each do |item|
|
||||
- @order.line_items.sorted_by_name_and_unit_value.each do |item|
|
||||
%tr
|
||||
%td
|
||||
= render 'spree/shared/line_item_name', line_item: item
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
%th.text-right.total
|
||||
%span= t(:total)
|
||||
%tbody{"data-hook" => ""}
|
||||
- order.line_items.each do |item|
|
||||
- order.line_items.sorted_by_name_and_unit_value.each do |item|
|
||||
%tr.line_item{"data-hook" => "order_details_line_item_row", class: "variant-#{item.variant.id}" }
|
||||
%td(data-hook = "order_item_description")
|
||||
|
||||
|
||||
@@ -14,6 +14,18 @@ module Spree
|
||||
let(:li1) { create(:line_item, order: o, product: p1) }
|
||||
let(:li2) { create(:line_item, order: o, product: p2) }
|
||||
|
||||
|
||||
let(:p3) {create(:product, name: 'Clear Honey') }
|
||||
let(:p4) {create(:product, name: 'Apricots') }
|
||||
let(:v1) {create(:variant, product: p3, unit_value: 500) }
|
||||
let(:v2) {create(:variant, product: p3, unit_value: 250) }
|
||||
let(:v3) {create(:variant, product: p4, unit_value: 500) }
|
||||
let(:v4) {create(:variant, product: p4, unit_value: 1000) }
|
||||
let(:li3) { create(:line_item, order: o, product: p3, variant: v1) }
|
||||
let(:li4) { create(:line_item, order: o, product: p3, variant: v2) }
|
||||
let(:li5) { create(:line_item, order: o, product: p4, variant: v3) }
|
||||
let(:li6) { create(:line_item, order: o, product: p4, variant: v4) }
|
||||
|
||||
it "finds line items for products supplied by a particular enterprise" do
|
||||
LineItem.supplied_by(s1).should == [li1]
|
||||
LineItem.supplied_by(s2).should == [li2]
|
||||
@@ -40,6 +52,10 @@ module Spree
|
||||
LineItem.without_tax.should == [li2]
|
||||
end
|
||||
end
|
||||
|
||||
it "finds line items sorted by name and unit_value" do
|
||||
o.line_items.sorted_by_name_and_unit_value.should == [li5,li6,li4,li3]
|
||||
end
|
||||
end
|
||||
|
||||
describe "capping quantity at stock level" do
|
||||
|
||||
Reference in New Issue
Block a user