Class: ProductCachesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
lib/rails/generators/shopifydev/templates/controllers/product_caches_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject

GET /product_caches GET /product_caches.json



6
7
8
9
10
# File 'lib/rails/generators/shopifydev/templates/controllers/product_caches_controller.rb', line 6

def index
  @jid = ProductCacheUpdater.perform_async(current_shop.id)
  params[:page] = 1 if params[:page] == ""
  current_shop.product_caches.page params[:page]
end

#statusObject

GET



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rails/generators/shopifydev/templates/controllers/product_caches_controller.rb', line 30

def status
  data = Sidekiq::Status::get_all(params[:jid])
  data[:created_ids] = data[:created_ids].split(',')
  data[:updated_ids] = data[:updated_ids].split(',')
  data[:status] = case data[:status]
  when 'queued', 'working'
    'updating cache...'
  else
    'product cache updated'
  end
  render json: data.to_json
end

#update_multipleObject

PATCH/PUT /product_caches/update_multiple



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rails/generators/shopifydev/templates/controllers/product_caches_controller.rb', line 13

def update_multiple
  
  @product_caches = current_shop.product_caches.update(
    params[:product_caches].keys, 
    permitted_params(params[:product_caches].values)
  ).reject { |p| p.errors.empty? }
  if @product_caches.empty? 
    flash[:success] = "Products updated"
    redirect_to product_caches_page_path(page: params[:page])
  else
    flash.now[:error] = "The following entries had errors:"
    @product_caches = []
    render :index
  end
end