Class: RestaurantCpt::Operations::Seo

Inherits:
Trailblazer::Operation
  • Object
show all
Defined in:
app/concepts/restaurant_cpt/operations/seo.rb

Overview

Responsible to adjust restaurant SEO to be displayed with 'meta-tags' gem

Defined Under Namespace

Classes: Sanitizer

Instance Method Summary collapse

Instance Method Details

#finalize(options) ⇒ Object



121
122
123
124
# File 'app/concepts/restaurant_cpt/operations/seo.rb', line 121

def finalize(options, *)
  options['result'] = options['t'].to_h
  true
end

#init(options) ⇒ Object



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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'app/concepts/restaurant_cpt/operations/seo.rb', line 72

def init(options, *)
  restaurant = options['params']['restaurant'].decorate
  image_cover = restaurant.image_cover_url(width: 600, height: 600, only_path: false, original: true)

  options['sanitizer'] = Sanitizer.new
  options['r'] = restaurant
  options['cell'] = ::RestaurantCpt::Cell::DefaultSeo.call(restaurant)
  # t means tags
  options['t'] = OpenStruct.new # tags
  options['t'].image_src = image_cover

  options['t'].og = {
    type: 'product',
    image: image_cover,
  }

  expired = false
  if restaurant.active?
    date_offer_expired = Time.use_zone(restaurant.time_zone) do
      restaurant.date_offer_expired?(Time.zone.now.to_date)
    end
    if date_offer_expired
      expired = true
    end
  else
    expired = true
  end

  options['t'].product = {
    retailer_item_id: restaurant.id,
    availability: expired ? Restaurant::AVAILABILITY_OUT_OF_STOCK : Restaurant::AVAILABILITY_IN_STOCK,
    condition: 'new',
    'price:amount': restaurant.price_per_person(as_string: false),
    'price:currency': 'THB',
    category: 'Business & Industrial > Food Service',
    is_product_shareable: true,
  }
  options['t'].fb = {
    app_id: 1_377_993_762_506_689,
    pages: 372_850_069_508_787,
  }
  options['t'].twitter = {
    card: 'summary_large_image',
    image: image_cover,
  }

  true
end