Class: Spree::Storefront::VariantFinder

Inherits:
Object
  • Object
show all
Defined in:
app/finders/spree/storefront/variant_finder.rb

Instance Method Summary collapse

Constructor Details

#initialize(product:, current_currency:, variant_id: nil, options_hash: {}) ⇒ VariantFinder

Returns a new instance of VariantFinder.



4
5
6
7
8
9
# File 'app/finders/spree/storefront/variant_finder.rb', line 4

def initialize(product:, current_currency:, variant_id: nil, options_hash: {})
  @product = product
  @variant_id = variant_id
  @current_currency = current_currency
  @options_hash = options_hash
end

Instance Method Details

#findObject



11
12
13
14
15
16
17
# File 'app/finders/spree/storefront/variant_finder.rb', line 11

def find
  try_variant_from_options
  return [@selected_variant, @variant_from_options] if @selected_variant.present?

  try_any_variant
  [@selected_variant, @variant_from_options]
end