Class: Spree::FeedProduct

Inherits:
Object
  • Object
show all
Defined in:
app/models/spree/feed_product.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(product) ⇒ FeedProduct

Returns a new instance of FeedProduct.



7
8
9
# File 'app/models/spree/feed_product.rb', line 7

def initialize(product)
  @product = product
end

Instance Attribute Details

#productObject (readonly)

Returns the value of attribute product.



5
6
7
# File 'app/models/spree/feed_product.rb', line 5

def product
  @product
end

Instance Method Details

#availabilityObject



54
55
56
# File 'app/models/spree/feed_product.rb', line 54

def availability
  product.master.in_stock? ? 'in stock' : 'out of stock'
end

#brandObject



58
# File 'app/models/spree/feed_product.rb', line 58

def brand; end

#categoryObject



64
65
66
# File 'app/models/spree/feed_product.rb', line 64

def category
  # Must be selected from https://support.google.com/merchants/answer/1705911
end

#conditionObject

Must be “new”, “refurbished”, or “used”.



46
47
48
# File 'app/models/spree/feed_product.rb', line 46

def condition
  "new"
end


39
40
41
42
43
# File 'app/models/spree/feed_product.rb', line 39

def image_link
  return unless product.images.any?

  product.images.first.attachment.url(:large)
end


35
36
37
# File 'app/models/spree/feed_product.rb', line 35

def link
  ->(view) { view.product_url(product) }
end

#mpnObject



60
61
62
# File 'app/models/spree/feed_product.rb', line 60

def mpn
  product.master.sku
end

#priceObject



50
51
52
# File 'app/models/spree/feed_product.rb', line 50

def price
  Spree::Money.new(product.price).money.format(symbol: false, with_currency: true)
end

#schemaObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/models/spree/feed_product.rb', line 11

def schema
  {
    'g:id' => id,
    'title' => title,
    'description' => description,
    'link' => link,
    'g:image_link' => image_link,
    'g:condition' => condition,
    'g:price' => price,
    'g:availability' => availability,
    'g:brand' => brand,
    'g:mpn' => mpn,
    'category' => category,
  }
end

#titleObject



29
30
31
# File 'app/models/spree/feed_product.rb', line 29

def title
  product.name
end