Class: Workarea::Storefront::DownloadsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/workarea/storefront/downloads_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_layout, #current_user_info, #health_check, #layout_content

Methods included from OrderLookup

#lookup_order, #lookup_order=

Methods included from CurrentCheckout

#clear_current_order, #completed_order, #completed_order=, #current_checkout, #current_order, #current_order=, #current_shipping, #current_shippings, #logout

Instance Method Details

#showObject



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

def show
  token = Fulfillment::Token.find(params[:id])
  sku = Fulfillment::Sku.find(token.sku) rescue nil

  if token&.enabled? && sku&.downloadable?
    token.inc(downloads: 1)
    send_file sku.file.file, filename: sku.file_name
  else
    flash[:info] = t('workarea.storefront.flash_messages.download_unavailable')
    redirect_to root_path
  end
end