Update variant sorting

This commit is contained in:
Matt-Yorkley
2023-08-09 18:30:56 +01:00
parent e65efe0f85
commit a33b6e0ec9
2 changed files with 5 additions and 9 deletions

View File

@@ -39,12 +39,10 @@ module Spree
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

View File

@@ -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