Module: Spree::Emails::TemplateData

Defined in:
app/services/spree/emails/template_data.rb

Overview

Turns a record into the JSON an email template reads: the serializer's output, the same data a renderer outside Ruby would receive. Shared by mailers and by the sample data the template editor previews with. Download links and other bearer tokens stay out of it.

Class Method Summary collapse

Class Method Details

.call(object, serializer, store:, currency: nil, **params) ⇒ Hash?

Parameters:

  • object (Object, nil) —

    the record

  • serializer (Class) —

    an email serializer

  • store (Spree::Store)
  • currency (String, nil) (defaults to: nil) —

    defaults to the store's

  • params (Hash) —

    serializer params over the defaults

Returns:

  • (Hash, nil)


14
15
16
17
18
19
20
# File 'app/services/spree/emails/template_data.rb', line 14

def self.call(object, serializer, store:, currency: nil, **params)
  return if object.nil?

  params = { store: store, currency: currency || store.default_currency, locale: I18n.locale.to_s,
             storefront_url: store.storefront_url.to_s.chomp('/'), hide_credentials: true }.merge(params)
  JSON.parse(serializer.new(object, params: params).serialize)
end