Order Spree::Product by price ?

563 views
Skip to first unread message

tknew

unread,
May 19, 2012, 10:48:21 AM5/19/12
to spree...@googlegroups.com
Hi,

Is it possible to order Spree::Product by price ?
I tried Spree::Product.find(:all, :order => 'price ASC'), it doesn't work 

Thanks 

tknew

unread,
May 19, 2012, 11:01:12 AM5/19/12
to spree...@googlegroups.com
versicolor_ answered me on the IRC channel :

@products = Spree::Product.joins(:variants_including_master).find(:all, :order => 'price ASC')

Thanks !!!

Khalid Shaikh

unread,
Dec 5, 2014, 1:25:35 PM12/5/14
to spree...@googlegroups.com
Thank you !!!

Joshua Farrar

unread,
Dec 5, 2014, 3:46:17 PM12/5/14
to spree...@googlegroups.com
If you check out search_scopes on Spree::Product, you'll see quite a few options for sorting:

pry(main)> Spree::Product.search_scopes
=> [:ascend_by_master_price,
 
:descend_by_master_price,
 
:price_between,
 
:master_price_lte,
 
:master_price_gte,
 
:in_taxon,
 
:in_taxons,
 
:with_property,
 
:with_property_value,
 
:with_option,
 
:with_option_value,
 
:with,
 
:in_name,
 
:in_name_or_keywords,
 
:in_name_or_description,
 
:with_ids,
 
:descend_by_popularity,
 
:not_deleted,
 
:available,
 
:active,
 
:taxons_name_eq,
 
:price_range_any,
 
:brand_any,
 
:selective_brand_any,
 
:in_taxon]

Spree::Product.ascend_by_master_price.each do |product|
  puts product.price
end
Reply all
Reply to author
Forward
0 new messages