Class: Spree::SearchProvider::ProductPresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/spree/search_provider/product_presenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(product, store) ⇒ ProductPresenter

Returns a new instance of ProductPresenter.



6
7
8
9
# File 'app/presenters/spree/search_provider/product_presenter.rb', line 6

def initialize(product, store)
  @product = product
  @store = store
end

Instance Attribute Details

#productObject (readonly)

Returns the value of attribute product.



4
5
6
# File 'app/presenters/spree/search_provider/product_presenter.rb', line 4

def product
  @product
end

#storeObject (readonly)

Returns the value of attribute store.



4
5
6
# File 'app/presenters/spree/search_provider/product_presenter.rb', line 4

def store
  @store
end

Instance Method Details

#callObject

Returns an array of documents — one per market × locale combination. Each document has flat name, description, price fields (no dynamic suffixes).



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/presenters/spree/search_provider/product_presenter.rb', line 13

def call
  documents = []

  market_locale_pairs.each do |market, locale|
    # Skip if product has no price in this currency
    next unless lowest_price(market.currency)

    Mobility.with_locale(locale) do
      documents << build_document(locale, market.currency, default_locale)
    end
  end

  # Fallback for stores without markets (legacy/test)
  if documents.empty?
    fallback_currency = store.default_market&.currency || store.supported_currencies_list.first&.iso_code
    if fallback_currency && lowest_price(fallback_currency)
      documents << build_document(default_locale, fallback_currency, default_locale)
    end
  end

  documents
end