Skip to content

Commit

Permalink
Update variant sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt-Yorkley committed Aug 9, 2023
1 parent e65efe0 commit a33b6e0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
8 changes: 3 additions & 5 deletions app/models/spree/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@ class Product < ApplicationRecord

has_many :product_properties, dependent: :destroy
has_many :properties, through: :product_properties
has_many :variants, -> { order("spree_variants.position ASC") }, class_name: 'Spree::Variant',
dependent: :destroy
has_many :variants, -> { order("spree_variants.id ASC") }, class_name: 'Spree::Variant',
dependent: :destroy

has_many :prices, -> {
order('spree_variants.position, spree_variants.id, currency')
}, through: :variants
has_many :prices, -> { order('spree_variants.id, currency') }, through: :variants

has_many :stock_items, through: :variants
has_many :supplier_properties, through: :supplier, source: :properties
Expand Down
6 changes: 2 additions & 4 deletions spec/models/spree/product_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ module Spree
end

describe 'Variants sorting' do
context 'without master variant' do
it 'sorts variants by position' do
expect(product.variants.to_sql).to match(/ORDER BY spree_variants.position ASC/)
end
it 'sorts variants by id' do
expect(product.variants.to_sql).to match(/ORDER BY spree_variants.id ASC/)
end
end
end
Expand Down

0 comments on commit a33b6e0

Please sign in to comment.