Class: Crm::Wayfair::SchemasController

Inherits:
CrmController
  • Object
show all
Defined in:
app/controllers/crm/wayfair/schemas_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/crm/wayfair/schemas_controller.rb', line 20

def create
  @wayfair_schema = WayfairSchema.new(wayfair_schema_params)
  @wayfair_schema.schema = { status: :must_refresh }
  if @wayfair_schema.save
    flash[:info] = 'Schema created, now refresh to pull schema'
    redirect_to url_for(action: :show, id: @wayfair_schema.id)
  else
    render :new, status: :unprocessable_entity
  end
end

#destroyObject



48
49
50
51
52
# File 'app/controllers/crm/wayfair/schemas_controller.rb', line 48

def destroy
  @wayfair_schema.destroy
  flash[:info] = 'Schema deleted'
  redirect_to url_for(action: :index)
end

#indexObject



6
7
8
9
10
11
# File 'app/controllers/crm/wayfair/schemas_controller.rb', line 6

def index
  authorize! :manage, WayfairSchema
  @q = WayfairSchema.ransack(params[:q])
  @q.sorts = 'taxonomy_category_id asc' if @q.sorts.empty?
  @pagy, @wayfair_schemas = pagy(@q.result)
end

#newObject



16
17
18
# File 'app/controllers/crm/wayfair/schemas_controller.rb', line 16

def new
  @wayfair_schema = WayfairSchema.new
end

#refresh_schemaObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/crm/wayfair/schemas_controller.rb', line 31

def refresh_schema
  orchestrator = Edi::Wayfair::Orchestrator.build(:wayfair_us)
  result = orchestrator.pull_taxonomy_schema_for_category(
    @wayfair_schema.taxonomy_category_id,
    wayfair_schema: @wayfair_schema,
    brand: @wayfair_schema.brand,
    country: @wayfair_schema.country,
    locale: @wayfair_schema.locale
  )
  if result
    flash[:notice] = "Schema refreshed (#{result.attributes_list.size} attributes)"
  else
    flash[:error] = 'Failed to refresh schema'
  end
  redirect_to url_for(action: :show, id: @wayfair_schema.id)
end

#showObject



13
14
# File 'app/controllers/crm/wayfair/schemas_controller.rb', line 13

def show
end