Class: Workarea::Storefront::WishListViewModel

Inherits:
ApplicationViewModel
  • Object
show all
Defined in:
app/view_models/workarea/storefront/wish_list_view_model.rb

Instance Method Summary collapse

Instance Method Details

#empty_stateObject



42
43
44
45
46
47
# File 'app/view_models/workarea/storefront/wish_list_view_model.rb', line 42

def empty_state
  I18n.t(
    options[:state] || :unpurchased,
    scope: 'workarea.storefront.wish_lists.empty.states'
  )
end

#empty_textObject



49
50
51
52
53
54
# File 'app/view_models/workarea/storefront/wish_list_view_model.rb', line 49

def empty_text
  I18n.t(
    'workarea.storefront.wish_lists.empty.message',
    state: empty_state
  )
end

#itemsObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/view_models/workarea/storefront/wish_list_view_model.rb', line 8

def items
  @items ||=
    begin
      items = if options[:state] == 'purchased'
        model.purchased_items
      else
        model.unpurchased_items
      end

      items.map do |item|
        product = products.detect { |p| p.id == item.product_id }

        next unless product.active?

        item = Storefront::OrderItemViewModel.new(item)

        WishListItemViewModel.new(
          item,
          product: product,
          inventory: inventory.for_sku(item.sku),
          inventory_collection: inventory,
          pricing: pricing
        )
      end.compact
    end
end

#nameObject



4
5
6
# File 'app/view_models/workarea/storefront/wish_list_view_model.rb', line 4

def name
  user.name.present? ? user.name : user.email
end

#state_optionsObject



35
36
37
38
39
40
# File 'app/view_models/workarea/storefront/wish_list_view_model.rb', line 35

def state_options
  [
    [I18n.t('workarea.storefront.wish_lists.unpurchased_items'), :unpurchased],
    [I18n.t('workarea.storefront.wish_lists.purchased_items'), :purchased]
  ]
end