Module: Workarea::Storefront::SchemaOrgHelper

Defined in:
app/helpers/workarea/storefront/schema_org_helper.rb

Instance Method Summary collapse

Instance Method Details



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/helpers/workarea/storefront/schema_org_helper.rb', line 24

def breadcrumb_list_schema(breadcrumbs)
  {
    "@context": "http://schema.org",
    "@type": "BreadcrumbList",
    "itemListElement": breadcrumbs.each_with_index.map do |(name, url), index|
      {
        "@type": "ListItem",
        "position": index + 1,
        "item": {
          "@id": url,
          "name": name
        }
      }
    end
  }
end

#fulfillment_email_schema(order, package) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'app/helpers/workarea/storefront/schema_org_helper.rb', line 107

def fulfillment_email_schema(order, package)
  {
    '@context': 'http://schema.org',
    '@type': 'ParcelDelivery',
    'deliveryAddress': {
      '@type': 'PostalAddress',
      'name': 'Ship To',
      'streetAddress': [
        order.shipping_address.street,
        order.shipping_address.street_2
      ].join(' / '),
      'addressLocality': order.shipping_address.city,
      'addressRegion': order.shipping_address.region,
      'addressCountry': order.shipping_address.country,
      'postalCode': order.shipping_address.postal_code
    },
    'carrier': {
      '@type': 'Organization',
      'name': package.carrier
    },
    'itemShipped': order.items.map do |item|
      {
        '@type': 'Product',
        'name': item.product.name,
        'sku': item.sku,
        'url': product_url(item.product, sku: item.sku),
        'image': path_to_url(product_image_url(item.product.primary_image, :small_thumb)),
      }
    end,
    'partOfOrder': {
      '@type': 'Order',
      'orderNumber': order.id,
      'merchant': {
        '@type': 'Organization',
        'name': Workarea.config.site_name
      },
      'orderStatus': 'http://schema.org/OrderInTransit'
    },
    'expectedArrivalUntil': Workarea.config.order_expected_arrival.call(order, package),
    'trackingNumber': package.tracking_number,
    'trackingUrl': package.tracking_link,
    'potentialAction': {
      '@type': 'TrackAction',
      'target': package.tracking_link
    }
  }
end

#order_email_schema(order) ⇒ Object



71
72
73
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
99
100
101
102
103
104
105
# File 'app/helpers/workarea/storefront/schema_org_helper.rb', line 71

def order_email_schema(order)
  {
    '@context': 'http://schema.org',
    '@type': 'Order',
    'merchant': {
      '@type': 'Organization',
      'name': Workarea.config.site_name
    },
    'orderNumber': order.id,
    'orderStatus': 'http://schema.org/OrderProcessing',
    'acceptedOffer': order.items.map do |item|
      {
        '@type': 'Offer',
        'itemOffered': {
          '@type': 'Product',
          'name': item.product.name,
          'sku': item.sku,
          'url': product_url(item.product, sku: item.sku),
          'image': path_to_url(product_image_url(item.product.primary_image, :small_thumb)),
        },
        'price': item.total_price.to_s,
        'priceCurrency': item.total_price.currency.to_s,
        'eligibleQuantity': {
          '@type': 'QuantitativeValue',
          'value': item.quantity
        }
      }
    end,
    'url': order_url(order),
    'potentialAction': {
      '@type': 'ViewAction',
      'url': order_url(order)
    }
  }
end

#product_schema(product, related_products: nil) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/helpers/workarea/storefront/schema_org_helper.rb', line 41

def product_schema(product, related_products: nil)
  schema = {
    "@context": "http://schema.org",
    "@type": "Product",
    "description": product.description,
    "name": product.name,
    "image": product_image_url(product.primary_image, :large_thumb),
    "url": product_url(product),
    "productID": product.id
  }

  if product.pricing.sell_min_price.present?
    schema['offers'] = {
      "@type": "Offer",
      "availability": "http://schema.org/InStock",
      "price": product.pricing.sell_min_price.to_s,
      "priceCurrency": product.pricing.sell_min_price.currency.to_s,
      "url": product_url(product)
    }
  end

  if related_products.present?
    schema['isRelatedTo'] = related_products.map do |related_product|
      product_schema(related_product)
    end
  end

  schema
end

#web_page_schema(type = 'WebPage') ⇒ Object



17
18
19
20
21
22
# File 'app/helpers/workarea/storefront/schema_org_helper.rb', line 17

def web_page_schema(type = 'WebPage')
  {
    '@context': 'http://schema.org',
    '@type': type
  }
end

#web_site_schemaObject



4
5
6
7
8
9
10
11
12
13
14
15
# File 'app/helpers/workarea/storefront/schema_org_helper.rb', line 4

def web_site_schema
  {
    '@context': 'http://schema.org',
    '@type': 'WebSite',
    'url': root_url,
    'potentialAction': {
      '@type': 'SearchAction',
      "target": "#{search_url}?q={search_term_string}",
      'query-input': 'required name=search_term_string'
    }
  }
end