Class: SolidusFeeds::Generators::GoogleMerchant
- Inherits:
-
Object
- Object
- SolidusFeeds::Generators::GoogleMerchant
- Defined in:
- lib/solidus_feeds/generators/google_merchant.rb
Overview
The GoogleMerchant XML feed as described in support.google.com/merchants/answer/7052112.
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#products ⇒ Object
Returns the value of attribute products.
Instance Method Summary collapse
-
#availability(product) ⇒ Object
Must be “in stock”, “preorder” or “out of stock”.
- #brand(product) ⇒ Object
- #call(io) ⇒ Object
-
#condition(product) ⇒ Object
Must be “new”, “refurbished”, or “used”.
- #description(product) ⇒ Object
- #google_product_category_id(product) ⇒ Object
- #id(product) ⇒ Object
- #image_link(product) ⇒ Object
-
#initialize(products, host:) ⇒ GoogleMerchant
constructor
A new instance of GoogleMerchant.
- #link(product) ⇒ Object
- #mpn(product) ⇒ Object
- #price(product) ⇒ Object
- #render_template(xml) ⇒ Object
- #title(product) ⇒ Object
Constructor Details
#initialize(products, host:) ⇒ GoogleMerchant
Returns a new instance of GoogleMerchant.
11 12 13 14 |
# File 'lib/solidus_feeds/generators/google_merchant.rb', line 11 def initialize(products, host:) self.products = products self.host = host end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
9 10 11 |
# File 'lib/solidus_feeds/generators/google_merchant.rb', line 9 def host @host end |
#products ⇒ Object
Returns the value of attribute products.
9 10 11 |
# File 'lib/solidus_feeds/generators/google_merchant.rb', line 9 def products @products end |
Instance Method Details
#availability(product) ⇒ Object
Must be “in stock”, “preorder” or “out of stock”
82 83 84 |
# File 'lib/solidus_feeds/generators/google_merchant.rb', line 82 def availability(product) product.master.in_stock? ? 'in stock' : 'out of stock' end |
#brand(product) ⇒ Object
86 87 88 |
# File 'lib/solidus_feeds/generators/google_merchant.rb', line 86 def brand(product) product.property("brand") || SolidusFeeds.title end |
#call(io) ⇒ Object
16 17 18 19 |
# File 'lib/solidus_feeds/generators/google_merchant.rb', line 16 def call(io) builder = Builder::XmlMarkup.new(target: io, indent: 0) render_template(builder) end |
#condition(product) ⇒ Object
Must be “new”, “refurbished”, or “used”.
73 74 75 |
# File 'lib/solidus_feeds/generators/google_merchant.rb', line 73 def condition(product) product.property("condition") || "new" end |
#description(product) ⇒ Object
55 56 57 |
# File 'lib/solidus_feeds/generators/google_merchant.rb', line 55 def description(product) product.description end |
#google_product_category_id(product) ⇒ Object
94 95 96 97 |
# File 'lib/solidus_feeds/generators/google_merchant.rb', line 94 def google_product_category_id(product) # Must be selected from https://support.google.com/merchants/answer/1705911 product.property("google_product_category_id") end |
#id(product) ⇒ Object
47 48 49 |
# File 'lib/solidus_feeds/generators/google_merchant.rb', line 47 def id(product) product.id end |
#image_link(product) ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/solidus_feeds/generators/google_merchant.rb', line 63 def image_link(product) return unless product.images.any? = product.images.first..url(:large) asset_host = ActionController::Base.asset_host || host URI.join(asset_host, ).to_s end |
#link(product) ⇒ Object
59 60 61 |
# File 'lib/solidus_feeds/generators/google_merchant.rb', line 59 def link(product) spree_routes.product_url(product, host: host) end |
#mpn(product) ⇒ Object
90 91 92 |
# File 'lib/solidus_feeds/generators/google_merchant.rb', line 90 def mpn(product) product.master.sku end |
#price(product) ⇒ Object
77 78 79 |
# File 'lib/solidus_feeds/generators/google_merchant.rb', line 77 def price(product) ::Spree::Money.new(product.price).money.format(symbol: false, with_currency: true) end |
#render_template(xml) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/solidus_feeds/generators/google_merchant.rb', line 21 def render_template(xml) xml.rss version: "2.0", "xmlns:g" => "http://base.google.com/ns/1.0" do xml.channel do xml.title SolidusFeeds.title xml.link SolidusFeeds.link xml.description SolidusFeeds.description xml.language SolidusFeeds.language products.find_each do |product| xml.item do xml.tag! 'g:id', id(product) xml.tag! 'g:title', title(product) xml.tag! 'g:description', description(product) xml.tag! 'g:link', link(product) xml.tag! 'g:image_link', image_link(product) xml.tag! 'g:condition', condition(product) xml.tag! 'g:price', price(product) xml.tag! 'g:availability', availability(product) xml.tag! 'g:brand', brand(product) xml.tag! 'g:mpn', mpn(product) xml.tag! 'g:google_product_category', google_product_category_id(product) end end end end end |
#title(product) ⇒ Object
51 52 53 |
# File 'lib/solidus_feeds/generators/google_merchant.rb', line 51 def title(product) product.name end |