Class: SolidusRecommendations::Recommendable::Products
- Defined in:
- lib/solidus_recommendations/recommendable/products.rb
Overview
Provides methods to get recommended products based on certain criteria such as “Bought Together” or “Users also bought”
Constant Summary collapse
- ACCEPTED_INDICES =
Acceptable indices to pass as index option to methods
[:user, :order]
Instance Method Summary collapse
-
#get(product, options = {}) ⇒ Array<Spree::Product]
Gets recommended products.
Instance Method Details
#get(product, options = {}) ⇒ Array<Spree::Product]
Gets recommended products
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/solidus_recommendations/recommendable/products.rb', line 40 def get(product, = {}) return [] if product.nil? .deep_symbolize_keys! index = .delete(:index) || :user size = .delete(:size) || 10 # If index is not supported then we will get a weird undefined # method error. This error will make more sense. raise Errors::NonSupportedIndex unless ACCEPTED_INDICES.include?(index.to_sym) product = convert_to_id([product]).first aggs = send("#{index}_index_significant_terms", product, size) from_significant_terms(aggs, [product], Spree::Product) end |