Class: Gemgento::Magento::ProductsController

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

Instance Method Summary collapse

Methods inherited from BaseController

#validate_ip

Instance Method Details

#destroyObject



37
38
39
40
41
42
43
44
45
# File 'app/controllers/gemgento/magento/products_controller.rb', line 37

def destroy
  data = params[:data]

  if Product.not_deleted.where('id = ? OR magento_id = ?', params[:id], data[:product_id]).count > 0
    @product = Product.find_by('id = ? OR magento_id = ?', params[:id], data[:product_id]).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
33
34
35
# File 'app/controllers/gemgento/magento/products_controller.rb', line 5

def update
  data = params[:data]

  @product = Gemgento::Product.find_or_initialize_by(magento_id: data[:product_id])

  @product.magento_id = data[:product_id]
  @product.magento_type = data[:type]
  @product.sku = data[:sku]
  @product.sync_needed = false
  @product.product_attribute_set = ProductAttributeSet.where(magento_id: data[:set]).first
  @product.magento_type = data[:type]
  @product.deleted_at = nil
  @product.save

  set_stores(data[:stores], @product) unless data[:stores].nil?

  unless data[:additional_attributes].nil?
    set_assets(data[:additional_attributes], @product)
    set_attribute_values_from_magento(data[:additional_attributes], @product)
  end

  if data[:configurable_attribute_ids]
    @product.configurable_attributes = Gemgento::ProductAttribute.where(magento_id: data[:configurable_attribute_ids])
  end

  set_associated_products(data[:simple_product_ids], data[:configurable_product_ids], @product)
  set_bundle_options(data[:bundle_options], @product) if data[:bundle_options]
  set_tier_prices(data[:tier_price], @product) if data[:tier_price]

  render nothing: true
end