Class: Gemgento::API::SOAP::Catalog::ProductAttributeMedia

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

Class Method Summary collapse

Class Method Details

.create(asset) ⇒ Gemgento::MagentoResponse

Create a Product Attribute Media in Magento.

Parameters:

Returns:



74
75
76
77
78
79
80
81
82
# File 'lib/gemgento/api/soap/catalog/product_attribute_media.rb', line 74

def self.create(asset)
  message = {
      product: asset.product.magento_id,
      data: compose_asset_entity_data(asset, true),
      identifier_type: 'id',
      store_view: asset.store.magento_id
  }
  ::Gemgento::MagentoApi.create_call(:catalog_product_attribute_media_create, message)
end

.fetch(product, store = nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/gemgento/api/soap/catalog/product_attribute_media.rb', line 15

def self.fetch(product, store = nil)
  store = ::Gemgento::Store.current if store.nil?
  response = list(product, store)

  if response.success?
    assets_to_keep = []

    response.body[:result][:item].each do |product_attribute_media|
      if asset = sync_magento_to_local(product_attribute_media, product, store)
        assets_to_keep << asset.id
      end
    end

    # destroy any assets that were not in the media gallery for each store
    ::Gemgento::Asset.skip_callback(:destroy, :before, :delete_magento)
    product.assets.where(store: store).where.not(id: assets_to_keep).destroy_all
    ::Gemgento::Asset.set_callback(:destroy, :before, :delete_magento)
  end
end

.fetch_allObject



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

def self.fetch_all
  ::Gemgento::Store.all.each do |store|
    ::Gemgento::Product.active.each do |product|
      fetch(product, store)
    end
  end
end

.fetch_all_media_typesObject



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/gemgento/api/soap/catalog/product_attribute_media.rb', line 35

def self.fetch_all_media_types
  ::Gemgento::ProductAttributeSet.all.each do |product_attribute_set|
    response = types(product_attribute_set)

    if response.success?
      response.body[:result][:item].each do |media_type|
        sync_magento_media_type_to_local(media_type, product_attribute_set)
      end
    end
  end
end

.infoObject



66
67
68
# File 'lib/gemgento/api/soap/catalog/product_attribute_media.rb', line 66

def self.info

end

.list(product, store) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/gemgento/api/soap/catalog/product_attribute_media.rb', line 47

def self.list(product, store)
  message = {
      product: product.magento_id,
      identifier_type: 'id',
      store_view: store.magento_id
  }
  response = ::Gemgento::MagentoApi.create_call(:catalog_product_attribute_media_list, message)

  if response.success?
    if response.body[:result][:item].nil?
      response.body[:result][:item] = []
    elsif !response.body[:result][:item].is_a? Array
      response.body[:result][:item] = [response.body[:result][:item]]
    end
  end

  return response
end

.remove(asset) ⇒ Gemgento::MagentoResponse

Remove Product Attribute Media in Magento.

Parameters:

Returns:



103
104
105
106
# File 'lib/gemgento/api/soap/catalog/product_attribute_media.rb', line 103

def self.remove(asset)
  message = { product: asset.product.magento_id, file: asset.file, identifier_type: 'id' }
  ::Gemgento::MagentoApi.create_call(:catalog_product_attribute_media_remove, message)
end

.types(product_attribute_set) ⇒ Gemgento::MagnetoRepsonse

Get Product Attribute Media Types from Magento.

Parameters:

Returns:

  • (Gemgento::MagnetoRepsonse)


112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/gemgento/api/soap/catalog/product_attribute_media.rb', line 112

def self.types(product_attribute_set)
  response = ::Gemgento::MagentoApi.create_call(:catalog_product_attribute_media_types, {set_id: product_attribute_set.magento_id})

  if response.success? &&
    if response.body[:result][:item].nil?
      response.body[:result][:item] = []
    elsif !response.body[:result][:item].is_a?(Array)
      response.body[:result][:item] = [response.body[:result][:item]]
    end
  end

  return response
end

.update(asset) ⇒ Gemgento::MagentoResponse

Update a Product Attribute Media in Magento.

Parameters:

Returns:



88
89
90
91
92
93
94
95
96
97
# File 'lib/gemgento/api/soap/catalog/product_attribute_media.rb', line 88

def self.update(asset)
  message = {
      product: asset.product.magento_id,
      file: asset.file,
      data: compose_asset_entity_data(asset, false),
      identifier_type: 'id',
      store_view: asset.store.magento_id
  }
  ::Gemgento::MagentoApi.create_call(:catalog_product_attribute_media_update, message)
end