Class: Gemgento::Magento::CategoriesController

Inherits:
BaseController show all
Defined in:
app/controllers/gemgento/magento/categories_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#validate_ip

Instance Method Details

#destroyObject



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/gemgento/magento/categories_controller.rb', line 34

def destroy
  @category = Category.find_by(magento_id: params[:id])

  unless @category.nil?
    @category.children.each do |category|
      category.mark_deleted!
    end

    @category.mark_deleted!
  end

  render nothing: true
end

#updateObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/gemgento/magento/categories_controller.rb', line 5

def update
  @category = Category.find_or_initialize_by(magento_id: params[:id])
  data = params[:data]

  @category.magento_id = data[:category_id]
  @category.is_active = data[:is_active].to_i == 1 ? true : false
  @category.position = data[:position]
  @category.parent = Category.find_by(magento_id: data[:parent_id]) unless data[:parent_id].nil?
  @category.name = data[:name]
  @category.url_key = data[:url_key]
  @category.include_in_menu = data[:include_in_menu]
  @category.sync_needed = false

  if data.key? :image
    begin
      @category.image = magento_image(data[:image][:value])
    rescue
      @category.image = nil
    end
  end

  @category.save

  set_stores(data[:store_ids], @category)
  set_products(data[:products], @category) unless data[:products].nil?

  render nothing: true
end