Module: Spree::ProductDecorator
- Defined in:
- app/decorators/models/spree/product_decorator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #in_stock? ⇒ Boolean
- #jsonld_data ⇒ Object
- #seo_brand ⇒ Object
- #seo_currency ⇒ Object
- #seo_data ⇒ Object
- #seo_description ⇒ Object
- #seo_images ⇒ Object
- #seo_name ⇒ Object
- #seo_price ⇒ Object
- #seo_url ⇒ Object
Class Method Details
.prepended(base) ⇒ Object
5 6 7 8 9 |
# File 'app/decorators/models/spree/product_decorator.rb', line 5 def self.prepended(base) base.class_eval do include SolidusSeo::Model end end |
Instance Method Details
#in_stock? ⇒ Boolean
43 44 45 |
# File 'app/decorators/models/spree/product_decorator.rb', line 43 def in_stock? available? && variants_including_master.suppliable.any? end |
#jsonld_data ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/decorators/models/spree/product_decorator.rb', line 74 def jsonld_data { "@context": "http://schema.org/", "@type": "Product", "name": name, "url": seo_url, "image": seo_images, "description": seo_name, "sku": sku, "brand": seo_brand, # TODO: ratings/reviews # "aggregateRating": { # "@type": "AggregateRating", # "ratingValue": "4.4", # "reviewCount": "89" # }, "offers": { "@type": "Offer", "priceCurrency": seo_currency, "price": seo_price, "itemCondition": "http://schema.org/NewCondition", "availability": "http://schema.org/#{ in_stock? ? 'InStock' : 'OutOfStock'}", } } end |
#seo_brand ⇒ Object
31 32 33 |
# File 'app/decorators/models/spree/product_decorator.rb', line 31 def seo_brand @brand ||= taxons.detect { |it| it.root.name =~ /^brands?$/i }.try(:name) end |
#seo_currency ⇒ Object
35 36 37 |
# File 'app/decorators/models/spree/product_decorator.rb', line 35 def seo_currency master.default_price.currency end |
#seo_data ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/decorators/models/spree/product_decorator.rb', line 47 def seo_data { title: seo_name, description: seo_description, name: seo_name, image_src: seo_images.first, og: { type: 'product', url: seo_url, brand: seo_brand, image: { _: :image_src, alt: seo_name, } }, product: { price: { amount: seo_price, currency: seo_currency, } }, twitter: { card: 'summary_large_image', } } end |
#seo_description ⇒ Object
27 28 29 |
# File 'app/decorators/models/spree/product_decorator.rb', line 27 def seo_description plain_text(try(:meta_description).presence || try(:description)) end |
#seo_images ⇒ Object
19 20 21 22 23 24 25 |
# File 'app/decorators/models/spree/product_decorator.rb', line 19 def seo_images return [] unless gallery.images.any? && gallery.images.first..file? [ url_helper.image_url(gallery.images.first..url(:large), host: store_host), ].compact end |
#seo_name ⇒ Object
11 12 13 |
# File 'app/decorators/models/spree/product_decorator.rb', line 11 def seo_name plain_text(try(:meta_title).presence) || name end |
#seo_price ⇒ Object
39 40 41 |
# File 'app/decorators/models/spree/product_decorator.rb', line 39 def seo_price master.default_price.amount end |
#seo_url ⇒ Object
15 16 17 |
# File 'app/decorators/models/spree/product_decorator.rb', line 15 def seo_url spree_route_helper.product_url(self, host: store_host) end |