Class: Gemgento::API::SOAP::Catalog::ProductAttribute

Inherits:
Object
  • Object
show all
Defined in:
lib/gemgento/api/soap/catalog/product_attribute.rb

Class Method Summary collapse

Class Method Details

.add_option(product_attribute_option, product_attribute) ⇒ Gemgento::MagentoResponse

Add an attribute option in Magento.

Parameters:

Returns:



99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/gemgento/api/soap/catalog/product_attribute.rb', line 99

def self.add_option(product_attribute_option, product_attribute)
  message = {attribute: product_attribute.magento_id, data: {
      label: {item: [{'store_id' => {item: Store.all.map { |s| s.magento_id.to_s } << 0}, value: product_attribute_option.label}]},
      order: '0',
      'is_default' => '0'
  }}

  response = MagentoApi.create_call(:catalog_product_attribute_add_option, message)
  fetch_all_options(product_attribute) if response.success?

  return response
end

.create(product_attribute) ⇒ Object



86
87
88
# File 'lib/gemgento/api/soap/catalog/product_attribute.rb', line 86

def self.create(product_attribute)
  # TODO: create a new product attribute set on Magento
end

.fetch(attribute_id, attribute_set) ⇒ Object



15
16
17
18
# File 'lib/gemgento/api/soap/catalog/product_attribute.rb', line 15

def self.fetch(attribute_id, attribute_set)
  attribute_info = info(attribute_id)
  sync_magento_to_local(attribute_info, attribute_set)
end

.fetch_allObject



7
8
9
10
11
12
13
# File 'lib/gemgento/api/soap/catalog/product_attribute.rb', line 7

def self.fetch_all
  ::Gemgento::ProductAttributeSet.all.each do |product_attribute_set|
    list(product_attribute_set).each do |product_attribute|
      sync_magento_to_local(info(product_attribute[:attribute_id]), product_attribute_set)
    end
  end
end

.fetch_all_options(product_attribute) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/gemgento/api/soap/catalog/product_attribute.rb', line 20

def self.fetch_all_options(product_attribute)
  option_ids = []

  # add attribute options if there are any
  Store.all.each do |store|
    options(product_attribute.magento_id, store).each_with_index do |attribute_option, index|
      label = MagentoApi.enforce_savon_string(attribute_option[:label])
      value = MagentoApi.enforce_savon_string(attribute_option[:value])

      product_attribute_option = ProductAttributeOption.find_or_initialize_by(product_attribute: product_attribute, value: value, store: store)
      product_attribute_option.label = label
      product_attribute_option.order = index
      product_attribute_option.sync_needed = false
      product_attribute_option.save

      option_ids << product_attribute_option.id
    end
  end

  product_attribute.product_attribute_options.where.not(id: option_ids).destroy_all
end

.info(attribute_id) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/gemgento/api/soap/catalog/product_attribute.rb', line 54

def self.info(attribute_id)
  response = MagentoApi.create_call(:catalog_product_attribute_info, {attribute: attribute_id})

  if response.success?
    response.body[:result]
  end
end

.list(product_attribute_set) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/gemgento/api/soap/catalog/product_attribute.rb', line 42

def self.list(product_attribute_set)
  response = MagentoApi.create_call(:catalog_product_attribute_list, {set_id: product_attribute_set.magento_id})

  if response.success?
    unless response.body[:result][:item].is_a? Array
      response.body[:result][:item] = [response.body[:result][:item]]
    end

    response.body[:result][:item]
  end
end

.options(product_attribute_id, store) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/gemgento/api/soap/catalog/product_attribute.rb', line 62

def self.options(product_attribute_id, store)
  message = {
      attributeId: product_attribute_id,
      storeView: store.magento_id
  }
  response = MagentoApi.create_call(:catalog_product_attribute_options, message)

  if response.success?
    if response.body[:result][:item].nil?
      response.body[:result][:item] = []
    end

    unless response.body[:result][:item].is_a? Array
      response.body[:result][:item] = [response.body[:result][:item]]
    end

    response.body[:result][:item]
  end
end

.remove_optionObject



112
113
114
# File 'lib/gemgento/api/soap/catalog/product_attribute.rb', line 112

def self.remove_option
  # TODO: update a product attribute set on Magento
end

.typesObject



82
83
84
# File 'lib/gemgento/api/soap/catalog/product_attribute.rb', line 82

def self.types
  # TODO: Create types API call
end

.update(product_attribute) ⇒ Object



90
91
92
# File 'lib/gemgento/api/soap/catalog/product_attribute.rb', line 90

def self.update(product_attribute)
  # TODO: update a product attribute set on Magento
end