Class: Workarea::Storefront::GoogleProductFeedViewModel

Inherits:
ApplicationViewModel
  • Object
show all
Includes:
ActionView::Helpers::SanitizeHelper, ActionView::Helpers::TextHelper
Defined in:
app/view_models/workarea/storefront/google_product_feed_view_model.rb

Defined Under Namespace

Modules: ProductImageUrl

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.fieldsObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/view_models/workarea/storefront/google_product_feed_view_model.rb', line 18

def self.fields
  [
    'item_group_id',
    'id',
    'title',
    'description',
    'link',
    'image_link',
    'availability',
    'condition',
    'brand',
    'color',
    'size',
    'google_product_category',
    'product_type',
    'price'
  ] + GoogleProductFeed.static_feed_values.keys
end

Instance Method Details

#brandObject



39
40
41
42
# File 'app/view_models/workarea/storefront/google_product_feed_view_model.rb', line 39

def brand
  return '' unless model.filters['brand'].present?
  model.filters['brand'].join(' ')
end

#category_nameObject



44
45
46
47
48
# File 'app/view_models/workarea/storefront/google_product_feed_view_model.rb', line 44

def category_name
  model.google_category.presence ||
  category&.google_name.presence ||
  Workarea::GoogleProductFeed.default_category
end

#imageObject

TODO this should be changed to return sku images if present



51
52
53
# File 'app/view_models/workarea/storefront/google_product_feed_view_model.rb', line 51

def image
  ProductImageUrl.product_image_url(images.primary, GoogleProductFeed.image_size)
end

#meta_descriptionObject



55
56
57
58
59
60
61
# File 'app/view_models/workarea/storefront/google_product_feed_view_model.rb', line 55

def meta_description
  if model.meta_description.present?
    sanitize_description(model.meta_description)
  else
    sanitize_description(model.description)
  end
end

#product_typeObject



63
64
65
66
# File 'app/view_models/workarea/storefront/google_product_feed_view_model.rb', line 63

def product_type
  return '' unless model.filters['product_type'].present?
  model.filters['product_type'].first
end

#sku_price(sku) ⇒ Object



77
78
79
# File 'app/view_models/workarea/storefront/google_product_feed_view_model.rb', line 77

def sku_price(sku)
  pricing.for_sku(sku).sell
end

#variantsObject



68
69
70
71
72
73
74
75
# File 'app/view_models/workarea/storefront/google_product_feed_view_model.rb', line 68

def variants
  @variants ||= model.variants.map do |variant|
    GoogleProductFeedSkuViewModel.wrap(
      variant,
      inventory_sku: inventory.for_sku(variant.sku)
    )
  end
end