Module: DiscoApp::Concerns::ShopUpdateJob

Extended by:
ActiveSupport::Concern
Included in:
ShopUpdateJob
Defined in:
app/jobs/disco_app/concerns/shop_update_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(shop, shop_data = nil) ⇒ Object

Perform an update of the current shop’s information.



5
6
7
8
9
10
11
# File 'app/jobs/disco_app/concerns/shop_update_job.rb', line 5

def perform(shop, shop_data = nil)
  # If we weren't provided with shop data (eg from a webhook), fetch it.
  shop_data ||= ActiveSupport::JSON::decode(ShopifyAPI::Shop.current.to_json)

  # Update attributes stored directly on the Shop model, along with the data hash itself.
  @shop.update(shop_data.with_indifferent_access.slice(*DiscoApp::Shop.column_names).except(:id, :created_at).merge(data: shop_data))
end